BDWM PLUS

BDWM_PLUS by motaguoke

目前为 2019-04-02 提交的版本。查看 最新版本

// ==UserScript==
// @name     BDWM PLUS
// @version  1.1
// @description BDWM_PLUS by motaguoke
// @include  http://bbs.pku.edu.cn/*
// @include  https://bbs.pku.edu.cn/*
// @include  https://*.bdwm.net/*
// @include  http://*.bdwm.net/*
// @namespace https://gf.qytechs.cn/users/284856
// ==/UserScript==
//设置
var GLOBAL_VERSION = "1.1"
//全局变量
var GLOBAL_SEEME_STATUS = false //当前只看某一作者状态
var GLOBAL_SEEME_AUTHOR = "" //当前只看某一作者的作者ID

console.log(`BDWM_PLUS by motaguoke Version: ${GLOBAL_VERSION}`)
window.onload = BDWM_ADDON_MAIN()


async function BDWM_ADDON_MAIN(){
    //初始化插件
    var observe = new MutationObserver(function (mutations){
        //初始化渲染插件
        BDWM_ADDON_SEEME_RENDER() //只看作者插件
        BDWM_ADDON_SETTINGINFO() //插件信息插件
    })
    observe.observe(document.documentElement,{childList:true,subtree:true})
    
}


document.addEventListener('click',async function(event){
    //点击事件钩子
    //console.log(event.target.className+" "+event.target.id)

    if (event.target.className == "only-seeme"){ // BDWM_ADDON_SEEME插件,只看某一作者
        if (event.target.innerText == "只看TA"){
            //进入只看作者状态
            event.target.innerText = "取消只看TA"
            GLOBAL_SEEME_AUTHOR = event.target.id
            GLOBAL_SEEME_STATUS = true

            obj_onlyseeme = document.getElementsByClassName("only-seeme")
            for (i=0;i<obj_onlyseeme.length;i++){
                obj_onlyseeme[i].innerText = "取消只看TA"
            }

        } else {
            //退出只看作者状态
            event.target.innerText = "只看TA"
            GLOBAL_SEEME_AUTHOR = ""
            GLOBAL_SEEME_STATUS = false

            obj_onlyseeme = document.getElementsByClassName("only-seeme")
            for (i=0;i<obj_onlyseeme.length;i++){
                obj_onlyseeme[i].innerText = "只看TA"
            }
        }
        BDWM_ADDON_SEEME_RENDER() //点击后立刻重新渲染
    }else{

    }

},true);



async function BDWM_ADDON_SEEME_RENDER(){

    if (window.location.href.indexOf("post-read.php")<0){
        //当切换到非读贴内容时,立刻重新刷新状态,避免上次查看主楼的延续
        GLOBAL_SEEME_AUTHOR = ""
        GLOBAL_SEEME_STATUS = false
    }

    obj_found = document.getElementsByClassName("only-seeme")
    if (obj_found.length==0){ //本页面第一次加载时,给每个帖子加按钮
        obj_functions = document.getElementsByClassName("functions")

        for (i = 0;i < obj_functions.length; i++){
            obj_widebtn = obj_functions[i].getElementsByClassName("line wide-btn")[0]
            obj_newobj = document.createElement("a")
            obj_newobj.className = "only-seeme"
            if (GLOBAL_SEEME_STATUS == false){
            obj_newobj.innerText = "只看TA"} else
            {obj_newobj.innerText = "取消只看TA"}

            if (obj_widebtn){
                //存在关注按钮,在关注按钮旁边添加即可
                str_username = obj_widebtn.getElementsByClassName("add-friend")[0].getAttribute("data-username")
                obj_newobj.id = str_username
                obj_widebtn.appendChild(obj_newobj)
            } else {
                //不存在关注按钮,需要首先获取的user-name,再新建一个widebtn类插入
                //得到username
                str_username = obj_functions[i].parentNode.getElementsByClassName("username")[0].getElementsByTagName("a")[0].innerText
                obj_newobj.id = str_username
                //插入widebtn
                obj_widebtn = document.createElement("div")
                obj_widebtn.className = "line wide-btn"
                obj_functions[i].appendChild(obj_widebtn)
                //重新获得插入的widebtn DOM
                obj_functions[i].lastChild.appendChild(obj_newobj)

            }


        }
    }

    if (GLOBAL_SEEME_STATUS==true){
        //只看作者状态
        obj_postcard = document.getElementsByClassName("post-card")
        for (i = 0;i < obj_postcard.length; i++){
            str_username = obj_postcard[i].getElementsByClassName("username")[0].getElementsByTagName("a")[0].innerText //关注后“关注”按钮将被隐藏
            if (str_username!=GLOBAL_SEEME_AUTHOR){
                obj_postcard[i].style.display = "none"
            }else{
                obj_postcard[i].style.display = "block"
            }
        }

    }else{
        //非只看作者状态
        obj_postcard = document.getElementsByClassName("post-card")
        for (i = 0;i< obj_postcard.length; i++){
            obj_postcard[i].style.display = "block"
        }
    }

}

async function BDWM_ADDON_SETTINGINFO(){
    //增加插件信息
    obj_footer = document.getElementById("footer")
    if (document.getElementById("footer").innerHTML.indexOf("BDWM_PLUS")<0) {

    obj_newobj = document.createElement("p")
    obj_newobj.style.color = "blue"
    obj_newobj.innerText = `BDWM_PLUS 版本 ${GLOBAL_VERSION} 作者 motaguoke`
    
    obj_footer.appendChild(obj_newobj)
    }
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址