万事可乐 发表于 2022-2-14 14:16:20

王一之 发表于 2022-2-14 13:45
测试没有问题,哥哥是不是提前resolve了,resolve会结束脚本,GM函数不再起作用 ...

// ==UserScript==
// @name         新成绩通知 test
// @namespace    icecola
// @version      0.1.0
// @descriptiontry to take over the world!
// @author       万事可乐
// @debug
// @require      https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js
// @connect      http://27.188.65.169:9900/
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_openInTab
// @crontab      */10 * * * *
// ==/UserScript==

return new Promise((resolve, reject) => {

    // class course {
    //   constructor(id,name,score){
    //         this.id=id;
    //         this.name=name;
    //         this.score=score;
    //   }
    // }

    GM_xmlhttpRequest({
      method: "get",
      url: "http://27.188.65.169:9900/pjxfjdpm/maxcj.asp?MIDD=MTkyMDMwMTEz",
      overrideMimeType:"text/html;charset=gb2312",
      timeout:1000,
      onload: function(r) {
            if($("#huegrade").length==0){
                $("body").append($(`<div id=huegrade></div>`))
            }
            $("#huegrade").html(r.responseText);
            document.querySelector("tbody > tr > td > table > tbody").id="optable";
            if (GM_getValue("amount")==undefined){
                GM_setValue("amount",$("#optable>tr").length);
                resolve('初始化成功')
            }
            else if($("#optable>tr").length==GM_getValue("amount")){
                resolve('请求成功,无新增成绩');
            }
            else if($("#optable>tr").length>GM_getValue("amount")){
                GM_notification({
                  title:'您有新的成绩提醒',
                  text:'您有一门新成绩,点击查看详情',
                  onclick:function(){
                        GM_openInTab('http://27.188.65.169:9900/pjxfjdpm/maxcj.asp?MIDD=MTkyMDMwMTEz',{active:true, insert: true})
                  }
                })
                resolve('请求成功,有新增成绩')
            }
            
            //console.log(r)
      },
      ontimeout: function(){
            GM_notification({
                title: '河工程成绩提醒',
                text: '请求超时',
            });
            reject('请求超时')
      },
      onerror: function () {
            GM_notification({
                title: '错误',
                text: '网络未连接或学号不存在',
            });
            reject('error');
      }
    });

});

万事可乐 发表于 2022-2-14 14:25:44

王一之 发表于 2022-2-14 14:13
应该写在 onclick 里

可以了,哥哥牛逼

王一之 发表于 2022-2-14 16:25:03

万事可乐 发表于 2022-2-14 14:25
可以了,哥哥牛逼

ggnb!期待哥哥的脚本!

wwwwwllllk 发表于 2023-7-2 20:23:37

王一之 发表于 2022-2-14 13:45
测试没有问题,哥哥是不是提前resolve了,resolve会结束脚本,GM函数不再起作用 ...

// ==UserScript==
// @name         New Userscript
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @descriptiontry to take over the world!
// @author       You
// @background
// @grant GM_notification
// @grant GM_openInTab
// ==/UserScript==

return new Promise((resolve, reject) => {
    // Your code here...
    GM_notification({
      title: '您有新的成绩提醒',
      text: '您有一门新成绩,点击查看详情',
      onclick: function () {
            GM_openInTab('https://www.baidu.com', { active: true, insert: true })
      }
    })
});
页: 1 [2]
查看完整版本: 后台脚本不能使用GM_openInTap吗