jkToolFuncs

超星泛雅平台学习通批量改作业

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/512727/1465270/jkToolFuncs.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         jkToolFuncs
// @namespace       moe.canfire.flf
// @version         1.0.0
// @description    jkToolFuncsxx
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @description  try to take over the world!
// @author       You
// @license MIT
// @match           *://*/*
// @grant unsafeWindow
// ==/UserScript==

 //访问 不到window对象,需用unsafewindow
(function() {
    'use strict';
//==========================================================
class jkToolFuncs{
 waitFor(fn,interval_10 ,timeout_5000 ) {
     //返回promise,//判断变量是否改变,默认间隔10毫秒,超时5000
     if(!interval_10)interval_10=3;      if(!timeout_5000)timeout_5000=5000;
  return new Promise((resolve, reject) => {
      let timeoutid=-1;
    const checkVariable = setInterval(() => {
      if (  fn()==true ) {  clearInterval(checkVariable); clearTimeout(timeoutid); resolve(); }
    }, interval_10); // 每100毫秒检查一次变量是否达到指定的值
    timeoutid=setTimeout(() => {
          clearInterval(checkVariable);
          reject(new Error('Timeout waiting variable to change'));
       }, timeout_5000 );     
  });  
}//===================
  sleep( miniseconds ){
   //一个简单的promise,延时1毫秒函数,在此基础上,实现同步的wait
  return new Promise(function(resolve){
    setTimeout(() => resolve("ok"), miniseconds );
  })
 }//func=========

 find(selector){
     return document.querySelector(selector);
   }
 finds(selector){
     return document.querySelectorAll(selector);
   }
 isValid(el){
       if((el==undefined)||el==null) return true; else  return false;
   }
 addSheet(cssText,id){
    var el=this.sel('#'+id);
    if(!this.isvalid(el))return;
    var style = document.createElement('style');    style.id=id;
    style.innerHTML =cssText;
    document.head.appendChild(style);
   }
  loadScript(url){ //loadscript(url).then
  var tmp=url.substring(url.lastIndexOf('/')+1);
  return new Promise((resolve,reject)=>{
  var script = document.createElement("script");
  script.type = "text/javascript";
  if(script.readyState){  //只有ie才有
    script.onreadystatechange = function(){
      if(script.readyState == "complete" || script.readyState == "loaded"){  
          console.log(tmp+" load Ok ie")
           resolve() 
           }
    }
  }else{
    script.onload = function(){  
         console.log(tmp+" load Ok browser")
         resolve() 
         }
  }
  script.src = url;
  document.head.appendChild(script);
  })
}//loadScript("01.js","test")

async loadjQuery(){
    if(!window.jQuery){  return this.loadScript('https://code.jquery.com/jquery-3.6.0.min.js' ); } return false;
}//function

}//class========================
 



unsafeWindow.jk=new jkToolFuncs();
//==========================================================
})();