YouTube Warning Popup (MDL)

Shows a Material Design Lite warning popup when you load YouTube

当前为 2025-08-13 提交的版本,查看 最新版本

// ==UserScript==
// @name         YouTube Warning Popup (MDL)
// @namespace    https://greasyfork.org/en/users/yourname
// @version      1.0
// @description  Shows a Material Design Lite warning popup when you load YouTube
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Inject MDL and dialog polyfill styles
    const mdlCSS = document.createElement('link');
    mdlCSS.rel = 'stylesheet';
    mdlCSS.href = 'https://code.getmdl.io/1.3.0/material.indigo-pink.min.css';
    document.head.appendChild(mdlCSS);

    const polyfillCSS = document.createElement('link');
    polyfillCSS.rel = 'stylesheet';
    polyfillCSS.href = 'https://cdnjs.cloudflare.com/ajax/libs/dialog-polyfill/0.5.6/dialog-polyfill.min.css';
    document.head.appendChild(polyfillCSS);

    // Inject MDL and dialog polyfill scripts
    const mdlJS = document.createElement('script');
    mdlJS.src = 'https://code.getmdl.io/1.3.0/material.min.js';
    document.head.appendChild(mdlJS);

    const polyfillJS = document.createElement('script');
    polyfillJS.src = 'https://cdnjs.cloudflare.com/ajax/libs/dialog-polyfill/0.5.6/dialog-polyfill.min.js';
    document.head.appendChild(polyfillJS);

    // Wait for scripts to load
    polyfillJS.onload = function () {
        // Create dialog HTML
        const dialog = document.createElement('dialog');
        dialog.id = 'ytWarningDialog';
        dialog.innerHTML = `
            <h4 class="mdl-dialog__title">⚠ YouTube Warning</h4>
            <div class="mdl-dialog__content">
              <p>
                You are about to access YouTube.<br>
                Some content may be inappropriate or distracting.<br>
                Please proceed with awareness.
              </p>
            </div>
            <div class="mdl-dialog__actions">
              <button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="proceedBtn">
                Proceed
              </button>
            </div>
        `;
        document.body.appendChild(dialog);

        // Register polyfill
        if (!dialog.showModal) {
            dialogPolyfill.registerDialog(dialog);
        }

        // Show popup after short delay
        setTimeout(() => dialog.showModal(), 1000);

        // Close on proceed
        document.getElementById('proceedBtn').addEventListener('click', () => {
            dialog.close();
        });
    };
})();