Greasy Fork

Greasy Fork is available in English.

四击关闭页面

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name 四击关闭页面
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 四击页面任意位置即可关闭页面
// @author 捈荼
// @license MIT
// @match http*://*/*
// @match file:///*/*
// @match edge://*
// @match chrome-extension://*
// @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);
    });
})();