My_General_Utils

Utils I use for other user scripts.

目前為 2020-06-04 提交的版本,檢視 最新版本

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

//@require 	 https://raw.githubusercontent.com/eligrey/FileSaver.js/master/dist/FileSaver.js
//My_General_Utils.js

//Saves data to a file
/*
*/
function saveLocalFile(data, fileName){
	var blob = new Blob([data], {type: "text/plain;charset=utf-8"});
	saveAs(blob, fileName);
}

//Takes strings of html elements and appendeds it to the selector
function createElements(elements, selector) {
    log("createElements Enter", true);
    //append element to selector
    $(selector).append(elements);
}

//waits for a jQuery element to exist then runs callback function
//syntax waitForElement(jQuery selector, function onec element exists, timout in milliseconds)
function waitForElement(selector, callback, ms) {
	if(ms == null){
		var ms = 100;
	}
    log("waitForElement Enter", true);
    if ($(selector).length) {
        callback(selector);
    } else {
        setTimeout(function () {
            waitForElement(selector, callback);
        }, ms);
    }
}

//Feed class string for html elemnt, returns array of all matching elements
function arryElements(element) {
    //log("arryElements Enter", true);
    //Create an array of all (...) settings buttons
    var elemCount = $(element).length;
    var elemArr = new Array(elemCount);
    elemArr = $(element).each($).toArray();

    return elemArr;
}

// Returns a promise which resolves after x amount of ms. Allows pausing on a line.
function sleep(ms) {
    // A promise is returned. When used in an async function with the await keyword, will wait the x amount of milliseconds to resolve and then continue
    return new Promise(resolve => setTimeout(resolve, ms));
}

QingJ © 2025

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