Greasy Fork

来自缓存

Greasy Fork is available in English.

专业技术人员学习新干线

开始学习直接跳转到学习页,不用二次中转

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         专业技术人员学习新干线
// @namespace    https://learning.hzrs.hangzhou.gov.cn
// @description  开始学习直接跳转到学习页,不用二次中转
// @author       NetFert
// @match        https://learning.hzrs.hangzhou.gov.cn/*
// @grant        none
// @license      MIT
// @version      0.0.4
// ==/UserScript==

(function () {
  "use strict";

  const loadLearnList = () => {
    fetch("https://learning.hzrs.hangzhou.gov.cn/api/index/Course/index", {
      headers: {
        accept: "application/json, text/plain, */*",
        authorization: "Bearer " + localStorage.getItem("front_token"),
        "cache-control": "no-cache",
        "content-type": "application/json",
        pragma: "no-cache",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
      },
      referrer: "https://learning.hzrs.hangzhou.gov.cn/",
      referrerPolicy: "strict-origin-when-cross-origin",
      body: '{"limit":10,"page":1}',
      method: "POST",
      mode: "cors",
      credentials: "include",
    })
      .then((response) => response.json())
      .then((res) => {
        const tbodyChildren =
          document.getElementsByTagName("tbody")[0].children;
        for (let i = 0; i < tbodyChildren.length; i++) {
          const childElement = tbodyChildren[i];
          childElement.childNodes[4].children[0].children[0].children[0].addEventListener(
            "click",
            function (e) {
              e.stopPropagation();
              e.preventDefault();
              window.open(
                "https://learning.hzrs.hangzhou.gov.cn/#/class?courseId=" +
                  res.data.data[i].courseid +
                  "&coursetitle=" +
                  res.data.data[i].coursename
              );
            },
            true
          );
        }
      });
  };

  const tryLoadLearnList = () => {
    let attempts = 0;
    const maxAttempts = 3000;
    const intervalTime = 10;

    function checkAndLoad() {
      const tbody = document.getElementsByTagName("tbody")[0];
      if (tbody && tbody.children.length > 0) {
        loadLearnList();
      } else {
        attempts++;
        if (attempts < maxAttempts) {
          setTimeout(checkAndLoad, intervalTime);
        } else {
          alert("脚本无法成功运行,可能失效了。");
        }
      }
    }
    checkAndLoad();
  };

  const killConfirm = () => {
    setInterval(() => {
      console.log("正在寻找确认按钮...");
      const allElements = document.querySelectorAll("*");
      const confirmButtons = [];
      allElements.forEach((el) => {
        if (el.textContent.trim() === "确定") {
          confirmButtons.push(el);
        }
      });

      for (let i = 0; i < confirmButtons.length; i++) {
        const button = confirmButtons[i];
        if (button.tagName === "BUTTON" || button.tagName === "A") {
          console.log("击毙确认按钮中...");
          button.click();
        }
      }
    }, 3000);
  };

  window.addEventListener("load", function () {
    if (window.location.hash.includes("#/learn")) {
      tryLoadLearnList();
    }

    if (window.location.hash.includes("#/class")) {
      killConfirm();
    }
  });
})();