letsmain / 油管自由访问突破地域限制,尽情畅享YouTube!

// ==UserScript==
// @name         油管自由访问突破地域限制,尽情畅享YouTube!
// @namespace    YouTube-Access-Assistant
// @version      1.0.6
// @description  无论您身处哪个国家或地区,这个脚本将为您打开通往YouTube的大门,让您畅快观看各类精彩视频、追踪最新趋势和与全球用户互动,YouTube自由浏览插件/代理YouTube脚本/油猴脚本YouTube解封器/浏览被封锁脚本/绕过审查YouTube浏览/自由访问YouTube的脚本/突破网络封锁的视频分享工具,您将能够无缝地浏览、搜索和观看您喜爱的视频内容,包括音乐、娱乐、教育、时事和更多。与此同时,该脚本支持多语言功能,让您能够以中英文等多种语言进行搜索和交流!
// @author       YouTube-Access-Assistant
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAsVBMVEX/////AAAoKCgAAAAMDAz4+PgjIyPFxcUZGRlGRkaNjY0fHx8WFhbr6+tsbGweHh5cXFycnJx0dHT/4ODX19c1NTWAgICrq6sSEhIKCgr/6Ojv7+//mZm+vr6Xl5fLy8v/YmL/Ly//Fhb/k5P/ICD/09NSUlKFhYU+Pj6lpaVkZGT/vr7/p6f/i4v/d3f/aGj/UVH/QUH/r6//8/P/wsL/SUn/hob/Vlb/eHj/wMDg4ODnNabOAAAFwklEQVR4nO2aa3+iOBSHI0Gk3lAHFWrVaadVsbftdjq76/f/YJtzEvBK5ebM7P7+zyukEPKQy8kJFQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4L/I9cPj083zy+vXP95u7+9qe9zd3b59fH19+XHz9Phw/atrWoT3b7e1HNw/X9qyMVXMqyvvMY+e5im5uc6c+pFK/ZCjK4bStuWiMsE/8wvWat/iu68kYX44dDw887yGPODq6JIrx7KcXlWC10UEa7UHc3sUWJYlO3w8keq4PTtnGFp7nFCp1vC1mOGbuX1DVvaUj+dUd+n/bobFBGu1d3O/pyrpNvmw3ybbcw9sSF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NowIYdhFetSYQIDh4iLGrrJDmQlhplzi1iGtS5p6M4mHUN2wQrywwPD6MLRIjflc/wDw8N4WDLiG8N6EvFzU36f5sAwWcmYXbh5Nau2raHV645GOQxL77UdGnJETnamuHZVrLxX8cq7Lh3Py7HyLr9femhYT9JCThRpJzUyXe20Iae2Vophkj3RnZyTbZLNkoyU3vM+NNTVSxLFXtyYlLX623C9NdTJYMe8kW1+2PbNnSyWJE2cKB5/rvqEooa7wWLPcEzHrUW0oA4W0oDUizp71NU7VAeGtAmpumlzFXh7ho5cLPgjDnd5bmBnFY04Ocs1qZb89nRsKDyuH2+omA1ibjrLawVNSmQPDKd6i8l15Li920tXrqNTFp0MNm0ulV9HmGuzreT3Q2NIbzY0hhuzmah6ZqhDc1+vudpXYuQeGYphS4tENGF6sWE474bxeWYRf5Xz8mxEEeW+ARtDGQSBNIais5ah+h3K7sScWUo7sKVat0bqQjZc8h1sOFnRSVf157YdSBp0K3W7mkBnMrRDmfTIWcClyG6eFQ1T6jv+aerz8Xg83+lLnel4Okm93FcXny5m2tjtkL4qxc+/r/8b/i/GRfh//z8NAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMCv5V8LFXt2dpAA1AAAAABJRU5ErkJggg==
// @require      http://cdn.staticfile.org/jquery/1.12.0/jquery.min.js
// @supportURL   http://letsmain.com/youtube-access-master?utm_source=openuserjs
// @include      *://*.youtube.com/*
// @match        *://www.youtube.com/*
// @include      *://*.bing.com/*
// @include      *://*.yandex.com/*
// @include      *://*.duckduckgo.com/*
// @include      *://*.baidu.com/*
// @include      *://*.sogou.com/*
// @include      *://*.so.com/*
// @include      *://*.sm.cn/*
// @include      *://*.startpage.com/*
// @include      *://*.fsoufsou.com/*
// @include      *://*.deepl.com/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_download
// @grant        GM_addStyle
// @grant        GM_openInTab
// @grant        unsafeWindow
// @run-at       document-idle
// @run-at       document-start
// @grant        GM_setClipboard
// @grant        GM_getResourceURL
// @grant        GM_getResourceURL
// @grant        GM_getResourceText
// @grant        GM_xmlhttpRequest
// @compatible	 Chrome
// @compatible	 Edge
// @compatible	 Firefox
// @compatible	 Safari
// @compatible	 Opera
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    var $ = window.jQuery;
    if (!$) {
        var script = document.createElement('script');
        script.src = 'https://code.jquery.com/jquery-3.6.1.min.js';
        document.head.appendChild(script);
        $ = window.jQuery;
    }
    var currentUrl = window.location.href;
    var currentHost = window.location.host;
    var resourceAnalysis = {};
    resourceAnalysis.addHtml = function() {
        var logoImgUrl = GM_getResourceURL('logo');
        var floatBoxHtml = '<div style="position:fixed;z-index:1076134;cursor:pointer;top:68px;left:0px;">' +
            '<div id="access-helper-wrap" style="width:136px;height:28px;line-height:28px;text-align:center;font-size:12px;color:#fff;background-color:#7C3AED;border:1px solid #7C3AED;border-left:none;border-top-right-radius:5px;border-bottom-right-radius:5px;">' +
            '<img src="' + logoImgUrl + '" style="width:20px;height:20px;position:relative;top:5px;" />&nbsp;YouTube访问助手' +
            '</div>' +
            '<div id="access-helper-url-wrap" style="font-size:12px;padding:6px 4px;">' +
            '<a href="http://letsmain.com/youtube-access-master?utm_source=greasyfork-recommend" target="_blank" style="color:#3b8cff;text-decoration:none">http://letsmain.com/youtube-access-master</a>' +
            '</div>' +
            '</div>';
        $('body').append(floatBoxHtml);
        var defaultVipUrl = 'http://letsmain.com/youtube-access-master?utm_source=greasyfork-recommend&invitation-code=#';
        $('body').on('click', '#access-helper-wrap', function() {
            defaultVipUrl = defaultVipUrl.replace(/#/g, encodeURIComponent(currentUrl));
            window.open(defaultVipUrl, '_blank');
        });
    };
    resourceAnalysis.init = function() {
        resourceAnalysis.addHtml();
    };
    resourceAnalysis.init();
    const options = {
        hookEvents: ["contextmenu", "select", "selectstart", "copy", "cut", "dragstart"],
        unhookEvents: ["mousedown", "mouseup", "keydown", "keyup"],
        doms: true,
        hookAddEventListener: true,
        hookPreventDefault: true,
        addCss: true,
        iframeSrc: "about:blank",
    };
    const shouldNotHook = (event) => !!event.closest("form");
    const clearEvents = () => {
        const targets = [
                document,
                document.body,
                ...document.getElementsByTagName("div"),
            ];
        const iframe = document.querySelector(`iframe[src="${options.iframeSrc}"]`);
        if (
            iframe &&
            iframe.clientWidth > 99 &&
            iframe.clientHeight > 11
        ) {
            targets.push(
                iframe.contentWindow.document,
                iframe.contentWindow.document.body
            );
        }
        for (const target of targets) {
            if (!target) continue;
            for (const eventType of options.hookEvents.concat(options.unhookEvents)) {
                const prop = "on" + eventType;
                target[prop] = null;
            }
        }
    };
    const hookEvents = (originalAddEventListener) => {
        const newAddEventListener = function (type, listener, options) {
            const useCapture =
                typeof options === "boolean" ? options : options && options.capture;
            if (!options.hookEvents.includes(type)) {
                originalAddEventListener.call(this, type, listener, useCapture);
            } else {
                originalAddEventListener.call(this, type, (e) => {
                    if (shouldNotHook(e) || !options.hookEvents.includes(e.type)) {
                    e.preventDefault();
                } else {
                    listener(e);
                }
            }, useCapture);
        }
    };
    EventTarget.prototype.addEventListener = newAddEventListener;
    document.addEventListener = newAddEventListener;
};
const hookPreventDefault = (originalPreventDefault, eventNames) => {
    Event.prototype.preventDefault = function () {
        if (shouldNotHook(this) || !eventNames.includes(this.type)) {
            originalPreventDefault.call(this);
        }
    };
};
const addCss = () => {
    GM_addStyle(`
    html, * {
        -webkit-user-select: text !important;
        -moz-user-select: text !important;
        user-select: text !important;
    }

::-moz-selection {
        color: #FFF!important;
        background: #3399FF!important;
    }

::selection {
        color: #FFF!important;
        background: #3399FF!important;
    }
  `);
};
const init = () => {
    if (options.doms) {
        setInterval(clearEvents, 9000);
        setTimeout(clearEvents, 1000);
        window.addEventListener("load", clearEvents, true);
    }
    if (options.hookAddEventListener) {
        hookEvents(EventTarget.prototype.addEventListener);
    }
    if (options.hookPreventDefault) {
        hookPreventDefault(
            Event.prototype.preventDefault,
            options.hookEvents.concat(options.unhookEvents)
        );
    }
    if (options.addCss) {
        addCss();
    }
};
init();
})();