GMLibrary

GMLibary

Verze ze dne 16. 12. 2022. Zobrazit nejnovější verzi.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greasyfork.org/scripts/456410/1128944/GMLibrary.js

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         GMLibrary
// @namespace    https://greasyfork.org/users/28298
// @version      1.1
// @description  GMLibary
// @author       Jerry
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_setClipboard
// @grant        GM_download
// @grant        GM_addStyle
// @grant        GM_notification
// @grant        GM_xmlhttpRequest
// @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);
}

// must call with asyn, await
function hget (url) {
    // https://wiki.greasespot.net/GM.xmlHttpRequest
    // https://stackoverflow.com/a/65561572/2292993
    return new Promise((resolve, reject) => {
    GM_xmlhttpRequest({
      method: "GET",
      url: url,
      // headers: {
      //   "User-Agent": "Mozilla/5.0",    // If not specified, navigator.userAgent will be used.
      //   "Accept": "text/xml"            // If not specified, browser defaults will be used.
      // },
      onload: function(response) {
        var responseXML = null;
        // Inject responseXML into existing Object (only appropriate for XML content).
        if (!response.responseXML) {
          responseXML = new DOMParser()
            .parseFromString(response.responseText, "text/xml");
        }
        resolve(responseXML);
        // console.log([
        //   response.status,
        //   response.statusText,
        //   response.readyState,
        //   response.responseHeaders,
        //   response.responseText,
        //   response.finalUrl,
        //   responseXML
        // ].join("\n"));
      },
      onerror: function(error) {
        reject(error);
      }
    });
    });
}