// ==UserScript== // @name 调整网页亮度 alt+↓(alt+方向键下) 降低亮度 // @namespace http://tampermonkey.net/ // @version 0.4 // @description 调整网页亮度,护眼 // @description:en Adjust page brightness,eyeshield // @author wodexianghua // @match http://*/* // @match https://*/* // @match file:///* // @grant GM_setValue // @grant GM_getValue // ==/UserScript== //按键: //alt+↑(alt+方向键上) 提高亮度 //alt+↓(alt+方向键下) 降低亮度 //ctrl+alt+s 打开调整界面,鼠标点击亮度条调整亮度,点击空白地方关闭调整界面 (function () { 'use strict'; //保证iframe不起作用 if (self == top) { var timer = null; var mousemove = false; var liangduui; var liangduuitz; var liangduuitzmouse; var __nightingale_view_cover; function insertHTML(lv) { if (self == top) { document.body.insertAdjacentHTML("beforebegin", '<div class="liangduui" style="display: none; 60px; height: 170px; background-color: rgb(255, 255, 255); z-index: 2147483640; position: fixed; top: 200px; left: 50%; border-radius: 50px; box-shadow: rgb(74, 74, 74) 0px 0px 20px;"><div class="liangduuitzmouse" style="40%;height:100px;background-color:#cecece;position:absolute;top:20px;left:30%;border-radius:50px;cursor:pointer"><div class="liangduuitz" style=" 100%; height: 100%; background-color: rgb(147, 112, 223); position: absolute; bottom: 0px; right: 0px; border-radius: 50px;"></div></div><div style="background-image:url(https://www.easyicon.net/api/resizeApi.php?id=1180288&size=24);24px;height:24px;position:absolute;bottom:15px;right:18px;border-radius:50%;box-shadow:0 0 10px #9370df;background-repeat:no-repeat"></div></div><div id="__nightingale_view_cover" style=" 100%; height: 100%; transition: -webkit-transform 10s ease-in-out 0s; position: fixed !important; left: 0px !important; bottom: 0px !important; overflow: hidden !important; background: rgb(0, 0, 0) !important; pointer-events: none !important; z-index: 2147483647; opacity: ' + lv + ';"></div>'); } liangduui = document.querySelector(".liangduui"); liangduuitz = document.querySelector(".liangduuitz"); liangduuitzmouse = document.querySelector(".liangduuitzmouse"); __nightingale_view_cover = document.querySelector("#__nightingale_view_cover"); liangduui.style.top = ((window.innerHeight / 2) - (liangduui.style.height.replace("px", "")/2)) + "px"; liangduui.style.left = ((window.innerWidth / 2) - (liangduui.style.width.replace("px", "")/2)) + "px"; liangduuitzmouse.addEventListener('mousedown', function (event) { mousemove = true; liangduuitz.style.height = (100 - (event.clientY - liangduui.offsetTop - liangduuitzmouse.offsetTop)) + "%" lv = (event.clientY - liangduui.offsetTop - liangduuitzmouse.offsetTop) / 100; GM_setValue("lv", lv); __nightingale_view_cover.style.opacity = lv }); liangduuitzmouse.addEventListener('mousemove', function (event) { if (!mousemove) return; if (liangduuitz.offsetTop <= 0 || liangduuitz.offsetTop > 100) return; liangduuitz.style.height = (100 - (event.clientY - liangduui.offsetTop - liangduuitzmouse.offsetTop)) + "%" lv = (event.clientY - liangduui.offsetTop - liangduuitzmouse.offsetTop) / 100; GM_setValue("lv", lv); __nightingale_view_cover.style.opacity = lv }); liangduuitzmouse.addEventListener('mouseup', function (event) { mousemove = false; }); } if (GM_getValue("lv") == undefined) { GM_setValue("lv", '0.35'); } document.addEventListener('keydown', function (event) { if (event.altKey && event.which == 40) { var lv = parseFloat(GM_getValue("lv")); lv += 0.02; if (lv > 1.0) lv = 1.0; GM_setValue('lv', lv); __nightingale_view_cover.style.opacity = lv; liangduui.style.display = "block"; liangduuitz.style.height = (100 - (lv * 100)) + "%"; window.clearTimeout(timer); timer = setTimeout(function () { liangduui.style.display = "none"; }, 2000); } else if (event.altKey && event.which == 38) { var lv = parseFloat(GM_getValue("lv")); lv -= 0.02; if (lv < 0) lv = 0; GM_setValue("lv", lv); __nightingale_view_cover.style.opacity = lv; liangduui.style.display = "block"; liangduuitz.style.height = (100 - (lv * 100)) + "%"; window.clearTimeout(timer); timer = setTimeout(function () { liangduui.style.display = "none"; }, 2000); } else if (event.ctrlKey && event.altKey && event.which == 83) { liangduuitz.style.height = (100 - (GM_getValue("lv") * 100)) + "%" liangduui.style.display = "block"; } }); document.addEventListener('visibilitychange', function () { if (document.visibilityState == 'hidden') { //状态判断 } else { var lv = parseFloat(GM_getValue("lv")); if (document.querySelector("#__nightingale_view_cover") == null) { insertHTML(GM_getValue("lv")); } GM_setValue("lv", lv); document.querySelector("#__nightingale_view_cover").style.opacity = lv } }); document.body.addEventListener('click', function () { liangduui.style.display = "none"; mousemove = false; }); // window.addEventListener("storage", function(event) { // console.log(event.key + '=' +event.newValue); // }); setTimeout(insertHTML(GM_getValue("lv")), 300); } // Your code here... })();
// ==UserScript== // @name 网页护眼壁纸 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 为网页增加一个好看、护眼的壁纸 // @author 吉王义昊 // @match https://*/* // @match http://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // Your code here... var huyanbeijinguserjsbyjwyh=document.createElement("div"); huyanbeijinguserjsbyjwyh.style="z-index: -999;position: fixed;transform: translate(-4%,-4%);background-position: 50%;transition-property: background-image,background-color;filter: blur(20px);height: calc(100% + 80px); calc(100% + 80px);background-image: url(https://ufile.ahgygl.com/userjs/huyanuserjsbyjwyh/green.jpg);"; document.body.insertBefore(huyanbeijinguserjsbyjwyh,document.body.firstChild); })();
// ==UserScript== // @name 当你发现有人窥屏,就按 F2按 ESC 消除 防窥屏 // @namespace https://greasyfork.org/zh-CN/scripts/389727 // @version 0.3.1 // @description 当你发现有人窥屏,就按 F2。按 ESC 消除。 // @author Phuker // @match *://*/* // @grant none // @run-at document-start // ==/UserScript== /* Forked from jinyu121/ShameEyesdroper.user.js https://gist.github.com/jinyu121/9e028686f35f330b52f60a30e7ef8ba3 */ (function() { 'use strict'; // - - - - - - - - - - 用户配置开始 Start User Config - - - - - - - - - - // 显示文本 // display text var option_text = '有沙雕正在窥屏'; // 不透明度,0.0 - 1.0,数值越大越不透明,建议 0.6 - 1.0 // opacity, 0.0 - 1.0 var option_opacity = '0.85'; // 主题 // color theme var option_theme = 'golden'; // 触发和恢复按键 // keys var option_key_activate = 'F2'; var option_key_cancel = 'Escape'; // - - - - - - - - - - 用户配置结束 End User config - - - - - - - - - - // background, text var option_themes = { 'golden': ['#17254D', '#F0E360'], // 土豪金 'normal': ['#fff', '#666'], // 普通 白底黑字 'dark': ['#333', '#ccc'], // 黑底白字 暗黑主题 'slate': ['#19191f', '#ebebf4'], // 蓝灰 暗色 } var option_background_color = option_themes[option_theme][0]; var option_text_color = option_themes[option_theme][1]; function AntiPeepScreen(){ var svg='<svg width="600" height="400" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <rect width="100%" height="100%" style="fill:' + option_background_color + ';" /> <text style="font-weight:bold; font-size:72px; fill:' + option_text_color + ';" transform="matrix(.70710678 -.70710678 .70710678 .70710678 -52.549041 262.010392)" x="26.015705" y="220.4375">'+ option_text +'</text> </svg>'; var bg_text="url(data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(svg)))+")"; var div = document.createElement('div'); div.className = 'phuker-anti-peep-screen'; div.style.cssText = ' z-index:65535; position:fixed; top:0; left:0; bottom:0; right:0; opacity:' + option_opacity + '; background-image:' + bg_text + '; background-repeat:repeat; background-position:center; overflow":"hidden"; '; document.body.appendChild(div); }; function ClearAntiPeepScreen(){ document.getElementsByClassName('phuker-anti-peep-screen')[0].remove(); } document.addEventListener("keydown", function(e){ if(e.key === option_key_activate){ AntiPeepScreen(); document.phuker_anti_peep_level = (document.phuker_anti_peep_level | 0) + 1; } if(e.key === option_key_cancel){ if(document.phuker_anti_peep_level){ ClearAntiPeepScreen(); e.preventDefault(); document.phuker_anti_peep_level -= 1; } } }); })();
// ==UserScript== // @name Disable Adblock Hider // @namespace Jefreesujit // @version 0.1 // @description Removes the notification reminder to disable the adblocker plugin // @author Jefreesujit // @match http://hitwicket.com/* // @match http://hitwicket.com // @grant none // ==/UserScript== $(document).ready(function() { setTimeout(function() { if($('#advertisement_top_banner_div').height() == 0) $('#advertisement_top_banner_div').load(" "); } , 1500); });
// ==UserScript== // @name Anti-adblocker重点是ready // @namespace https://openuserjs.org/users/Goodgy // @updateURL https://openuserjs.org/meta/Goodgy/Anti-adblocker.meta.js // @downloadURL https://openuserjs.org/src/scripts/Goodgy/Anti-adblocker.user.js // @version 1.1 // @description Removes any notification that tells you to disable adblock. // @author Goodgy // @require https://code.jquery.com/jquery-3.1.0.min.js // @include http*://*deviantart.com/* // @include http*://*.deviantart.com/* // @match https://openuserjs.org/?q=anti-adblock // @grant none // ==/UserScript== (function() { 'use strict'; function remove_banner_deviantart(){ $('div.banner-wrap').hide(); $('div#block-notice').hide(); $('div#elnino-modal').hide(); $('div#modalfade').hide(); } function start_up(){ var current_link = $(document).attr('URL'); if (current_link.indexOf("deviantart.com") !=-1) { setInterval(remove_banner_deviantart,1); } console.log("Done"); } // If the window is loaded, start up the bot $(document).ready(function() { start_up(); }); })();
// ==UserScript== // @name Adblock Wikia--重点是ready // @namespace http://tampermonkey.net/ // @version 1.0 // @description Get rid of ads on Wikia; I developed this script so that I could avoid the no-adblocker allowed messages on the site. // @author Crimtos // @match http://*.wikia.com/* // @require http://code.jquery.com/jquery-latest.js // @grant none // ==/UserScript== // $("div").removeClass("ad-placement ad-main-med-rect-footer"); (function() { 'use strict'; $(".WikiaTopAds").remove(); $(".fan-feed").remove(); $("#WikiaTopAds").remove(); $("#TOP_RIGHT_BOXAD").remove(); // $("#NATIVE_TABOOLA_RAIL").remove(); $("#WikiaFooter").remove(); $("#WikiaArticleBottomAd").remove(); })(); $(document).ready(function(){ $(".recirculation-rail module recirculation-unit").remove(); $("#RECIRCULATION_RAIL").remove(); $("[class='ChatModule module ChatModuleUninitialized']").removeClass('ChatModule module ChatModuleUninitialized').addClass('ChatModule module'); // $("[class='ChatModule module ChatModuleUninitialized']").remove(); });
// ==UserScript== // @name lolalytics anti ad block fix重点是添加风格 // @namespace http://tampermonkey.net/ // @version 1.0 // @description disables anti adblock measures on lolalytics // @author Jeddunk // @match http://*.lolalytics.com/* // @match http://lolalytics.com/* // @grant none // @updateURL https://openuserjs.org/meta/Jeddunk/lolalytics_anti_ad_block_fix.meta.js // ==/UserScript== (function() { 'use strict'; addGlobalStyle('.wrapper {opacity: 1 !important}'); addGlobalStyle('#RXcYvSQMUpqm > p {display: none !important}'); addGlobalStyle('header > div.wrapper > div > div:nth-child(1) {height: 0 !important}'); addGlobalStyle('header > div.wrapper > div > div:nth-child(2) {display: none !important}'); })(); function addGlobalStyle(css) { var head, style; head = document.getElementsByTagName('head')[0]; if (!head) { return; } style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = css; head.appendChild(style); }
// ==UserScript== // @name Linkcrypt.ws Remove Anti Adblock // @namespace https://greasyfork.org/users/5174-jesuis-parapluie // // @description Removes anti adblock overlay and unhides container buttons // // @include http://linkcrypt.ws/dir/* // // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js // // @grant none // // @version 0.0.5 // ==/UserScript== (function ($) { "use strict"; /*jslint browser:true */ /*global $, jQuery */ var apply = function () { $('#ad_cont').css('display', ''); $('#ad_cont').attr('id', ''); $('#container_check').hide(); $('#kbf1').hide(); $('#container').show(); }; $(function () { $(document).bind('DOMNodeInserted', apply); apply(); }); }(jQuery));
// ==UserScript== // @name Close adblocker alert执行func // @namespace https://www.myfxbook.com // @version 0.3 // @description User script that automatically closes the adblocker alert which keeps popping up. Perhaps a design error. // @author angelo.ndira@gmail.com // @match https://www.myfxbook.com // @match https://www.myfxbook.com/* // @match http://www.myfxbook.com // @match http://www.myfxbook.com/* // @grant none // ==/UserScript== (function() { 'use strict'; try { closeAdBlockerLightBox(); } catch(ex) { console.log("Error occurred while closing adblocker alert. " + ex); } })();
// ==UserScript== // @name anti-adblock bypass初始化干广告 // @include /^https://.*?-fan.tv/episode.php/ // @version 1.0 // @description Bypass anti-adblock (fuckadblock.js) // @copyright 2020, CheeseSaus (https://openuserjs.org/users/CheeseSaus) // @license MIT // @updateURL https://openuserjs.org/meta/CheeseSaus/anti-adblock_bypass.meta.js // ==/UserScript== window.addEventListener("load", function (event) { adBlockNotDetected() });
// ==UserScript== // @name mouse events ad killer // @author keepcalmandbelogical // @description Disables this mouse events listeners: click, mousedown, mouseup, contextmenu, touchstart. Also disables peer connections. Script only valid for websites with href anchors for navigation // @version 0.2.6 // @include http://*divxatope*.com* // @include http://*newpct*.com* // @include http://*elitetorrent.net* // @include http://*tumejortorrent.com* // @include http://*descargas2020.com* // @grant none // @run-at document-start // @downloadURL https://openuserjs.org/install/keepcalmandbelogical/mouse_events_ad_killer.user.js // @supportURL https://openuserjs.org/scripts/keepcalmandbelogical/mouse_events_ad_killer/issues // @license MIT // ==/UserScript== /* jshint -W097 */ (function() { try { Window.prototype.RTCPeerConnection=null; } catch(e) {} try { Window.prototype.mozRTCPeerConnection=null; } catch(e) {} try { Window.prototype.webkitRTCPeerConnection=null; } catch(e) {} try { window.RTCPeerConnection=null; } catch(e) {} try { window.mozRTCPeerConnection=null; } catch(e) {} try { window.webkitRTCPeerConnection=null; } catch(e) {} Window.prototype.addEventListener=(function() { var f=Window.prototype.addEventListener; return function(type,handler) { switch(type.toLowerCase()) { case "click": case "mousedown": case "mouseup": case "touchstart": case "contextmenu": break; default: f.apply(this,arguments); break; } }; })(); window.addEventListener=Window.prototype.addEventListener; HTMLDocument.prototype.addEventListener=(function() { var f=HTMLDocument.prototype.addEventListener; return function(type,handler) { switch(type.toLowerCase()) { case "click": case "mousedown": case "mouseup": case "touchstart": case "contextmenu": break; default: f.apply(this,arguments); break; } }; })(); document.addEventListener=HTMLDocument.prototype.addEventListener; Element.prototype.addEventListener=(function() { var f=Element.prototype.addEventListener; return function(type,handler) { switch(type.toLowerCase()) { case "click": case "mousedown": case "mouseup": case "touchstart": case "contextmenu": break; default: f.apply(this,arguments); break; } }; })(); })();
// ==UserScript== // @name SolarizedLight_BackgroundColor加载后改色 // @namespace https://mpcx.me/ // @version 0.2 // @description Set BackgroundColor of article page to base3 color of SolarizedLight Theme // @author CharlesMa // @match https://sspai.com/article/* // @match https://sspai.com/post/* // @grant none // ==/UserScript== window.addEventListener('load', function() { var article = ""; switch (location.host) { case "sspai.com": var pageType = location.pathname.split('/')[1]; if (pageType == "article") { article = document.getElementsByClassName("series-article-wrapper"); } if (pageType == "post") { article = document.getElementsByClassName("article-wrapper"); } break; } article[0].style.backgroundColor = "#fdf6e3"; }, false);
// ==UserScript== // @name Inoreader - Highlights row light blue when mouse over in Article Pane // @namespace https://openuserjs.org/scripts/jg5050/Inoreader_-_Highlights_row_light_blue_when_mouse_over_in_Article_Pane // @description Change background to light blue when hovering with the mouse over headers in the article pane // @downloadURL https://github.com/jimmygoings50/Userscripts/blob/master/Inoreader_-_Highlights_Row_Light_Blue_on_Mouseover.user.js // @updateURL https://github.com/jimmygoings50/Userscripts/blob/master/Inoreader_-_Highlights_Row_Light_Blue_on_Mouseover.user.js // @author jg5050 // @version 1.0 // @domain www.inoreader.com // @domain inoreader.com // @domain beta.inoreader.com // @match https://*.inoreader.com/* // @match https://inoreader.com/* // @match http://*.inoreader.com/* // @match http://inoreader.com/* // @include https://*.inoreader.com/* // @include https://inoreader.com/* // @include http://*.inoreader.com/* // @include http://inoreader.com/* // @grant GM_addStyle // ==/UserScript== (function() { var css = "@namespace url(http://www.w3.org/1999/xhtml); div.article_subscribed:hover {background-color: rgb(173,216,230) !important; color: rgb(255,195,0) !important;} div.article_header:hover {background-color: rgb(173,216,230) !important; color: rgb(255,195,0) !important;} div.article_header:hover .article_feed_title {color: rgb(255,195,0) !important;} div.article_header:hover .article_header_title {color: rgb(255,195,0) !important;} div.article_header:hover .arrow_div {background-color: rgb(173,216,230) !important;}"; if (typeof GM_addStyle != "undefined") { GM_addStyle(css); } else if (typeof PRO_addStyle != "undefined") { PRO_addStyle(css); } else if (typeof addStyle != "undefined") { addStyle(css); } else { var heads = document.getElementsByTagName("head"); if (heads.length > 0) { var node = document.createElement("style"); node.type = "text/css"; node.appendChild(document.createTextNode(css)); heads[0].appendChild(node); } } })();
// ==UserScript== // @name 拒绝小说网站背景色、修改字体、段落距离、去除起点阅读/笔趣阁等网站广告 // @namespace https://xuexizuoye.com // @version 1.32 // @description 我不要绿色,不要护眼色,不要你觉得,就要我觉得! // @author huansheng // @include http://*/* // @include https://*/* // @exclude *www.52pojie.cn* // @exclude *chinaz.com* // @exclude *greasyfork.org* // @grant GM_addStyle // @run-at document-start // ==/UserScript== function bgcwhite(){ console.log("修改背景色,字体格式->starting……"); GM_addStyle("body,.main-text-wrap,#content,.content,#main-text-wrap,.chapter-content,#chapter-content,#contentWp,.paper-box,.content-body,.content-body,.content-ext,#content p,#htmlContent,#chaptercontent {background-color: rgba(0, 0, 0, 0) !important;font-size: 16px!important;font-family: Helvetica Neue,Arial,PingFang SC,STHeiti,Microsoft YaHei,SimHei,sans-serif!important;line-height: 130%!important}"); console.log("修改背景色,字体格式->end……"); }; //#mys-wrapper function addel(){ console.log("尝试去除广告->starting……"); GM_addStyle(".con_ad,#close-game-op,#mys-wrapper,.mys-wrapper,#google-center-div,.google-center-div,#mys-content,#GoogleActiveViewElement,.GoogleActiveViewElement,#google_image_div,.adsbygoogle,.adsbygoogle-noablate,boy.jar,.GoogleActiveViewInnerContainer,div .top-read-ad,ins.ee,img.img_ad,.GoogleActiveViewElement img,.GoogleActiveViewElement a,.top-read-ad img,.top-read-ad a,.downcode,#j-topBgBox,#j-topHeadBox .back-to-op,.right-op-wrap,.games-op-wrap,.jumpWrap,#j_bodyRecWrap,.body-rec-mask,.game-wrap,.banner-wrap,.focus-img.cf,.notice-banner,#float-op-wrap,#j_leftRecBox a,#j_leftRecBox a,.body-rec-wrap,.float-op-wrap,.notice-list>ul>li>.red,#appss>dd div {background-image: none!important;dispaly:none!important;0!important;height:0!important;margin-left:-99999px!important}"); setTimeout(function () { GM_addStyle("body>div:last-child,#cs_kd_div {background-image: none!important;dispaly:none!important;0!important;height:0!important;margin-left:-99999px!important;z-index:0!important;overflow:visible!important;}"); }, 15000) console.log("尝试去除广告->end……"); }; (function() { console.log("开始修改->end……"); bgcwhite(); console.log("修改网页结束->end……"); })(); window.onload=function(){ console.log("网页加载完毕再次修改确保万一!……"); addel(); bgcwhite(); console.log("再次修改确保结束!……"); }();
// ==UserScript==// @name Inoreader - Highlights row light blue when mouse over in Article Pane// @namespace https://openuserjs.org/scripts/jg5050/Inoreader_-_Highlights_row_light_blue_when_mouse_over_in_Article_Pane// @description Change background to light blue when hovering with the mouse over headers in the article pane // @downloadURLhttps://github.com/jimmygoings50/Userscripts/blob/master/Inoreader_-_Highlights_Row_Light_Blue_on_Mouseover.user.js// @updateURLhttps://github.com/jimmygoings50/Userscripts/blob/master/Inoreader_-_Highlights_Row_Light_Blue_on_Mouseover.user.js// @author jg5050// @version 1.0// @domain www.inoreader.com // @domain inoreader.com// @domain beta.inoreader.com // @match https://*.inoreader.com/* // @match https://inoreader.com/* // @match http://*.inoreader.com/* // @match http://inoreader.com/*// @include https://*.inoreader.com/* // @include https://inoreader.com/* // @include http://*.inoreader.com/* // @include http://inoreader.com/*// @grantGM_addStyle// ==/UserScript==(function() {var css = "@namespace url(http://www.w3.org/1999/xhtml); div.article_subscribed:hover {background-color: rgb(173,216,230) !important; color: rgb(255,195,0) !important;} div.article_header:hover {background-color: rgb(173,216,230) !important; color: rgb(255,195,0) !important;} div.article_header:hover .article_feed_title {color: rgb(255,195,0) !important;} div.article_header:hover .article_header_title {color: rgb(255,195,0) !important;} div.article_header:hover .arrow_div {background-color: rgb(173,216,230) !important;}";if (typeof GM_addStyle != "undefined") {GM_addStyle(css);} else if (typeof PRO_addStyle != "undefined") {PRO_addStyle(css);} else if (typeof addStyle != "undefined") {addStyle(css);} else {var heads = document.getElementsByTagName("head");if (heads.length > 0) {var node = document.createElement("style");node.type = "text/css";node.appendChild(document.createTextNode(css));heads[0].appendChild(node); }}})();
// ==UserScript== // @name 解除网页限制-github是重点 // @namespace http://github.com/rxliuli/userjs // @version 2.2.3 // @description 破解禁止复制/剪切/粘贴/选择/右键菜单的网站 // @author rxliuli // @include * // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_listValues // @grant GM_registerMenuCommand // @grant GM_addStyle // @grant GM_xmlhttpRequest // @grant unsafeWindow // 这里的 @run-at 非常重要,设置在文档开始时就载入脚本 // @run-at document-start // @license MIT // ==/UserScript== ; (() => { /** * 安全执行某个函数 * 支持异步函数 * @param fn 需要执行的函数 * @param defaultVal 发生异常后的默认返回值,默认为 null * @param args 可选的函数参数 * @returns 函数执行的结果,或者其默认值 */ function safeExec(fn, defaultVal, ...args) { const defRes = (defaultVal === undefined ? null : defaultVal); try { const res = fn(...args); return res instanceof Promise ? res.catch(() => defRes) : res; } catch (err) { return defRes; } } /** * 兼容异步函数的返回值 * @param res 返回值 * @param callback 同步/异步结果的回调函数 * @typeparam T 处理参数的类型,如果是 Promise 类型,则取出其泛型类型 * @typeparam Param 处理参数具体的类型,如果是 Promise 类型,则指定为原类型 * @typeparam R 返回值具体的类型,如果是 Promise 类型,则指定为 Promise 类型,否则为原类型 * @returns 处理后的结果,如果是同步的,则返回结果是同步的,否则为异步的 */ function compatibleAsync(res, callback) { return (res instanceof Promise ? res.then(callback) : callback(res)); } /** * 在固定时间周期内只执行函数一次 * @param {Function} fn 执行的函数 * @param {Number} time 时间周期 * @returns {Function} 包装后的函数 */ function onceOfCycle(fn, time) { const get = window.GM_getValue.bind(window); const set = window.GM_setValue.bind(window); const LastUpdateKey = 'LastUpdate'; const LastValueKey = 'LastValue'; return new Proxy(fn, { apply(_, _this, args) { const now = Date.now(); const last = get(LastUpdateKey); if (![null, undefined, 'null', 'undefined'].includes(last) && now - last < time) { return safeExec(() => JSON.parse(get(LastValueKey)), 1); } return compatibleAsync(Reflect.apply(_, _this, args), res => { set(LastUpdateKey, now); set(LastValueKey, JSON.stringify(res)); return res; }); }, }); } /** * 解除限制 */ class UnblockLimit { /** * 监听 event 的添加 * 注:必须及早运行 */ static watchEventListener() { const documentAddEventListener = document.addEventListener; const eventTargetAddEventListener = EventTarget.prototype.addEventListener; function addEventListener(type, listener, useCapture) { const $addEventListener = this instanceof Document ? documentAddEventListener : eventTargetAddEventListener; // 在这里阻止会更合适一点 if (UnblockLimit.eventTypes.includes(type)) { console.log('拦截 addEventListener: ', type, this); return; } Reflect.apply($addEventListener, this, [type, listener, useCapture]); } document.addEventListener = EventTarget.prototype.addEventListener = addEventListener; } // 代理网页添加的键盘快捷键,阻止自定义 C-C/C-V/C-X 这三个快捷键 static proxyKeyEventListener() { const documentAddEventListener = document.addEventListener; const eventTargetAddEventListener = EventTarget.prototype.addEventListener; function addEventListener(type, listener, useCapture) { const $addEventListener = this === document ? documentAddEventListener : eventTargetAddEventListener; // 在这里阻止会更合适一点 const listenerHandler = { apply(target, thisArg, argArray) { const ev = argArray[0]; const proxyKey = ['c', 'x', 'v', 'a']; const proxyAssistKey = ['Control', 'Alt']; if ((ev.ctrlKey && proxyKey.includes(ev.key)) || proxyAssistKey.includes(ev.key)) { console.log('已阻止: ', ev.ctrlKey, ev.altKey, ev.key); return; } if (ev.altKey) { return; } // Reflect.apply(target, thisArg, argArray) }, }; Reflect.apply($addEventListener, this, [ type, UnblockLimit.keyEventTypes.includes(type) ? new Proxy(listener, listenerHandler) : listener, useCapture, ]); } document.addEventListener = EventTarget.prototype.addEventListener = addEventListener; } // 清理使用 onXXX 添加到事件 static clearJsOnXXXEvent() { const emptyFunc = () => { }; function modifyPrototype(prototype, type) { Object.defineProperty(prototype, `on${type}`, { get() { return emptyFunc; }, set() { return true; }, }); } UnblockLimit.eventTypes.forEach(type => { modifyPrototype(HTMLElement.prototype, type); modifyPrototype(document, type); }); } // 清理或还原DOM节点的onXXX 属性 static clearDomOnXXXEvent() { function _innerClear() { UnblockLimit.eventTypes.forEach(type => { document .querySelectorAll(`[on${type}]`) .forEach(el => el.setAttribute(`on${type}`, 'return true')); }); } setInterval(_innerClear, 3000); } // 清理掉网页添加的全局防止复制/选择的 CSS static clearCSS() { GM_addStyle(`html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video, html body * { -webkit-user-select: text !important; -moz-user-select: text !important; user-select: text !important; } ::-moz-selection { color: #111 !important; background: #05d3f9 !important; } ::selection { color: #111 !important; background: #05d3f9 !important; } `); } } UnblockLimit.eventTypes = [ 'copy', 'cut', 'paste', 'select', 'selectstart', 'contextmenu', 'dragstart', ]; UnblockLimit.keyEventTypes = [ 'keydown', 'keypress', 'keyup', ]; //更新屏蔽列表 class BlockHost { static fetchHostList() { return new Promise((resolve, reject) => { GM_xmlhttpRequest({ method: 'GET', url: 'https://rxliuli.com/userjs/src/UnblockWebRestrictions/blockList.json', onload(res) { resolve(JSON.parse(res.responseText)); }, onerror(e) { reject(e); }, }); }); } static updateHostList(hostList) { hostList .filter(config => GM_getValue(JSON.stringify(config)) === undefined) .forEach(domain => { console.log('更新了屏蔽域名: ', domain); GM_setValue(JSON.stringify(domain), true); }); } static findKey() { return GM_listValues() .filter(config => GM_getValue(config) === true) .find(configStr => { const config = safeExec(() => JSON.parse(configStr), { type: 'domain', url: configStr, }); return this.match(new URL(location.href), config); }); } static match(href, config) { if (typeof config === 'string') { return href.host.includes(config); } else { const { type, url } = config; switch (type) { case 'domain': return href.host.includes(url); case 'link': return href.href === url; case 'linkPrefix': return href.href.startsWith(url); case 'regex': return new RegExp(url).test(href.href); } } } } // 更新支持的网站列表 BlockHost.updateBlockHostList = onceOfCycle(async () => { BlockHost.updateHostList(await BlockHost.fetchHostList()); }, 1000 * 60 * 60 * 24); //注册菜单 class MenuHandler { static register() { const findKey = BlockHost.findKey(); const key = findKey || JSON.stringify({ type: 'domain', url: location.host, }); console.log('key: ', key); GM_registerMenuCommand(findKey ? '恢复默认' : '解除限制', () => { GM_setValue(key, !GM_getValue(key)); console.log('isBlock: ', key, GM_getValue(key)); location.reload(); }); } } /** * 屏蔽列表配置 API,用以在指定 API 进行高级配置 */ class ConfigBlockApi { list() { return GM_listValues() .filter(key => key !== 'LastUpdate' && key !== 'LastValue') .map(config => ({ ...safeExec(() => JSON.parse(config), { type: 'domain', url: config, }), enable: GM_getValue(config), key: config, })); } switch(key) { GM_setValue(key, !GM_getValue(key)); } remove(key) { GM_deleteValue(key); } add(config) { GM_setValue(JSON.stringify(config), true); } clear() { GM_listValues().forEach(GM_deleteValue); } async update() { await BlockHost.updateBlockHostList(); } } //启动类 class Application { start() { MenuHandler.register(); if (BlockHost.findKey()) { UnblockLimit.watchEventListener(); UnblockLimit.proxyKeyEventListener(); UnblockLimit.clearJsOnXXXEvent(); } BlockHost.updateBlockHostList(); window.addEventListener('load', function () { if (BlockHost.findKey()) { UnblockLimit.clearDomOnXXXEvent(); UnblockLimit.clearCSS(); } }); if (location.href.includes('https://rxliuli.com/userjs/') || location.hostname === '127.0.0.1') { Reflect.set(unsafeWindow, 'com.rxliuli.UnblockWebRestrictions.configBlockApi', new ConfigBlockApi()); } } } new Application().start(); })();