Greasy Fork

Greasy Fork is available in English.

远景小助手

远景论坛自定义小功能~:自定义常用语,屏蔽指定用户的发言,隐藏等级|徽章|表情显示等。

目前为 2024-10-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         远景小助手
// @namespace    http://tampermonkey.net/
// @version      5.0.0.2
// @description  远景论坛自定义小功能~:自定义常用语,屏蔽指定用户的发言,隐藏等级|徽章|表情显示等。
// @author       lalaki
// @match        https://*.pcbeta.com/*
// @icon         https://bbs.pcbeta.com/favicon.ico
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT
// ==/UserScript==
(function () {
	"use strict";
	const FINAL_VERSION = 5.2;
	//UI
	let gui = document.createElement("div");
	gui.innerHTML = `
    <div style="font-size:144%" draggable="false">
        <div style="background:#ff5245;padding:4px 12px 4px 12px;border-top-right-radius:10px">
        <img src="/favicon.ico" style="pointer-events:none;width:24px;position:absolute"><h1 style="margin:0 0 0 28px;color:#fff;">远景小助手</b>
        <div style="float:right;color:red;font-size:24px;line-height:20px;cursor:pointer;transform: translateX(10px);" id="tool_gui_close">❎</div>
        </div>
        <div style="display:flex;padding:2px 8px 5px 8px;background:#f3f3f3">
        <ul>
        <li><input id="hide_exp" type="checkbox"><label for="hide_exp">不显示默认表情</label></li>
        <li><input id="hide_star" type="checkbox"><label for="hide_star">不显示用户等级</label></li>
        <li><input id="hide_ava" type="checkbox"><label for="hide_ava">不展示用户徽章</label></li>
        <li><input id="hide_user_sign" type="checkbox"><label for="hide_user_sign">不展示用户签名</label></li>
        <li><input id="hide_ip_address" type="checkbox"><label for="hide_ip_address">不展示IP属地</label></li>
        <li><input id="hide_details" type="checkbox"><label for="hide_details">不展示用户详细信息(仅显示头像与名字)</label></li>
        <li><input id="show_all_ava" type="checkbox"><label for="show_all_ava">为自己佩戴全部徽章</label></li>
        <li><div>常用语(每行一句话):</div><textarea id="faster_msg_area" style="resize:both;width:382px;height:120px"></textarea></li>
        <li><div>黑名单(每行一个用户名):</div><textarea id="deny_users_area" style="resize:both;width:382px;height:120px"></textarea></li>
        <li><a id="up_pcbeta_tools" style="font-size:14px;color:green;display:none" target="_blank" href="https://lalaki.cn/pb/">有新版可用,点此获取</a><input type="button" id="tool_gui_save" value="存储配置" style="font-size:18px;float:right"></li>
        </ui>
        </div>
    </div>
        `;
	gui.style =
		"border-top-right-radius: 15px;display:none;user-select:none;position:fixed;left:0;top:0;z-index:999999;background:#333;box-shadow:5px 5px 10px rgba(0,0,0,0.3);";
	document.body.append(gui);
	document.querySelector("#tool_gui_close").onclick = () => {
		gui.style.display = "none";
	};
	//等级
	let hideStar = document.querySelector("#hide_star");
	hideStar.checked = GM_getValue("star", "false") == true;
	hideStar.addEventListener("change", () => {
		GM_setValue("star", hideStar.checked);
	});
	//徽章
	let hideAva = document.querySelector("#hide_ava");
	hideAva.checked = GM_getValue("ava", "false") == true;
	hideAva.addEventListener("change", () => {
		GM_setValue("ava", hideAva.checked);
	});
	//表情
	let hideExp = document.querySelector("#hide_exp");
	hideExp.checked = GM_getValue("exp", "false") == true;
	hideExp.addEventListener("change", () => {
		GM_setValue("exp", hideExp.checked);
	});
	//所有徽章体验
	let showAllAva = document.querySelector("#show_all_ava");
	showAllAva.checked = GM_getValue("avas", "false") == true;
	showAllAva.addEventListener("change", () => {
		GM_setValue("avas", showAllAva.checked);
	});
	//隐藏用户详细信息
	let hideDetail = document.querySelector("#hide_details");
	hideDetail.checked = GM_getValue("dts", "false") == true;
	hideDetail.addEventListener("change", () => {
		GM_setValue("dts", hideDetail.checked);
	});
	//不要地域黑
	let hideIPAddr = document.querySelector("#hide_ip_address");
	hideIPAddr.checked = GM_getValue("hip", "false") == true;
	hideIPAddr.addEventListener("change", () => {
		GM_setValue("hip", hideIPAddr.checked);
	});
	if (hideIPAddr.checked) {
		document.querySelectorAll("span").forEach((aa) => {
			if ((aa.innerHTML + "").trim().startsWith("IP属地")) {
				aa.style = "display:none";
			}
		});
	}
	//不显示签名
	let hideUserSign = document.querySelector("#hide_user_sign");
	hideUserSign.checked = GM_getValue("hsg", "false") == true;
	hideUserSign.addEventListener("change", () => {
		GM_setValue("hsg", hideUserSign.checked);
	});
	if (hideUserSign.checked) {
		document.querySelectorAll(".sign")?.forEach((sg) => {
			sg.style = "display:none";
		});
	}
	fetch("https://lalaki.cn/up/")
		.then(async (res) => ({
			status: res.status,
			body: await res.text(),
		}))
		.then(({ status, body }) => {
			if (status == 200 && body != FINAL_VERSION) {
				document.querySelector("#up_pcbeta_tools").style.display = "inline";
			} else {
				document.querySelector("#up_pcbeta_tools").innerHTML =
					"版本号: V" + FINAL_VERSION;
				document.querySelector("#up_pcbeta_tools").style.display = "inline";
				document
					.querySelector("#up_pcbeta_tools")
					.removeAttribute("href", location.href + "#");
				document.querySelector("#up_pcbeta_tools").setAttribute("target", "");
			}
		});
	document.querySelector("#tool_gui_save").onclick = () => {
		GM_setValue("denyUsers", document.querySelector("#deny_users_area").value);
		GM_setValue("fastMsgs", document.querySelector("#faster_msg_area").value);
		gui.style.display = "none";
		showDialog("配置已存储", "notice", "提示", () => {
			location.reload();
		});
	};
	//UI---
	//加载快捷发言
	const fastMsgList = GM_getValue("fastMsgs", "UNSET");
	if (fastMsgList != "UNSET") {
		let tmp = ("" + fastMsgList).trim();
		if (tmp != "") {
			document.querySelector("#faster_msg_area").value = tmp;
		}
	}
	let denyUsers = [];
	const denyList = GM_getValue("denyUsers", "UNSET");
	if (denyList != "UNSET") {
		let tmp = ("" + denyList).trim();
		if (tmp != "") {
			denyUsers = tmp.split("\n");
			document.querySelector("#deny_users_area").value = tmp;
		}
	}
	let me = (document.querySelector(".vwmy a")?.innerHTML + "").trim();
	document.querySelector("#postlist")?.childNodes.forEach((p) => {
		//在用户名后面添加拉黑按钮
		let pid = p.id;
		if (("" + pid).startsWith("post_")) {
			let user = document.querySelector("#" + pid + " .authi a");
			let username = ("" + user.innerHTML).trim();
			if (username != "" && denyUsers.indexOf(username) != -1) {
				p.style = "display:none";
			}
			let parent = user.parentNode;
			let block = document.createElement("a");
			block.innerHTML = "拉黑Ta";
			block.style = "float:right;cursor:pointer";
			block.onclick = () => {
				if (block.innerHTML == "已拉黑") {
					return;
				}
				showDialog(
					"确定要拉黑 <b>" + username + "</b> 吗?",
					"confirm",
					"询问",
					() => {
						document.querySelector("#deny_users_area").value =
							document.querySelector("#deny_users_area").value +
							"\n" +
							username;
						document.querySelector("#tool_gui_save").click();
						block.innerHTML = "已拉黑";
					}
				);
			};
			if (me != username) {
				parent.append(block);
			}
			//去掉引用内容
			let quote = document.querySelector("#" + pid + " .quote");
			denyUsers.forEach((du) => {
				if (("" + quote?.innerText).trim().startsWith(du)) {
					quote.style = "display:none";
				}
			});
			//去掉点评内容
			document.querySelectorAll("#" + pid + " .pstl.xs1").forEach((x) => {
				let name = ("" + x.querySelector(".psti a").innerHTML).trim();
				if (name != "" && denyUsers.indexOf(name) != -1) {
					x.style = "display:none";
				}
			});
		}
	});
	//屏蔽用户评分
	document.querySelectorAll(".rate li").forEach((r) => {
		let username = ("" + r.lastElementChild.innerText).trim();
		if (username != "" && denyUsers.indexOf(username) != -1) {
			r.style = "display:none";
		}
	});
	//屏蔽提醒消息
	document.querySelectorAll("dl").forEach((nt) => {
		let username = (nt.querySelector(".ntc_body a")?.innerHTML + "").trim();
		if (username != "" && denyUsers.indexOf(username) != -1) {
			nt.style = "display:none";
		}
	});
	//屏蔽主题贴子
	document.querySelectorAll(".pbw").forEach((t) => {
		let all = t.querySelectorAll("a");
		let last = all[all.length - 2];
		let username = ("" + last.innerHTML).trim();
		if (username != "" && denyUsers.indexOf(username) != -1) {
			t.style = "display:none";
		}
	});
	//屏蔽随便看看
	document.querySelectorAll("tbody").forEach((b) => {
		b.querySelectorAll("tr").forEach((tr) => {
			let username = ("" + tr.querySelectorAll("a")[3]?.innerHTML).trim();
			if (username != "" && denyUsers.indexOf(username) != -1) {
				tr.style = "display:none";
			}
		});
	});
	//屏蔽板块帖子
	document.querySelectorAll(".by a").forEach((un) => {
		let username = (un.innerHTML + "").trim();
		if (username != "" && denyUsers.indexOf(username) != -1) {
			let parent = un.parentNode;
			while (parent != null) {
				if (parent.nodeName == "TR") {
					parent.style = "display:none";
					break;
				}
				parent = parent.parentNode;
			}
		}
	});
	//屏蔽等级显示
	if (hideStar.checked) {
		document
			.querySelectorAll(".avatar_p")
			.forEach((a) => (a.style = "display:none"));
		document.querySelectorAll("p").forEach((st) => {
			if (("" + st.id).startsWith("g_up")) {
				st.style = "display:none";
			}
		});
	}
	//屏蔽徽章显示
	if (hideAva.checked) {
		document
			.querySelectorAll(".md_ctrl")
			.forEach((a) => (a.style = "display:none"));
	}
	//屏蔽论坛小表情
	if (hideExp.checked) {
		document.querySelectorAll("img").forEach((i) => {
			if (
				("" + i.src).startsWith("https://bbs.pcbeta.com/static/image/smiley")
			) {
				i.style = "display:none";
			}
		});
	}
	//一键客套
	let faster = document.createElement("span");
	document.querySelector(".bar")?.append(faster);
	faster.innerHTML = "&nbsp;&nbsp;常用语模板";
	faster.style = "position:absolute;cursor:pointer;user-select:none";
	faster.onclick = () => {
		let fasterUIGet = faster.parentNode.querySelector("ul");
		if (fasterUIGet != null) {
			fasterUIGet.style.display = "block";
			return;
		}
		let fasterListUI = document.createElement("ul");
		fasterListUI.style =
			"left:" +
			faster.offsetLeft +
			"px;padding:4px;margin-top: 26px;position:absolute;background:#fff; box-shadow: -5px 5px 10px rgba(0, 0, 0, 0.2),5px 5px 10px rgba(0, 0, 0, 0.2),0 5px 10px rgba(0, 0, 0, 0.2);";
		let fastMsgs1 = document.querySelector("#faster_msg_area").value.trim();
		if (fastMsgs1 != "") {
			fasterListUI.innerHTML = "<style>.my-hover:hover{color:red;}</style>";
			fastMsgs1.split("\n").forEach((fm) => {
				let fasterListItem = document.createElement("li");
				fasterListItem.innerHTML = fm;
				fasterListItem.className = "my-hover";
				fasterListItem.style = "cursor:pointer";
				fasterListItem.onclick = () => {
					document.querySelector(".area textarea").value =
						fasterListItem.innerHTML;
					fasterListUI.style.display = "none";
				};
				fasterListUI.append(fasterListItem);
			});
			faster.after(fasterListUI);
		}
	};
	//装逼模式
	let avas = [
		"https://i.pcbeta.com/static/image/common/medal_201209/zscj.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/yxbz.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/xcs.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/ycxf.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/rxhy.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/jdz.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/hdzz.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/cyxf.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/jydr.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/ryhy.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/yjsf.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/yxbs.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/nmxx.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/mhdr.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/kfdr.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/jsdr.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/jzt.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/byg.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/yxdr.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/xbs.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/xbs2.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/pcdr.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/tsgx.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/ss.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/rich.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/7.png",
		"https://i.pcbeta.com/static/image/common/medal_iety.png",
		"https://i.pcbeta.com/static/image/common/medal_surface1.png",
		"https://i.pcbeta.com/static/image/common/medal_movies.png",
		"https://i.pcbeta.com/static/image/common/medal_appx.png",
		"https://i.pcbeta.com/static/image/common/medal_zdx.png",
		"https://i.pcbeta.com/static/image/common/medal_book.png",
		"https://i.pcbeta.com/static/image/common/medal_8th.png",
		"https://i.pcbeta.com/static/image/common/medal_smdr.png",
		"https://i.pcbeta.com/static/image/common/medal_dianzan.png",
		"https://i.pcbeta.com/static/image/common/medal_windowsphone.png",
		"https://i.pcbeta.com/static/image/common/medal_worldcup.png",
		"https://i.pcbeta.com/static/image/common/medal_daxuesheng.png",
		"https://i.pcbeta.com/static/image/common/medal_9a.png",
		"https://i.pcbeta.com/static/image/common/Win_10_forerunner.png",
		"https://i.pcbeta.com/static/image/common/10.png",
		"https://i.pcbeta.com/static/image/common/medal_201209/medal_11th.png",
	];
	if (showAllAva.checked) {
		let bava = document.createElement("p");
		bava.className = "md_ctrl";
		avas.forEach((au) => {
			let avico = document.createElement("img");
			avico.src = au;
			bava.append(avico);
		});
		document.querySelectorAll(".pil.cl").forEach((ckme) => {
			let ifMe = ckme.parentNode.querySelector(".authi a").innerHTML.trim();
			if (ifMe == me && me != "") {
				ckme.after(bava);
			}
		});
	}
	let shortcut = document.createElement("a");
	shortcut.innerHTML = "远景小助手";
	shortcut.style = "cursor:pointer;";
	shortcut.onclick = () => {
		gui.style.display = "block";
	};
	let alla = document.querySelectorAll("a");
	for (let i = 0; i < alla.length; i++) {
		if (alla[i]?.innerHTML == "马甲") {
			alla[i].before(shortcut);
			break;
		}
	}
	if (hideDetail.checked) {
		document.querySelectorAll(".pil.cl")?.forEach((dt) => {
			dt.style = "display:none";
		});
	}
})();