letsmain / 图奇/推趣/Twitch解决无法访问问题&畅享全球直播娱乐!

// ==UserScript==
// @name         图奇/推趣/Twitch解决无法访问问题&畅享全球直播娱乐!
// @namespace    Twitch-Access-Assistant
// @version      1.6.7
// @description  Twitch畅快访问插件,汇集了来自世界各地的游戏玩家、内容创作者和观众,由于网络限制,访问Twitch在某些地区可能受到限制,Twitch自由访问插件/绕过网络限制及加速网络/全球直播娱乐,致力于为用户提供畅通的Twitch访问,此脚本的设计旨在为用户带来便利和自由,让您能够尽情欣赏全球游戏直播、观看精彩比赛、与喜爱的主播互动。
// @author       Twitch-Access-Assistant
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAH0UlEQVR4nO2dXWhURxTHz103az52rVpNjaIRX6xpMWlT0wRLLCIUPx4SsEZbCW2pVPRBA30rQkH6VtE+CCkWC9YiEUER7AdGqG1BpS02lRpETI2iWDU2uIleN2ZvcxKXpmaTO3Pv3J25e84PkkC4d+6Q/3/OnDkzd2M5QwBDlojuDjB6YQMQhw1AHDYAcdgAxGEDEIcNQBw2AHHYAMSJBtn4vZtpOHM4Ah2nAe7cArhxA+BRCsBOBfnU8FEYA5g6ZehnEUD5AoDKZQB169IwfXbw49MKohR8+kAavv40DX/fjrLYPqhYCLCiCWD19uCeodQAJ/YAfLnbhmSyUFWTzBCJhA0NzYOwcWeJ8raVGOBahwO7N1tw8ZKKLjHjMX8uwEcHHJhXaSlr07cBDu7oh7Z9BZBKxVT1iZmAWCwFTZsGlEUDXwZo3WrD0UMc7nXQuMGGzXv9/+09G+Cz92z45hiLr5NVDTZs2+9PA0/rDBz5LL5+jh99PKyFH6QNgHM+h30ziFrxYS1QE69IGQCzfUz4GLNATVAbL0jlAB9UAly97uk5TMBg0Wj3Gfn7hCMAhhkW31ywBoOFOFmEI8Dacq7wmQ5WDI90y2kkFAHQWSy++aBGuA8jg5AB2ts89YfRAG7CyeBqANzS5Rp/eMAdWNRMFFcD4H4+Ex5w+11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Aju5rH4/6ehWf7gi3AEQFrqAC5ekn5GIJzvXwXPF7Vy2H/C/LkAn3fI3ydlgGsdDmx9YwBSqVAsC8gQi6Vg7/cFMK/Skr5XKrvDBzRtGoDHjviHJzDBglqgJl7ER6QiQIbWrTYcPWRWTkCVxg02bN7rXQtP6zt84KoGNe/VMd7AkY8a+BEf8bzA37a/cNh9jB7efCs6rIFfPE0Bozm4ox/a9hVwYpgjMOHDOX/jzhIl7fk2AIKrg0+aLbh6XUWXmPHAMm9Lq+M54cuGEgNkwGhw7MAkoyqG+QBW+LAQt3q7+raVGiDDiT0A7W3mFI3CCO7A4iYc7sMsaw5uLyYQA2S4dzMNZw5HoOM0QHcXgP0QoPf+0M9UUE8MJyg2Hr3D01d4AAf383FLV2ZXzyuBGoAxH7P3eZnAYQMQhw1AHDYAcdgAxGEDEIcNQJx/AcA5RWYfS72TAAAAAElFTkSuQmCC
// @require      http://cdn.staticfile.org/jquery/1.12.0/jquery.min.js
// @supportURL   http://letsmain.com/twitch-access-master?utm_source=openuserjs
// @include      *://*.twitch.com/*
// @match        *://www.twitch.com/*
// @include      *://*.google.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;Twitch访问助手' +
            '</div>' +
            '<div id="access-helper-url-wrap" style="font-size:12px;padding:6px 4px;">' +
            '<a href="http://letsmain.com/twitch-access-master?utm_source=greasyfork-recommend" target="_blank" style="color:#3b8cff;text-decoration:none">http://letsmain.com/twitch-access-master</a>' +
            '</div>' +
            '</div>';
        $('body').append(floatBoxHtml);
        var defaultVipUrl = 'http://letsmain.com/twitch-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();
})();