您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Customizes various sites based on specified block values.
当前为
// ==UserScript== // @name List Filter // @namespace http://tampermonkey.net/ // @version 1.0 // @description Customizes various sites based on specified block values. // @author listfilterEric // @match *://news.google.com/* // @match *://www.youtube.com/* // @match *://www.reddit.com/r/* // @grant none // @require http://code.jquery.com/jquery-1.12.4.min.js // @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012 // @licence CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/ // @licence GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt // ==/UserScript== /*jshint esversion: 6 */ /* Last update: 6-05-2019 */ /* Search for these markers for locations where you need to add new selectors for new sites. markA (select the text block) markB (select the block you want to apply css to) markC (css of each class) */ (function() { 'use strict'; const lfShowFilterButton = 0; // set to 1 to show a button to manually run this script. const lfDynamicChecking = 1; // set to 1 to run the script automatically when new block elements are detected. const lfShowConsoleMsg = 0; // set to 1 to show console messages about how the filter checked each block. function consolelog(text) { if (lfShowConsoleMsg) { console.log(text); } } consolelog("list filter script start."); // ==== filter lists ==== //strong highlight var highlight1 = [ /apple/i, ]; //weak highlight var highlight2 = [ /gamestop/i, ]; //weak lowlight var lowlight1 = [ /goodbye/i, ]; //strong lowlight var lowlight2 = [ /\btv\b/i, ]; //delete block var delete1 = [ /throne|dany|\bgot\b/i, ]; var domainName = window.location.hostname; //href might be less limiting var hrefString = window.location.href; // ==== function definitions ==== // checks string against given list of regular expressions. function checkReg(string, regList) { for (var i = 0; i < regList.length; i++) { if (regList[i].test(string)) { return true; } } return false; } var elementCounter = 0; // check attributes of a block to choose what class to add to it. function checkBlock(index, element) { var titleText; // markA start if (/news\.google\.com/gi.test(domainName)) { titleText = jQuery(this).find("div>article>h3").eq(0).text().trim(); }else if (/www\.youtube\.com/gi.test(domainName)) { titleText = jQuery(this).find("span#video-title").text().trim(); }else if (/www\.reddit\.com/gi.test(domainName)) { titleText = jQuery(this).find("span>a>h2").text().trim(); } // markA end // class list identifies what was checked in past iterations var classList = ""; if ( jQuery(this).attr("class") ) { classList = jQuery(this).attr("class"); //consolelog(classList); } if ( titleText && (!classList || !/\blf-/.test(classList)) ) { //if ( titleText ) { elementCounter++; var matchCode = "n1"; // delete and lowlight lists are checked before highlight lists if (checkReg(titleText,delete1)) { matchCode = "d1"; jQuery(this).remove(); }else if (checkReg(titleText,lowlight2)) { matchCode = "l2"; jQuery(this).addClass("lf-lowlight2"); }else if (checkReg(titleText,lowlight1)) { matchCode = "l1"; jQuery(this).addClass("lf-lowlight1"); }else if (checkReg(titleText,highlight1)) { matchCode = "h1"; jQuery(this).addClass("lf-highlight1"); }else if (checkReg(titleText,highlight2)) { matchCode = "h2"; jQuery(this).addClass("lf-highlight2"); }else { jQuery(this).addClass("lf-checked"); } // prints to console the outcome of what the block matched. //if (1) { if (/d|l/gi.test(matchCode)) { var printMsg = elementCounter; printMsg += " "+ matchCode; printMsg += ": "+ titleText; consolelog(printMsg); } //console.log(elementCounter +" "+ matchCode +": "+ titleText +"("+ vidLength +")"); } } // end function checkBlock() // ==== adds reset button for highlight/lowlight and runs initial execution. ==== // markB start var blockSelector = "article"; if(/news\.google\.com/gi.test(domainName)) { blockSelector = "main>c-wiz>div>div"; checkBlocks(); }else if (/www\.youtube\.com/gi.test(domainName)) { blockSelector = "ytd-compact-video-renderer"; checkBlocks(); }else if (/www\.reddit\.com/gi.test(domainName)) { blockSelector = ".scrollerItem>div>div:nth-child(2)"; checkBlocks(); } // markB end function checkBlocks() { jQuery(blockSelector).each(checkBlock); consolelog("end checkBlocks()."); } jQuery("#lf-reset").click(function() { consolelog("highlight/lowlight reset began."); elementCounter = 0; checkBlocks(); consolelog("highlight/lowlight reset finished."); }); if (lfDynamicChecking) { waitForKeyElements( blockSelector, checkBlocks ); }else { checkBlocks(); } const listFilterCss = `<style> #lf-reset { display: block !important; background: #177e14; padding: 5px; border-radius: 5px; position: fixed; top: 5px; right: 5px; z-index: 999; color: white; font-weight: bold; cursor: pointer; } </style>`; if (lfShowFilterButton) { jQuery("body").prepend('<div id="lf-reset" hidden>H/L</div>'); jQuery(document.body).append(listFilterCss); } // markC start const googleFilterCss = `<style> main>c-wiz>div>div.lf-highlight1 { background: #baffc9;/*green*/ } main>c-wiz>div>div.lf-highlight2 { background: #ffffba;/*yellow*/ } main>c-wiz>div>div.lf-lowlight1 { background: #ffdfba;/*orange*/ opacity: .3; } main>c-wiz>div>div.lf-lowlight2 { background: #ffccca;/*red*/ opacity: .5; } </style>`; const youtubeFilterCss = `<style> ytd-compact-video-renderer.lf-highlight1 { background: #baffc9;/*green*/ } ytd-compact-video-renderer.lf-highlight2 { background: #ffffba;/*yellow*/ } ytd-compact-video-renderer.lf-lowlight1 { background: #ffdfba;/*orange*/ opacity: .3; } ytd-compact-video-renderer.lf-lowlight2 { background: #ffccca;/*red*/ opacity: .5; } </style>`; const redditFilterCss = `<style> .scrollerItem>div>div:nth-child(2).lf-highlight1 { background: #baffc9;/*green*/ } .scrollerItem>div>div:nth-child(2).lf-highlight2 { background: #ffffba;/*yellow*/ } .scrollerItem>div>div:nth-child(2).lf-lowlight1 { background: #ffdfba;/*orange*/ opacity: .3; } .scrollerItem>div>div:nth-child(2).lf-lowlight2 { background: #ffccca;/*red*/ opacity: .5; } </style>`; if(/news\.google\.com/gi.test(domainName)) { jQuery(document.body).append(googleFilterCss); }else if (/www\.youtube\.com/gi.test(domainName)) { jQuery(document.body).append(youtubeFilterCss); }else if (/www\.reddit\.com/gi.test(domainName)) { jQuery(document.body).append(redditFilterCss); } // markC end consolelog("list filter script finished."); })();