Website Blocker with Password Protection

Block access to specific websites with password protection

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Website Blocker with Password Protection
// @namespace    http://tampermonkey.net/
// @version      1.3
// @license      MIT
// @description  Block access to specific websites with password protection
// @match        *://*/*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';
    const PASSWORDS = ["RedPeach9002!", "Charles17578!"]; // Set the passwords here
    const ERROR_PAGE = "https://example.com/error.html"; // Set the custom error page URL here
    const BLOCKED_URLS = [
        {
            url: "https://classroom.google.com/",
            message: "Enter the password to access Google Classroom"
        },
        {
            url: "https://hac20.esp.k12.ar.us/",
            message: "Enter the password to access Hac20"
        },
        {
            url: "https://www.youtube.com/",
            message: "Enter the password to access YouTube"
        },
        {
            url: "https://docs.google.com/",
            message: "Enter the password to access Google Docs"
        },
        {
            url: "https://clever.discoveryeducation.com/",
            message: "Enter the password to access Clever"
        },
        {
            url: "https://www.desmos.com/",
            message: "Enter the password to access Desmos"
        },
        {
            url: "https://chrome.google.com/webstore/detail/prodigy-hacking-extension/cddgplffojbmjffebkmngmmlhkkhfibp",
            message: "Enter the password to access Prodigy Hacks"
        }
    ];
    const PASSWORD_CACHE_TIME = 300 * 1000; // Password cache time in milliseconds (5 minutes)
    const currentPage = window.location.href;
    let isBlocked = false;
    let message = "";
    for (let i = 0; i < BLOCKED_URLS.length; i++) {
        const blockedUrl = BLOCKED_URLS[i];
        if (currentPage.startsWith(blockedUrl.url)) {
            isBlocked = true;
            message = blockedUrl.message;
            break;
        }
    }
    if (isBlocked) {
        const cachedPassword = GM_getValue("password_cache", {});
        if (currentPage in cachedPassword && (Date.now() - cachedPassword[currentPage].time) < PASSWORD_CACHE_TIME) {
            // Password is cached and not expired, continue to website
            return;
        }
        const password = prompt(message);
        if (!PASSWORDS.includes(password)) {
            // Redirect to custom error page with message
            window.location.href = ERROR_PAGE + "?message=Incorrect password";
        } else {
            // Cache the password for this page
            cachedPassword[currentPage] = {password: password, time: Date.now()};
            GM_setValue("password_cache", cachedPassword);
        }
    }
})();