Browsing Reminder Client

Remind you when you waste too much time on specified websites.

  1. // ==UserScript==
  2. // @name Browsing Reminder Client
  3. // @namespace JustSong
  4. // @version 0.2
  5. // @description Remind you when you waste too much time on specified websites.
  6. // @author JustSong
  7. // @require https://cdn.jsdelivr.net/npm/toastify-js
  8. // @require https://cdn.jsdelivr.net/npm/sweetalert2@10
  9. // @match https://www.zhihu.com/*
  10. // @match https://*.youtube.com/*
  11. // @match https://*.bilibili.com/*
  12. // @match https://*.reddit.com/*
  13. // @match https://zh.wikipedia.org/*
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. 'use strict';
  18. const serverUrl = "https://ping.iamazing.cn";
  19. const pingInterval = 60; // Unit is second.
  20. const maxMinutes = 10;
  21. const needConfirm = true;
  22. window.pingServer = function () {
  23. console.log("ping~");
  24. fetch(serverUrl, {
  25. method: 'POST',
  26. mode: 'cors',
  27. headers: {
  28. 'Content-Type': 'application/json'
  29. },
  30. body: JSON.stringify({
  31. Host: window.location.hostname
  32. })
  33. }).then(function (response) {
  34. return response.text().then(function (minutes) {
  35. let counter = parseInt(minutes);
  36. window.processRequest(counter);
  37. })
  38. }).catch(function (reason) {
  39. console.log(reason)
  40. })
  41. };
  42. window.processRequest = function (minutes) {
  43. window.toast(`You have wasted ${minutes} minutes.`);
  44. if (minutes >= maxMinutes) {
  45. if (needConfirm) {
  46. // choose = confirm(`You have wasted ${minutes} minutes in this site, would you like to close it?`);
  47. Swal.fire({
  48. title: 'Notice',
  49. text: `You have wasted ${minutes} minutes in this site, would you like to close it?`,
  50. icon: 'warning',
  51. showCancelButton: true,
  52. confirmButtonText: 'Ok',
  53. cancelButtonText: 'Nope'
  54. }).then((result) => {
  55. if (result.dismiss === Swal.DismissReason.cancel) {
  56. Swal.fire(
  57. 'Notice',
  58. 'The timer has been reset.',
  59. 'error'
  60. )
  61. fetch(`${serverUrl}/clear`, {
  62. method: 'POST',
  63. mode: 'cors',
  64. headers: {
  65. 'Content-Type': 'application/json'
  66. },
  67. body: JSON.stringify({
  68. Host: window.location.hostname
  69. })
  70. }).finally()
  71. } else {
  72. window.location.href = "https://google.com";
  73. }
  74. })
  75. } else {
  76. window.location.href = "https://google.com";
  77. }
  78. }
  79. };
  80. window.insertCSS = function () {
  81. let head = document.getElementsByTagName('head')[0];
  82. let styleElement = document.createElement('style');
  83. styleElement.innerHTML = `.toastify{padding:12px 20px;color:#fff;display:inline-block;box-shadow:0 3px 6px -1px rgba(0,0,0,.12),0 10px 36px -4px rgba(77,96,232,.3);background:-webkit-linear-gradient(315deg,#73a5ff,#5477f5);background:linear-gradient(135deg,#73a5ff,#5477f5);position:fixed;opacity:0;transition:all .4s cubic-bezier(.215,.61,.355,1);border-radius:2px;cursor:pointer;text-decoration:none;max-width:calc(50% - 20px);z-index:2147483647}.toastify.on{opacity:1}.toast-close{opacity:.4;padding:0 5px}.toastify-right{right:15px}.toastify-left{left:15px}.toastify-top{top:-150px}.toastify-bottom{bottom:-150px}.toastify-rounded{border-radius:25px}.toastify-avatar{width:1.5em;height:1.5em;margin:-7px 5px;border-radius:2px}.toastify-center{margin-left:auto;margin-right:auto;left:0;right:0;max-width:fit-content;max-width:-moz-fit-content}@media only screen and (max-width:360px){.toastify-left,.toastify-right{margin-left:auto;margin-right:auto;left:0;right:0;max-width:fit-content}}`;
  84. head.appendChild(styleElement);
  85. }
  86. window.insertCSS();
  87. window.toast = function (message) {
  88. Toastify({
  89. text: message,
  90. duration: 5000,
  91. close: false,
  92. gravity: "bottom",
  93. position: "center",
  94. backgroundColor: "#ea4335",
  95. stopOnFocus: true,
  96. }).showToast();
  97. };
  98. window.pingServer();
  99. let timer = setInterval(window.pingServer, pingInterval * 1000);
  100. document.addEventListener("visibilitychange", function () {
  101. if (document.visibilityState === 'visible') {
  102. window.pingServer();
  103. timer = setInterval(window.pingServer, pingInterval * 1000);
  104. } else {
  105. clearInterval(timer)
  106. }
  107. });
  108. })();

QingJ © 2025

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