四击关闭页面

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

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

// ==UserScript==
// @name 四击关闭页面
// @namespace http://tampermonkey.net/
// @version 0.2
// @description 四击页面任意位置即可关闭页面
// @author 捈荼
// @license MIT
// @match http*://*/*
// @match file:///*/*
// @match edge://*
// @match chrome-extension://*
// @run-at document-start
// @grant unsafeWindow
// @grant window.close
// ==/UserScript==


'use strict';


(function () {
    if (!String.prototype.format) {
        String.prototype.format = function () {
            var args = arguments;
            return this.replace(/{(\d+)}/g, function (match, number) {
                return typeof args[number] != 'undefined' ? args[number] : match;
            });
        };
    } else {
        throw 'String.prototype.format defined.';
    }
})();

function nclickEvent(n, interval, dom, fn) {
    dom.removeEventListener('dblclick', null);
    n = parseInt(n) < 1 ? 1 : parseInt(n);
    var count = 0, lastTime = 0;
    var handler = function (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, function (event, n) {
        console.log(n + 'click');
        window.opener = null;
        window.open('', '_self');
        setTimeout(function () {
            window.close();
        }, 1);
    });
})();

QingJ © 2025

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