WHUCodeInference

武大本科生院附件下载自动填验证码

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         WHUCodeInference
// @namespace    http://luxiaoxiao.work/
// @version      0.2.4
// @description  武大本科生院附件下载自动填验证码
// @author       LXX
// @license      MIT
// @match        https://uc.whu.edu.cn/system/_content/download.jsp*
// @icon         https://uc.whu.edu.cn/2022/images/favicon.ico
// @connect      code.luxiaoxiao.work
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';
    var image = document.getElementById("codeimg");
    function sleep(sleepTime) {
        for(var start = new Date; new Date - start <= sleepTime;) {}
    }

    const inference = function(){
        context.drawImage(image, 0, 0);
        var base64Data = canvas.toDataURL('image/png');
        console.log(base64Data);
        base64Data = base64Data.replace(/^data:image\/png;base64,/, '');
        base64Data = base64Data.replace(/\+/g, '-').replace(/\//g, '_');
        console.log(base64Data);

        GM_xmlhttpRequest({
            method: 'get',
            url: 'https://code.luxiaoxiao.work/code/' + base64Data,
            onload: function(response){
                console.log(response);
                document.getElementById('codeValue').value = response.responseText;
            }
        })
    }

    const main = function(){
        image = document.getElementById("codeimg");
        inference();
    }
    window.addEventListener('load', function() {
        // 在页面的所有资源加载完成后执行一些操作
        image = document.getElementById("codeimg");
        inference();
    });
    //main();

    var canvas = document.createElement('canvas');
    canvas.width = 60
    canvas.height = 20;
    var context = canvas.getContext('2d');

    const callback = function(){
        console.log('changed!');
        sleep(500);
        image = document.getElementById("codeimg");
        inference();
    }
    const observer = new MutationObserver(callback);
    const config = {
        attributes: true
    }
    observer.observe(image, config);
    
})();