订阅帖子(前台)
// ==UserScript==
// @name 订阅帖子(前台)
// @storageName Su.订阅帖子
// @version 0.1.0
// @description 在楼主的帖子里添加订阅按钮
// @author Su.
// @match https://bbs.tampermonkey.net.cn/*
// @grant unsafeWindow
// @grant GM_notification
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// ==/UserScript==
let tid
if(location.href.indexOf('forum.php?mod=viewthread&tid=')!==-1){tid=document.querySelector("#k_collect").href.split('tid=')[1];dingyue()}
else if(location.href.indexOf('thread-')!==-1){tid=location.href.split('-')[1];dingyue()}
function dingyue(){
document.querySelector("#p_btn > a.sharep > i > img").src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAASlJREFUOE+lkkFOwkAUhv+/GNdT5QAcQEyPoIt2a29gvUFXyE6WsCs3qDdgTUxaT2AjHsADQJm1xj4zhSZgig3lrWbezPvm/f884sTgsfUyVw49nVV1LQB2BvCNXv5gICWgP1wGENzvdUM8L8bdeDcniVL4wR3EiiGY0svDEnA9WH0KJBSro6uCj7GdVmtJVA/f1hOIACKvIBwIZ/TyYAN4XMn75LJWjtEMMgE4pZuPtvsUZ9Ljrdb/AraXZxDxK+M2OSi6uuywAWAMk4ie3vPCFF4N1zdG5kGAvCgfBUf01k7dV1eyDwPmFzFYZHR11A5gOuggNUa1AjRNaKOEowD9wTItxxOobfcvTIgeIPZi0vVLE51wrYrzImx6dffc+rKiLLI3g3RK/ALqQp4RGbtohAAAAABJRU5ErkJggg=='
let newa=document.createElement('a')
let 是否订阅=GM_getValue(tid)
document.querySelector("#p_btn").appendChild(newa)
if(是否订阅==null){
newa.outerHTML="<a href=\"javascript:void(0)\" id=\"k_attention\" title=\"订阅该贴\"><i><img src=\"https://bbs.tampermonkey.net.cn/template/comiis_mi/img/oshr.png\">订阅</img></i></a>"
document.querySelector('a[id="k_attention"]').addEventListener('click',mid(1))
}
else {
GM_setValue("已订阅"+tid,'回复数'+document.querySelector('#postlist > div.bm_h.comiis_snvbt > span.y.comiis_hfs').innerText.split('\n')[0])
newa.outerHTML="<a href=\"javascript:void(0)\" id=\"k_attentioned\" title=\"取消订阅\"><i><img src=\"https://bbs.tampermonkey.net.cn/template/comiis_mi/img/oshr.png\">取消订阅</img></i></a>"
document.querySelector('a[id="k_attentioned"]').addEventListener('click',mid(2))
}
}
function mid(d){
return ()=>{
if(d==1){GMs(d)}
else {GMs(d)}
}
}
function GMs(d){
let tit,tex
if(d==1){
tit='已订阅',tex='后台会监测该贴回复数';
GM_setValue("已订阅"+tid,'回复数'+document.querySelector('#postlist > div.bm_h.comiis_snvbt > span.y.comiis_hfs').innerText.split('\n')[0])
GM_setValue(tid,location.href)
}
else {
tit='已取消订阅',tex='不再监测该贴回复数';
if(GM_getValue(tid)){
GM_deleteValue("已订阅"+tid);
GM_deleteValue(tid)
}
}
GM_notification({
title:tit,
text:tex,
timeout:4000,
});
location.reload()
}