Greasy Fork

Greasy Fork is available in English.

远景小助手

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

当前为 2024-10-20 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         远景小助手
// @namespace    http://tampermonkey.net/
// @version      5.0.0.4
// @description  远景论坛自定义小功能~:自定义常用语,屏蔽指定用户的发言,隐藏等级|徽章|表情显示等。
// @author       lalaki
// @match        https://*.pcbeta.com/*
// @icon         https://i.pcbeta.com/favicon.ico
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT
// ==/UserScript==
(function () {
    "use strict";
    const FINAL_VERSION = 5.4;
    //UI
    let gui = document.createElement("div");
    gui.innerHTML = `
    <div style="font-size:144%" draggable="false">
        <div style="background:#1985db;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:22px;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><input id="fast_send_msg_legacy" type="checkbox"><label for="fast_send_msg_legacy">兼容性(功能正常时无需启用)</label></li>
        <li><input id="fast_send_msg" type="checkbox"><label for="fast_send_msg">快捷发言</label></li>
        <li id="fast_send_msg_ct" style="display:none"><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;margin:0 0 0 5px"><input type="button" id="tools_bug_report" value="反馈" style="font-size:18px;float:right"></li>
        </ui>
        </div>
    </div>
        `;
    gui.style =
        "font-family:Segoe UI;border-top-right-radius: 15px;display:none;user-select:none;position:fixed;left:0;top:-1000px;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 = () => {
        let top = 0;
        let iv = setInterval(() => {
            if (Math.abs(top) <= gui.offsetHeight + 100) {
                gui.style.top = top + "px";
                top -= 60;
            } else {
                gui.style.display = "none";
                clearInterval(iv);
            }
        }, 15);
    };
    document.querySelector("#tools_bug_report").onclick = () => {
        location.href = "https://bbs.pcbeta.com/viewthread-2019443-1-1.html";
    };
    //等级
    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 fastMsg = document.querySelector("#fast_send_msg");
    fastMsg.checked = GM_getValue("fmg", "false") == true;
    fastMsg.addEventListener("change", () => {
        GM_setValue("fmg", fastMsg.checked);
        document.querySelector("#fast_send_msg_ct").style =
            "display:" + (fastMsg.checked ? "block" : "none");
    });
    //兼容性
    let legacy = document.querySelector("#fast_send_msg_legacy");
    legacy.checked = GM_getValue("lga", "false") == true;
    legacy.addEventListener("change", () => {
        GM_setValue("lga", legacy.checked);
    });
    //不显示签名
    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);
        document.querySelector("#tool_gui_close").click();
        // eslint-disable-next-line
        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").map((it) => it.trim());
            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;
                }
                // eslint-disable-next-line
                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);
            }
        }
    });
    //拉黑核心代码v5
    if (denyUsers.length > 0) {
        const h0 = "display:none";
        document.querySelectorAll(".quote").forEach((q) => {
            let qu = ("" + q.innerText).trim();
            denyUsers.forEach((u) => {
                if (qu != "" && qu.startsWith(u)) {
                    q.style = h0;
                }
            });
        });
        document.querySelectorAll("a").forEach((a) => {
            let parent = a;
            let patch = false;
            while (parent != null) {
                let username = ("" + a.innerHTML).trim();
                if (username == "" || denyUsers.indexOf(username) == -1) {
                    break;
                }
                let pid = ("" + parent.id).trim();
                if (
                    pid.startsWith("post_") ||
                    pid.startsWith("stickthread_") ||
                    pid.startsWith("normalthread_")
                ) {
                    parent.style = h0;
                    break;
                }
                let pClass = ("" + parent.className).trim();
                let nd = parent.nodeName.toLowerCase();
                if (
                    pClass == "pbw" ||
                    pClass == "bw0_all" ||
                    nd == "tr" ||
                    nd == "li"
                ) {
                    //处理特殊情况
                    parent.style = h0;
                    break;
                }
                if (
                    pClass == "nts" ||
                    nd == "body" ||
                    pClass == "p_pop" ||
                    pClass == "y"
                ) {
                    //保护节点
                    break;
                }
                let pc = 0;
                parent.querySelectorAll("a").forEach((pa) => {
                    if (pa.href.indexOf(a.href) != -1) {
                        pc++;
                    }
                });
                if (pc > 1) {
                    parent.style = h0;
                    patch = true;
                    break;
                }
                parent = parent.parentNode;
            }
            if (patch) {
                //修复回复部分~~
                parent = a;
                while (parent != null) {
                    let pid = ("" + parent.id).trim();
                    if (
                        pid.startsWith("post_") ||
                        pid.startsWith("stickthread_") ||
                        pid.startsWith("normalthread_")
                    ) {
                        parent.style = h0;
                        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");
    if (fastMsg.checked) {
        document.querySelector("#fast_send_msg_ct").style = "display:block";
        let append = document.querySelector("#append_parent");
        if (legacy.checked) {
            setInterval(() => {
                let r1 = document.querySelector("#fwin_content_reply .fpd");
                if (r1 == null) {
                    r1 = document.querySelector(".bar");
                }
                if (r1 != null) {
                    r1.append(faster);
                }
            }, 500);
        }
        if (append != null) {
            const observer = new MutationObserver((mutationsList) => {
                for (let mutation of mutationsList) {
                    if (
                        mutation.type == "childList" &&
                        document.querySelector(".area textarea") != null
                    ) {
                        setTimeout(() => {
                            let r1 = document.querySelector("#fwin_content_reply .fpd");
                            if (r1 == null) {
                                r1 = document.querySelector(".bar");
                            }
                            if (r1 != null) {
                                r1.append(faster);
                            }
                        }, 500);
                    }
                }
            });
            observer.observe(append, {
                childList: true,
            });
        }
    }
    faster.innerHTML = "&nbsp;&nbsp;常用语模板";
    faster.style =
        "position:absolute;cursor:pointer;user-select:none;z-index:200";
    faster.onclick = () => {
        let fasterUIGet = faster.parentNode.querySelector("ul");
        if (fasterUIGet != null) {
            if (fasterUIGet.style.display == "block") {
                fasterUIGet.style.display = "none";
            } else {
                fasterUIGet.style.display = "block";
            }
            return;
        }
        let fasterListUI = document.createElement("ul");
        fasterListUI.style =
            "left:" +
            faster.offsetLeft +
            "px;border-radius:3px;z-index:99999;user-select:none;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 = () => {
                    let editContent = document.querySelector(".area textarea");
                    let editNb = editContent.nextElementSibling;
                    if (
                        editContent == null ||
                        (editNb != null && editNb.nodeName.toLowerCase() == "iframe")
                    ) {
                        // eslint-disable-next-line
                        showDialog("当前页面不支持常用语");
                    }
                    if (editContent != null) {
                        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;user-select:none";
    shortcut.onclick = () => {
        if (gui.style.display == "block") {
            return;
        }
        gui.style.display = "block";
        let top = -1000;
        let iv = setInterval(() => {
            if (top <= 0) {
                gui.style.top = top + "px";
                top += 100;
            } else {
                clearInterval(iv);
            }
        }, 15);
    };
    let alla = document.querySelectorAll("a");
    for (let i = 0; i < alla.length; i++) {
        if (["马甲", "快捷导航", "返回首页"].indexOf(alla[i]?.innerHTML) != -1) {
            alla[i].before(shortcut);
            break;
        } else if (alla[i]?.innerHTML == "登录") {
            let tmpli = document.createElement("li");
            tmpli.style = "width:auto";
            tmpli.append(shortcut);
            alla[i].parentNode.before(tmpli);
            tmpli.parentNode.style = "width:auto";
            shortcut.style =
                "width:auto;padding:0 0 0 5px;cursor:pointer;user-select:none";
            break;
        }
    }
    if (hideDetail.checked) {
        document.querySelectorAll(".pil.cl")?.forEach((dt) => {
            dt.style = "display:none";
        });
    }
})();