Website Blocker with Password Protection

Block access to specific websites with password protection

目前为 2023-04-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Website Blocker with Password Protection
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @license MIT
  6. // @description Block access to specific websites with password protection
  7. // @match https://classroom.google.com/*
  8. // @match https://hac20.esp.k12.ar.us/*
  9. // @match https://www.youtube.com/*
  10. // @match https://docs.google.com/*
  11. // @match https://clever.discoveryeducation.com/*
  12. // @match https://www.desmos.com/*
  13. // @match https://chrome.google.com/webstore/detail/prodigy-hacking-extension/cddgplffojbmjffebkmngmmlhkkhfibp
  14. // @grant GM_setValue
  15. // @grant GM_getValue
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20. const PASSWORDS = ["RedPeach9002!", "Charles17578!"]; // Set the passwords here
  21. const ERROR_PAGE = "https://example.com/error.html"; // Set the custom error page URL here
  22. const BLOCKED_URLS = [
  23. {
  24. url: "https://classroom.google.com/",
  25. message: "Enter the password to access Google Classroom"
  26. },
  27. {
  28. url: "https://hac20.esp.k12.ar.us/",
  29. message: "Enter the password to access Hac20"
  30. },
  31. {
  32. url: "https://www.youtube.com/",
  33. message: "Enter the password to access YouTube"
  34. },
  35. {
  36. url: "https://docs.google.com/",
  37. message: "Enter the password to access Google Docs"
  38. },
  39. {
  40. url: "https://clever.discoveryeducation.com/",
  41. message: "Enter the password to access Clever"
  42. },
  43. {
  44. url: "https://www.desmos.com/",
  45. message: "Enter the password to access Desmos"
  46. },
  47. {
  48. url: "https://chrome.google.com/webstore/detail/prodigy-hacking-extension/cddgplffojbmjffebkmngmmlhkkhfibp",
  49. message: "Enter the password to access Prodigy Hacks"
  50. }
  51. ];
  52. const PASSWORD_CACHE_TIME = 300 * 1000; // Password cache time in milliseconds (5 minutes)
  53. const currentPage = window.location.href;
  54. let isBlocked = false;
  55. let message = "";
  56. for (let i = 0; i < BLOCKED_URLS.length; i++) {
  57. const blockedUrl = BLOCKED_URLS[i];
  58. if (currentPage.startsWith(blockedUrl.url)) {
  59. isBlocked = true;
  60. message = blockedUrl.message;
  61. break;
  62. }
  63. }
  64. if (isBlocked) {
  65. const cachedPassword = GM_getValue("password_cache", {});
  66. if (currentPage in cachedPassword && (Date.now() - cachedPassword[currentPage].time) < PASSWORD_CACHE_TIME) {
  67. // Password is cached and not expired, continue to website
  68. return;
  69. }
  70. const password = prompt(message);
  71. if (!PASSWORDS.includes(password)) {
  72. // Redirect to custom error page with message
  73. window.location.href = ERROR_PAGE + "?message=Incorrect password";
  74. } else {
  75. // Cache the password for this page
  76. cachedPassword[currentPage] = {password: password, time: Date.now()};
  77. GM_setValue("password_cache", cachedPassword);
  78. }
  79. }
  80. })();