🏠 Home 

四击关闭页面

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


ติดตั้งสคริปต์นี้?
สคริปต์ที่แนะนำของผู้เขียน

คุณอาจชื่นชอบ 百度搜索引擎推广参数移除


ติดตั้งสคริปต์นี้
  1. // ==UserScript==
  2. // @name 四击关闭页面
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.4
  5. // @description 四击页面任意位置即可关闭页面
  6. // @author 捈荼
  7. // @license Apache License 2.0
  8. // @match *://*/*
  9. // @require https://greasyfork.org/scripts/453846-string-format/code/string%20format.js
  10. // @run-at document-start
  11. // @grant unsafeWindow
  12. // @grant window.close
  13. // @grant GM_log
  14. // ==/UserScript==
  15. // commented by ChatGPT
  16. function nclickEvent(n, interval, dom, fn) {
  17. "use strict";
  18. // Convert the incoming n parameter to an integer and set it to 1 if it is less than 1
  19. n = parseInt(n) < 1 ? 1 : parseInt(n);
  20. // Define variables count and lastTime to track the number of consecutive clicks and the time of the last click event
  21. let count = 0, lastTime = 0;
  22. // Define the handler function
  23. let handler = (event) => {
  24. // Record the current time
  25. let currentTime = new Date().getTime();
  26. // Compare the time difference between the current time and the time of the last click event
  27. // If the time difference is less than the specified interval, increment the count variable by 1;
  28. // If the time difference is greater than or equal to the interval, reset the count variable to 0
  29. count = (currentTime - lastTime) < interval ? count + 1 : 0;
  30. GM_log('click event: last since {} ms;\nconsecutive {} times.\n'.format(currentTime - lastTime, count + 1));
  31. // Record the current time
  32. lastTime = new Date().getTime();
  33. // If count is greater than or equal to n - 1, call the callback function fn and reset the count variable to 0
  34. if (count >= n - 1) {
  35. fn(event, n);
  36. count = 0;
  37. }
  38. };
  39. // Add a click event listener to the given DOM element with the handler function as the event handler
  40. dom.addEventListener('click', handler);
  41. }
  42. (function () {
  43. "use strict";
  44. // Listen for click events and call the callback function when 4 consecutive clicks are detected
  45. nclickEvent(4, 250, document, (_event, n) => {
  46. GM_log(n + 'click');
  47. window.opener = null;
  48. window.open('', '_self');
  49. setTimeout(() => window.close(), 1);
  50. });
  51. })();