Access Control For Maintaning Mindfulness

Allow YouTube access only during specified hours

目前为 2024-11-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Access Control For Maintaning Mindfulness
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Allow YouTube access only during specified hours
  6. // @author KQ yang
  7. // @match *://*.youtube.com/*
  8. // @match *://*.reddit.com/*
  9. // @match *://*.zhihu.com/*
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. // Configuration variables
  15. const CONFIG = {
  16. startHour: 12, // Access start time (24-hour format)
  17. endHour: 14, // Access end time (24-hour format)
  18. messageStyle: "background-color: white; margin-top: 20vh; margin-left: 100px; margin-right: 100px; font-size:64px",
  19. blockMessage: `
  20. <h1 style="background-color: white;margin-top: 20vh;margin-left: 100px;margin-right: 100px;font-size:64px">
  21. Dear Me!<br>
  22. You preserved this page 👍<br><br>
  23. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;👏 Congratulations! You successfully maintained mindfulness! Well done!👏<br><br>
  24. This is restricted time.<br>
  25. Welcome back between 12:00 and 14:00.
  26. </h1>`
  27. };
  28.  
  29. (function() {
  30. 'use strict';
  31.  
  32. // Get current time
  33. const now = new Date();
  34. const hours = now.getHours();
  35. const minutes = now.getMinutes();
  36.  
  37. // Check if current time is within allowed range
  38. if (hours < CONFIG.startHour || (hours >= CONFIG.endHour && minutes > 0)) {
  39. // If outside allowed time range, replace page content with warning message
  40. document.body.innerHTML = CONFIG.blockMessage;
  41. }
  42. })();