您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
BDWM_PLUS by motaguoke
当前为
- // ==UserScript==
- // @name BDWM PLUS
- // @version 1.0
- // @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://greasyfork.org/users/284856
- // ==/UserScript==
- //设置
- var GLOBAL_VERSION = "1.0"
- //全局变量
- 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()
- })
- 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 {
- //不存在关注按钮,需要首先获取mail中的user-name,再新建一个widebtn类插入
- //得到username
- str_username = obj_functions[i].getElementsByClassName("mail")[0].getAttribute("data-username")
- 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){
- console.log("开始渲染只看作者状态")
- //只看作者状态
- obj_postcard = document.getElementsByClassName("post-card")
- for (i = 0;i < obj_postcard.length; i++){
- obj_mail = obj_postcard[i].getElementsByClassName("mail")[0] //关注后“关注”按钮将被隐藏
- str_username = obj_mail.getAttribute("data-username")
- if (str_username!=GLOBAL_SEEME_AUTHOR){
- obj_postcard[i].style.display = "none"
- }else{
- obj_postcard[i].style.display = "block"
- }
- }
- }else{
- //非只看作者状态
- console.log("开始渲染查看全部状态")
- obj_postcard = document.getElementsByClassName("post-card")
- for (i = 0;i< obj_postcard.length; i++){
- obj_postcard[i].style.display = "block"
- }
- }
- console.log("渲染完毕")
- }