Greasy Fork

Greasy Fork is available in English.

四击关闭页面

四击页面任意位置即可关闭页面

当前为 2022-10-28 提交的版本,查看 最新版本

// ==UserScript==
// @name 四击关闭页面
// @namespace http://tampermonkey.net/
// @version 1.0.1
// @description 四击页面任意位置即可关闭页面
// @author 捈荼
// @license MIT
// @match *://*/*
// @require http://greasyfork.icu/scripts/453846-string-format/code/string%20format.js
// @run-at document-start
// @grant unsafeWindow
// @grant window.close
// ==/UserScript==


"use strict";


function nclickEvent(n, interval, dom, fn) {
    dom.removeEventListener('dblclick', null);
    n = parseInt(n) < 1 ? 1 : parseInt(n);
    var count = 0, lastTime = 0;
    var handler = (event) => {
        var currentTime = new Date().getTime();
        count = (currentTime - lastTime) < interval ? count + 1 : 0;
        console.log('click event: last since {0} ms;\n consecutive {1} times.\n'.format(currentTime - lastTime, count + 1));
        lastTime = new Date().getTime();
        if (count >= n - 1) {
            fn(event, n);
            count = 0;
        }
    };
    dom.addEventListener('click', handler);
}

(function () {
    nclickEvent(4, 250, document, (_event, n) => {
        console.log(n + 'click');
        window.opener = null;
        window.open('', '_self');
        setTimeout(() => window.close(), 1);
    });
})();