// ==UserScript== // @name Acfun过滤UP计划 // @namespace http://tampermonkey.net/ // @version 1.10 // @description 帮助你屏蔽不想看的UP主 // @author 人文情怀 // @match http://www.acfun.cn/a/ac* // @match http://www.acfun.cn/v/list63 // @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* // @require https://code.jquery.com/jquery-3.4.1.min.js // @grant GM_getValue // @grant GM_setValue // @grant GM.getValue // @grant GM.setValue // @run-at document-idle // @downloadURL none // ==/UserScript== function core() { 'use strict'; $.info = unsafeWindow.$.info; let empty = (a) => { if (typeof a == "undefined") { return () => { }; } else { return a; } ; }; let GM_set = typeof GM_setValue == "undefined" ? function (key, value, callback, failcallback) { //console.log("GM.setvalue") let p = GM.setValue(key, value); p.then(empty(callback), empty(failcallback)); } : function (key, value, callback) { let res = GM_setValue(key, value); callback(); }; let GM_get = typeof GM_getValue == "undefined" ? function (key, value, callback) { let p = GM.getValue(key, value); p.then((debug)=>{empty(callback)(debug); }, ()=>{callback(value);}); //console.log("empty", empty(callback)); } : function (key, value, callback, failcallback) { let res = GM_getValue(key, value); callback(res); } function cleanList() { GM_set("ACFUN_BLOCK_LIST", []); } let up = function (callback) { GM_get("ACFUN_BLOCK_LIST", [], callback); }; function addToList(id, callback) { //let old = up((old) => { if (old.indexOf(id) >= 0) { $.info.show("你已经屏蔽过UP主[" + id + "]啦!") return; } old.push(id); GM_set("ACFUN_BLOCK_LIST", old, () => { $.info.show("已将UP主[" + id + "]加入屏蔽列表") empty(callback)(); }); }); } function removeFromList(id, callback) { up((old) => { let i = old.indexOf(id); if (i >= 0) { old.splice(i, 1); } GM_set("ACFUN_BLOCK_LIST", old, () => { $.info.show("已将UP主[" + id + "]移出屏蔽列表。"); empty(callback)(); }); }); } let filterButton = document.createElement("div"); function initButton() { 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(0,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 < selections.length; i++) { let tag = selections[i]; let m = tag[mark]; //if (addMark) tag[mark] = mval; if (typeof mark !== "undefined" && m !== mval && !addMark) { //continue; } let info = $(tag).attr("data-info"); let json = JSON.parse(info); let username = json.userName; res.push({tag: $(tag).parent()[0], username: username, type: 1}); //$(tag) } //过滤右边排行榜视频 let sel = $("ul[data-con]"); //For each rank for (let i = 0; i < sel.length; i++) { let tag = sel[i]; let rows = $(tag).find("li"); //For each row for (let ri = 0; ri < rows.length; ri++) { let rowTag = rows[ri]; // let m = rowTag[mark]; //if (addMark) rowTag[mark] = mval; if (typeof mark !== "undefined" && m !== mval && !addMark) { //continue; } // let aTag = $(rowTag).find("[title]")[0]; let title = $(aTag).attr("title"); let matches = usernameByTitle(title) if (matches) { let username = matches[0].substring(3).trim(); //$(rowTag) res.push({tag: rowTag, username: username, type: 2}); } } } //-------------------- sel = $("div[data-con]"); for (let i = 0; i < sel.length; i++) { let tag = sel[i]; let rows = $(tag).find("li"); //For each row for (let ri = 0; ri < rows.length; ri++) { let rowTag = rows[ri]; // let m = rowTag[mark]; //if (addMark) rowTag[mark] = mval; if (typeof mark !== "undefined" && m !== mval && !addMark) { //continue; } // let aTag = $(rowTag).find("[title]")[0]; let title = $(aTag).attr("title"); if (title) { let matches = usernameByTitle(title) if (matches) { let username = matches[0].substring(3).trim(); res.push({tag: rowTag, username: username, type: 3}); } } } } //香蕉搒 var allBananas = $("figure.fl.block-box.block-video.weblog-item").find("> figcaption > em > a"); for (let i = 0; i < allBananas.length; i++) { let sel = allBananas[i]; let upname = $(sel).attr("title"); let tag = $(sel).parent().parent().parent()[0]; //console.log(tag); res.push({tag: tag, username: upname, type: 1}); } return res; } function getListSelection(mark, mval, addMark) { if (typeof addMark == "undefined") { addMark = false; } let res = []; let sel = $("div.weblog-item"); //console.log("sel weblog") for (let i = 0; i < sel.length; i++) { let row = sel[i]; // let m = row[mark]; if (addMark) row[mark] = mval; //console.log(mark, mval, m); if (typeof mark !== "undefined" && m !== mval && !addMark) { //console.log("continue"); continue; } // let aTag = $(row).find(".atc-up")[0]; let username = $(aTag).attr("title"); res.push({tag: row, username: username, type: 4}); } return res; } let d3=unsafeWindow.d3; function displayList() { up((data)=>{ $("#blockpanel").empty(); for (let i=0;i"+data[i]+"") let str = data[i]; b.on("click", function(){ removeFromList(str, ()=>{ displayList(); }); }); $("#blockpanel").append(b); } }); } let show = false; let dragging =false; function addPanel() { let dx=0; let dy=0; let sx=0; let sy=0; let ox=0; let oy=0; let ppanel = $("
"); let dragbutton = $("
|||||
") let pbutton = $(""); let p = $(""); GM_get("ACFUN_BLOCK_POS", "{ox:0, oy:0}", (d)=>{ console.log("d=",d); ox=parseInt(d.ox); oy=parseInt(d.oy); ox = isNaN(ox) ? 0 : ox; oy = isNaN(oy) ? 300 : oy; console.log(ox,oy); p.css("transform","translate("+(ox)*0+"px,"+(oy)+"px)"); $(ppanel).css("transform","translate("+(ox)*0+"px,"+(oy)+"px)"); }); $(document.body).append(ppanel); ppanel.append(dragbutton); ppanel.append(pbutton); $(document.body).append(p); pbutton.on("click", function () { show = !show; p.css("display", show ? "block" : "none"); if (show) { displayList(); } }) dragbutton.on("mousedown", (event )=>{ sx=event.pageX; sy=event.pageY; console.log("s",sx,sy); dragging=true; }); $(document).on("mouseup", ()=>{ if (dragging){ ox=dx+ox; oy=dy+oy; let maxHeight = $(window.top).height()-123; let maxWidth = $(window.top).width()-23; ox = ox>maxWidth?maxWidth:ox; ox = ox<0?0:ox; oy= oy<0?0:oy; oy = oy>maxHeight? maxHeight: oy; p.css("transform","translate("+(ox)*0+"px,"+(oy)+"px)"); $(ppanel).css("transform","translate("+(ox)*0+"px,"+(oy)+"px)"); GM_set("ACFUN_BLOCK_POS", {ox:ox,oy:oy}, (d)=>{ console.log("DEBUG", "POSITION SET", ox, oy); }); } dragging=false; }); $(document).on("mousemove",(event)=>{ if (dragging){ dx=event.pageX-sx; dy=event.pageY-sy; $(ppanel).css("transform","translate("+(dx+ox)*0+"px,"+(dy+oy)+"px)") } }) } function addButton(pageType) { //console.log("page type", pageType); let attach = function (list) { //console.log("list",list) for (let i = 0; i < list.length; i++) { let tag = list[i].tag; $(tag).mousemove(function () { //$(tag).parent().css("overflow-x", "visible") //$(tag).parent().parent().css("overflow-x", "visible") //$(tag).parent().parent().parent().css("overflow-x", "visible") //$(tag).parent().parent().parent().parent().css("overflow-x", "visible") //console.log(tag); if (window.currentTag == tag) return; let rect = tag.getBoundingClientRect(); let brect = filterButton.getBoundingClientRect(); let button = $(filterButton).detach(); //.css("left", (rect.right-brect.width)+"px") //.css("top", rect.top+"px") //.show(); $(tag) .css("white-space", "nowrap") .css("overflow", "visible") .css("position", "relative") .append(button) window.currentTag = tag; window.currentUser = list[i].username; $(filterButton).off("click"); if (pageType !== "home") { $(filterButton) .css("right", "0") .css("top", "0") .css("transform", "translate(0,0)") //.css("z-index", "99999") } $(filterButton) .on("click", function () { console.log("current", window.currentTag, window.currentUser); if (typeof window.currentTag !== "undefined" && window.currentTag !== null) { addToList(window.currentUser, ()=>{displayList();}); } }) .show(); }) $(tag).mouseleave(function () { let rect = tag.getBoundingClientRect(); $(filterButton).detach(); window.currentTag = null; window.currentUser = null; $(filterButton).off("click").hide() }) } } if (pageType == "home") { let list = getHomeSelection("ATTACHED", true, true); attach(list); } else { let list = getListSelection("ATTACHED", true, true); attach(list); } } let pannelAdded = false; function addUI(pageType) { addButton(pageType); if (!pannelAdded) { addPanel(); pannelAdded = true; } } // console.log("match type", window.location.href) function usernameByTitle(title) { let regex = /UP:(.+)[\s\v\n]/g return title.match(regex); } function hideTag(tag){ if ($(tag).css("visibility")!=="hidden"){ $(tag).css("visibility", "hidden"); let d=$(tag).css("display"); tag["_d"]=d; $(tag).css("display", "none"); let bar = $(tag).next(); if ($(bar).prop("tagName").toUpperCase()=="HR"){ $(bar).css("display", "none"); } } } function showTag(tag){ if ($(tag).css("visibility")!=="visible"){ $(tag).css("visibility", "visible"); if (typeof tag["_d"]!=="undefined"){ $(tag).css("display", tag["_d"]); }else{ $(tag).css("display", "none"); } let bar = $(tag).next(); if ($(bar).prop("tagName").toUpperCase()=="HR"){ $(bar).css("display", "block"); } } } function FilterVideos() { up((upList) => { //过滤主页视频 let selections = getHomeSelection("FILTER", false, false); for (let i = 0; i < selections.length; i++) { let tag = selections[i].tag; ; let username = selections[i].username; if (upList.indexOf(username) >= 0) { //console.log("hiding", tag); hideTag(tag); } else { showTag(tag); } } //过滤右边排行榜视频 let sel = $("ul[data-con]"); //For each rank for (let i = 0; i < sel.length; i++) { let tag = sel[i]; let rows = $(tag).find("li"); //For each row for (let ri = 0; ri < rows.length; ri++) { let rowTag = rows[ri]; let aTag = $(rowTag).find("[title]")[0]; let title = $(aTag).attr("title"); let matches = usernameByTitle(title) if (matches) { let username = matches[0].substring(3).trim(); if (upList.indexOf(username) >= 0) { //找到了,隐藏本条 hideTag(rowTag); } else { showTag(rowTag); } } } } }); } //过滤主页文章区 function FilterArticles() { up((upList) => { let sel = $("div[data-con]"); for (let i = 0; i < sel.length; i++) { let tag = sel[i]; let rows = $(tag).find("li"); //For each row for (let ri = 0; ri < rows.length; ri++) { let rowTag = rows[ri]; let aTag = $(rowTag).find("[title]")[0]; let title = $(aTag).attr("title"); if (title) { let matches = usernameByTitle(title); if (matches) { let username = matches[0].substring(3).trim(); if (upList.indexOf(username) >= 0) { //找到了,隐藏本条 // console.log("过滤文脏区 rank=", i, "row=",ri,"username=",username); hideTag(rowTag); } else { showTag(rowTag); } } } } } }); } //过滤文章列表页 function FilterListPage() { up(((upList) => { let sel = $("div.weblog-item"); //console.log("uplist = ", upList, sel); for (let i = 0; i < sel.length; i++) { let row = sel[i]; //if (typeof row.visited=="undefined"){ row.visited = true; }else{continue;} let aTag = $(row).find(".atc-up")[0]; let username = $(aTag).attr("title"); //console.log("username",username, window.currentUser); if (upList.indexOf(username) >= 0) { //console.log("过滤文脏区",username); //屏蔽 hideTag(row); } else { showTag(row); } } })) } 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() { if (typeof $ == "undefined") { console.log("Loading..", typeof unsafeWindow.$); $=unsafeWindow.$; setTimeout(initLoad, 1000); return; } initButton(); function isArtileListPage(){ let t = ["list63","list110","list73","list164","list184","list74","list75"]; let url = window.location.href; for (let i=0;i=0) return true; } return false; } 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) { //可能是文章列表 if (isArtileListPage()){ console.log("DEBUG handle list page"); HandleListPage(); }else{ HandleHomePage(); } } 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(); } } initLoad(); }; core();