GMLibrary

GMLibary

目前為 2022-12-10 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/456410/1127029/GMLibrary.js

// ==UserScript==
// @name         GMLibrary
// @namespace    https://gf.qytechs.cn/users/28298
// @version      1.0
// @description  GMLibary
// @author       Jerry
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_setClipboard
// @grant        GM_download
// @grant        GM_addStyle
// @grant        GM_notification
// @noframes
// @license      GNU GPLv3
// ==/UserScript==

// match violentmonkey supports * anywhere in url
// GM_notification requires macOS to turn on notification for browser
// https://violentmonkey.github.io/api/gm/
// https://www.tampermonkey.net/documentation.php?ext=dhdg
function addbutton(text,func,top,left,width,height) {
    //top, left, [width[, height]] in px
    // e.g., width 100px, height 25px
    // https://stackoverflow.com/a/1535421/2292993
    if (window.top != window.self) {
        return;
    }   //don't run on frames or iframes

    let btn = document.createElement("button");
    btn.innerHTML = text;
    document.body.appendChild(btn);
    btn.addEventListener("click", func);

    btn.style.cssText = "border-radius: 5px; border:1px solid black; background-color:#D3D3D3; color:black";
    btn.style.position = 'absolute';
    btn.style.top = top+'px';
    btn.style.left = left+'px';
    if (width !== undefined) {btn.style.width = width+'px';}
    if (height !== undefined) {btn.style.height = height+'px';}
    console.log("top: " + top + 'px' + " left: " + left + 'px');
}

// // must call with await in async function; otherwise not working
// function sleep(ms) {
//     setTimeout(()=>{console.log("Sleeping...");},3000);
//     return new Promise(resolve => setTimeout(resolve, ms));
// }
function sleep(millis) {
    var date = new Date();
    var curDate = null;
    do { curDate = new Date(); }
    while(curDate-date < millis);
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址