QOS-Handler

QOS-Handler(window param ver)

03.08.2021 itibariyledir. En son verisyonu görün.

Bu script direkt olarak kurulamaz. Başka scriptler için bir kütüphanedir ve meta yönergeleri içerir // @require https://update.greasyfork.org/scripts/430297/956917/QOS-Handler.js

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         QOS-Handler
// @namespace    http://greasyfork.org/
// @version      0.1
// @description  QOS-Handler(window param ver)
// @author       Cosil.C
// @license      GPL
// ==/UserScript==

/* jshint esversion: 6 */
/**
 * @description 流控相关
 */
document.defaultView.qos = {
    /**
     * @description 记录这次的访问时间戳,并返回是否超出限制
     * @param sec 时间限制
     * @param timesLimit 次数限制
     * @returns sec秒内访问了超过timesLimit次 ? true : false
     */
    record: (sec, timesLimit) => {
        sec = sec || 5;
        timesLimit = timesLimit || 10;
        console.log(`start qos recording...\nsec:${sec},timesLimit:${timesLimit}`);
        let timestamp = new Date().getTime(), historyArr = document.defaultView.qos.getRecord();
        historyArr.push(timestamp);
        if (historyArr.length > timesLimit) {
            let shift;
            do {
                shift = parseInt(historyArr.shift());
            } while (historyArr.length > timesLimit);
            //
            if (timestamp - shift <= sec * 1000) {
                let format = function (target) {
                    return new Date(target).toTimeString().substr(0, 8);
                };
                console.log(`current:${format(timestamp)}, shift:${format(shift)}, interval(sec):${(timestamp - shift) / 1000}`);
                return true;
            }
        }
        localStorage.setItem('historyArr', JSON.stringify(historyArr));
        console.log('qos recorded');
        return false;
    },
    /**
     * @description 清除缓存中的记录
     */
    clearRecord: () => {
        localStorage.removeItem('historyArr');
    },
    /**
     * @description 获取记录的历史
     * @returns 历史记录数组
     */
    getRecord: () => {
        let historyArr;
        try {
            historyArr = JSON.parse(localStorage.getItem('historyArr') || '[]');
        } catch (e) {
            console.error(e);
            console.error(`cause:${localStorage.getItem('historyArr')}`);
            document.defaultView.qos.clearRecord();
            historyArr = [];
        }
        return historyArr;
    }
};