三击关闭页面

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

当前为 2022-11-13 提交的版本,查看 最新版本

// ==UserScript==
// @name 三击关闭页面
// @namespace http://tampermonkey.net/
// @version 1.0.4
// @description 三击页面任意位置即可关闭页面
// @author 捈荼
// @license Apache License 2.0
// @match *://*/*
// @require https://greasyfork.org/scripts/453846-string-format/code/string%20format.js
// @run-at document-start
// @grant unsafeWindow
// @grant window.close
// @grant GM_log
// ==/UserScript==
 
 
 
function nclickEvent(n, interval, dom, fn) {
    "use strict";
 
    n = parseInt(n) < 1 ? 1 : parseInt(n);
    let count = 0, lastTime = 0;
    let handler = (event) => {
        let currentTime = new Date().getTime();
        count = (currentTime - lastTime) < interval ? count + 1 : 0;
        GM_log('click event: last since {} ms;\nconsecutive {} 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 () {
    "use strict";
 
    nclickEvent(3, 250, document, (_event, n) => {
        GM_log(n + 'click');
        window.opener = null;
        window.open('', '_self');
        setTimeout(() => window.close(), 1);
    });
})();