// ==UserScript== // @name Acfun过滤UP计划 // @namespace http://tampermonkey.net/ // @version 0.542 // @description 帮助你屏蔽不想看的UP主 // @author 人文情怀 // @match http://www.acfun.cn/a/ac* // @match http://www.acfun.cn/v/list* // @match https://www.acfun.cn/a/ac* // @match http://www.acfun.cn/* // @match https://www.acfun.cn/* // @match https://www.acfun.cn/v/list* // @match http://www.acfun.cn/a/ac* // @match https://www.acfun.cn/a/ac* // @match http://www.acfun.cn/v/ac* // @match https://www.acfun.cn/v/ac* // @grant GM_getValue // @grant GM_setValue // @reference https://greasyfork.org/en/scripts/377561-block-acfun-up // @downloadURL none // ==/UserScript== // 在0.40版本中受到 https://greasyfork.org/en/scripts/377561-block-acfun-up 的启发添加的借用代码。可以更准确的等待页面载入。 // https://gist.github.com/raw/2625891/waitForKeyElements.js not suppored by Greasy Fork, copied here /*--- waitForKeyElements(): A utility function, for Greasemonkey scripts, that detects and handles AJAXed content. Usage example: waitForKeyElements ( "div.comments" , commentCallbackFunction ); //--- Page-specific function to do what we want when the node is found. function commentCallbackFunction (jNode) { jNode.text ("This comment changed by waitForKeyElements()."); } IMPORTANT: This function requires your script to have loaded jQuery. */ function waitForKeyElements ( selectorTxt, /* Required: The jQuery selector string that specifies the desired element(s). */ actionFunction, /* Required: The code to run when elements are found. It is passed a jNode to the matched element. */ bWaitOnce, /* Optional: If false, will continue to scan for new elements even after the first match is found. */ iframeSelector /* Optional: If set, identifies the iframe to search. */ ) { var targetNodes, btargetsFound; if (typeof iframeSelector == "undefined") targetNodes = $(selectorTxt); else targetNodes = $(iframeSelector).contents () .find (selectorTxt); if (targetNodes && targetNodes.length > 0) { btargetsFound = true; /*--- Found target node(s). Go through each and act if they are new. */ targetNodes.each ( function () { var jThis = $(this); var alreadyFound = jThis.data ('alreadyFound') || false; if (!alreadyFound) { //--- Call the payload function. var cancelFound = actionFunction (jThis); if (cancelFound) btargetsFound = false; else jThis.data ('alreadyFound', true); } } ); } else { btargetsFound = false; } //--- Get the timer-control variable for this selector. var controlObj = waitForKeyElements.controlObj || {}; var controlKey = selectorTxt.replace (/[^\w]/g, "_"); var timeControl = controlObj [controlKey]; //--- Now set or clear the timer as appropriate. if (btargetsFound && bWaitOnce && timeControl) { //--- The only condition where we need to clear the timer. clearInterval (timeControl); delete controlObj [controlKey] } else { //--- Set a timer, if needed. if ( ! timeControl) { timeControl = setInterval ( function () { waitForKeyElements ( selectorTxt, actionFunction, bWaitOnce, iframeSelector ); }, 300 ); controlObj [controlKey] = timeControl; } } waitForKeyElements.controlObj = controlObj; } (function() { 'use strict'; function cleanList(){ GM_setValue("ACFUN_BLOCK_LIST", []); } function helper() { var head= document.getElementsByTagName('head')[0]; var script= document.createElement('script'); script.type= 'text/javascript'; script.src= 'https://d3js.org/d3.v3.min.js'; head.appendChild(script); }; helper(); let up=function(){ return GM_getValue("ACFUN_BLOCK_LIST",[]); }; function addToList(id){ let old = up(); if (old.indexOf(id)>=0){ $.info.show("你已经屏蔽过UP主["+id+"]啦!") return; } old.push(id); GM_setValue("ACFUN_BLOCK_LIST", old); $.info.show("已将UP主["+id+"]加入屏蔽列表") console.trace("a"); } function removeFromList(id){ let old = up(); let i =old.indexOf(id); if (i>=0){ old.splice(i,1); } GM_setValue("ACFUN_BLOCK_LIST", old); $.info.show("已将UP主["+id+"]移出屏蔽列表。"); } let filterButton = document.createElement("div"); document.body.appendChild(filterButton); $(filterButton) .css("width","15px") .css("height","15px") .css("background-color","rgba(255,0,0,1)") .css("font-familty","'黑体',serif") .css("font-weight","600") .css("font-size","11px") .css("padding","1.5px") .css("left","0") .css("top","0") .css("transform","translate(-100%,0)") .css("display","block") .css("position","absolute") .css("z-index","99999") .css("background-size","contain") .css("background-image","url('https://cdn.aixifan.com/dotnet/20130418/umeditor/dialogs/emotion/images/ac/12.gif')") //获得所有主页的UP的DOM TAG function getHomeSelection(mark, mval, addMark){ if (typeof addMark=="undefined"){ addMark=false; } let res=[]; //过滤主页视频 let selections = $("a[data-info]"); for (let i=0;i figcaption > em > a"); for (let i = 0;i屏蔽列表"); let p = $(""); $(document.body).append(pbutton); $(document.body).append(p); pbutton.on("click", function(){ show=!show; p.css("display", show ? "block" :"none"); if (show){ displayList(); } }) } let a = 0; function addButton(pageType){ //console.log("page type", pageType); let attach= function(list){ //console.log("list",list) for (let i=0;i=0){ $(tag).css("visibility","hidden"); }else{ $(tag).css("visibility","visible"); } } //过滤右边排行榜视频 let sel=$("ul[data-con]"); //For each rank for (let i=0;i=0){ //找到了,隐藏本条 $(rowTag).css("visibility","hidden"); }else{ $(rowTag).css("visibility","visible"); } } } } } //过滤主页文章区 function FilterArticles(){ let upList=up(); let sel=$("div[data-con]"); for (let i=0;i=0){ //找到了,隐藏本条 // console.log("过滤文脏区 rank=", i, "row=",ri,"username=",username); $(rowTag).css("visibility","hidden"); }else{ $(rowTag).css("visibility","visible"); } } } } } } //过滤文章列表页 function FilterListPage(){ let upList=up(); let sel=$("div.weblog-item"); //console.log("uplist = ", upList, sel); for (let i = 0;i=0){ //console.log("过滤文脏区",username); //屏蔽 $(row).css("display","none"); //$(row).removeClass("wblog-item"); //或者删除 //$(row).remove(); }else{ $(row).css("display","block"); } } } function HandleHomePage(){ //屏蔽首页UP,包括视频和右边的文章区 FilterVideos(); FilterArticles(); addUI("home"); setTimeout(HandleHomePage, 800); } function HandleListPage(){ //屏蔽文章页, FilterListPage(); addUI("list"); setTimeout(HandleListPage, 500); } function HandleArticlePage(){ //对于单独的文章页或者视频,添加一个按钮屏蔽当前UP主 console.log(window.location.href.indexOf("www.acfun.cn/a/ac"), window.location.href.indexOf("www.acfun.cn/v/ac")) let button = $("
屏蔽UP
") console.log("DEBUG Attach Button S.") $(document.body).append(button); console.log("DEBUG Attach Button S Done.") button.on("click", function(){ let upname=""; if (window.location.href.indexOf("www.acfun.cn/v/ac")>=0){ upname = $("a.name-wrap").html(); console.log("upname", upname); }else if (window.location.href.indexOf("www.acfun.cn/a/ac")>=0){ upname = $("a.upname").html(); console.log("upname", upname); } addToList(upname); }) } function initLoad(){ console.log("DEBUG body Loaded"); if (window.location.href=="http://www.acfun.cn/" || window.location.href=="https://www.acfun.cn/"){ HandleHomePage(); } if (window.location.href.indexOf("www.acfun.cn/v/list")>=0){ console.log("DEBUG handle list page"); HandleListPage(); } if (window.location.href.indexOf("www.acfun.cn/v/ac")>=0 || window.location.href.indexOf("www.acfun.cn/a/ac")>=0){ console.log("DEBUG handle single Page"); HandleArticlePage(); } } waitForKeyElements ("body", initLoad); })();