Skip to content

Instantly share code, notes, and snippets.

@TomoeMami
Created January 27, 2022 11:12
Show Gist options
  • Save TomoeMami/9b127b61e7896363c7da81237a3ef8a3 to your computer and use it in GitHub Desktop.
Save TomoeMami/9b127b61e7896363c7da81237a3ef8a3 to your computer and use it in GitHub Desktop.
S1用户标记脚本
// ==UserScript==
// @name S1 User Marker
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Mark certain user
// @ogirin_author 冰箱研会长、masakahaha
// @author Nanachi
// @match https://bbs.saraba1st.com/2b/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_listValues
// ==/UserScript==
function getElementByXpath(path) {
return document.evaluate(path, document, null,
XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function Blockbutton_Appender(HtmlDiv, Block_Target, Origin_Name,PostNumber) {
var Block_status = '';
var status_text = GM_getValue(Origin_Name,null) ? '取消标记' : '标记此人';
if (GM_getValue(Origin_Name,null)) {
Block_Target.style='color:red';
Block_Target.innerText = Block_Target.innerText + '#' + GM_getValue(Origin_Name);
}
function buttonClick(){
console.log('test');
console.log(Origin_Name);
if (GM_getValue(Origin_Name,null)) {
console.log('1');
GM_deleteValue(Origin_Name);
window.location.reload();
} else {
console.log('2');
var tag = prompt("输入自定义标签","");
if (tag != undefined && tag != "") {
console.log(Origin_Name);
// blockedList.set(Block_Target, tag);
GM_setValue(Origin_Name, tag);
window.location.reload();
}
}
}
var StrPostNumber = PostNumber.toString();
HtmlDiv.innerHTML = HtmlDiv.innerHTML.concat(`
<table class="tfm" cellspacing="0" cellpadding="0">
<tbody><tr>
<td>
<button type="button" name="blacklistsubmit_btn" id="blockbtn`,StrPostNumber,`" value="true" class="pn vm" ><em>`,status_text,`</em></button>
</td>
</tr>
</tbody></table>`);
var button1 = document.getElementById("blockbtn"+PostNumber.toString());
console.log(button1);
// 在js页面获取HTML的按钮函数
button1.onclick = buttonClick;
}
function S1_Reply_Blocker() {
var PostLists = getElementByXpath(`//div[@id='postlist']`);
// console.log(PostLists)
if (PostLists) {
var PostCounter = 1;
while (getElementByXpath(`//div[@id='postlist']/div[${PostCounter}]`)) {
var PostAuthor = getElementByXpath(`//div[@id='postlist']/div[${PostCounter}]/table/tbody/tr[1]/td[1]/div/div[1]/div/a`);
if(PostAuthor){
if(PostAuthor.innerText){
var origin_author = PostAuthor.innerText;
}
var PostAruthorColumn = getElementByXpath(`//div[@id='postlist']/div[${PostCounter}]/table[1]/tbody[1]/tr[1]/td[1]/div[1]`);
if (PostAruthorColumn) {
Blockbutton_Appender(PostAruthorColumn, PostAuthor,origin_author,PostCounter);
}}
PostCounter = PostCounter + 1;
}
}
}
S1_Reply_Blocker();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment