Greasy Fork

Greasy Fork is available in English.

Acfun过滤UP计划

帮助你屏蔽不想看的UP主

当前为 2019-05-24 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Acfun过滤UP计划
// @namespace    http://tampermonkey.net/
// @version      0.40
// @description  帮助你屏蔽不想看的UP主
// @author       人文情怀
// @match        http://www.acfun.cn/a/ac*
// @match        http://www.acfun.cn
// @match        http://www.acfun.cn/v/list*
// @match        https://www.acfun.cn/a/ac*
// @match        https://www.acfun.cn
// @match        https://www.acfun.cn/v/list*
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==



(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();
        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<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});

                    }
                }
            }
        }
        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;
    }


    function displayList(){
        let data = up();
        d3.select("#blockpanel")
            .selectAll("div.blockname")
            .data(up)
            .exit()
            .remove();

        let entersel=        d3.select("#blockpanel")
        .style("font-size","11px")
        .selectAll("div.blockname")
        .data(up)
        .enter()
        let nameblock = entersel.append("div")
        .attr("class","blockname")
        .style("display","inline-block")
        .style("margin", "2px")
        .style("height","18px")
        .style("background-color","white");
        nameblock.append("span")
            .text(function(d){return d})
        nameblock.append("button")
            .text("×")
            .style("width","18px")
            .style("height","18px")
            .style("line-height","18px")
            .style("padding","2px")
            .style("background-color","rgb(255,120,120)")
            .style("border-width","0px")
            .on("click", function(d){
            console.log("remove",d);
            removeFromList(d);
            displayList();
        })
    }
    let show = false;
    function addPanel(){
        let pbutton =$("<button id='blockbutton' style=';z-index:999;position:fixed;height: 100px; width: 23px; padding: 3px; background-color:rgba(255,50,50,0.3); left: 0; top: 300px;text-orientation:upright; border-width:0;'>屏蔽列表</button>");
        let p = $("<div id='blockpanel' style='overflow-y:scroll;display:none; padding: 3px;z-index:998;position:fixed; background-color: rgba(0,120,255,0.3);left:23px; top: 300px;; height: 200px; width: 200px;'></div>");
        $(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<list.length;i++){

                let tag = list[i].tag;
                $(tag).mousemove(function(){
                    //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(100%,0)")
                    }

                    $(filterButton)
                        .on("click",
                            function(){
                        console.log("current", window.currentTag, window.currentUser);
                        if (typeof window.currentTag!=="undefined" && window.currentTag!==null){
                            addToList(window.currentUser);
                            console.log("a=",a);
                            a++;
                            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 FilterVideos(){
        let upList=up();

        //过滤主页视频
        let selections = $("a[data-info]");
        for (let i=0;i<selections.length;i++){
            let tag=selections[i];
            let info=$(tag).attr("data-info");
            let json=JSON.parse(info);
            let username=json.userName;
            if (upList.indexOf(username)>=0){
                $(tag).parent().css("visibility","hidden");
            }else{
                $(tag).parent().css("visibility","visible");
            }
        }
        //过滤右边排行榜视频
        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){
                        //找到了,隐藏本条
                        $(rowTag).css("visibility","hidden");
                    }else{
                        $(rowTag).css("visibility","visible");
                    }
                }
            }
        }
    }

    //过滤主页文章区
    function FilterArticles(){
        let upList=up();
        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);
                            $(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<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);
                //屏蔽
                $(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);
    }
    $(document).ready(function(){
        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){
            HandleListPage();
        }

    })

})();