Website Blocker with Password Protection

Block access to specific websites with password protection

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