Greasy Fork

Greasy Fork is available in English.

YangtzeRain-AutoQuiz

长江雨课堂课堂习题监控

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @license MIT
// @name         YangtzeRain-AutoQuiz
// @version      0.1
// @description  长江雨课堂课堂习题监控
// @author       Viatin
// @match        *://changjiang.yuketang.cn/lesson/fullscreen/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_xmlhttpRequest
// @connect      sctapi.ftqq.com
// @run-at       document-start
// @namespace    http://greasyfork.icu/zh-CN/users/1278689-endorsie
// ==/UserScript==

const sendkey = '把Server酱的SendKey粘贴到这里'

function sendGotifyMessage(url, token, title, message, priority=9){
    GM_xmlhttpRequest({
        method: "post",
        url: `${url}/message?token=${token}`,
        headers: {
            "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
        },
        data: `title=${title}&message=${message}&priority=${priority}`,

        onload: function(response){
            console.log("请求成功");
        },
        onerror: function(response){
            console.log("请求失败");
        }
    });
}

function sendWxMessage(sendkey, title){
    GM_xmlhttpRequest({
        method: "get",
        url: `https://sctapi.ftqq.com/${sendkey}.send?title=${title}`,

        onload: function(response){
            console.log("请求成功");
        },
        onerror: function(response){
            console.log("请求失败");
        }
    });
}

function onPageLoad() {
    // 选择将观察突变的节点
    let targetNode = document.querySelector('section.timeline__wrap');

    // 观察者的选项(要观察哪些突变)
    let config = { attributes: false, childList: true, subtree: false };

    // 当观察到突变时执行的回调函数
    let callback = function(mutationsList) {
        mutationsList.forEach(function(item,index){
            if (item.type == 'childList') {
                for (let node of item.addedNodes) {
                    if (node.querySelector('div.problem')) {
                        sendWxMessage(sendkey, `雨课堂-${document.title}有新习题`);
                    }
                }
            }
        });
    };

    // 创建一个链接到回调函数的观察者实例
    let observer = new MutationObserver(callback);

    // 开始观察已配置突变的目标节点
    observer.observe(targetNode, config);

    sendWxMessage(sendkey, `雨课堂-${document.title}已上线`);
}

(function() {
    'use strict';

    // Your code here...
    window.onload = function() {
        setTimeout(onPageLoad, 5000);
    };
})();