Website Blocker with Password Protection

Block access to specific websites with password protection

当前为 2023-03-05 提交的版本,查看 最新版本

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