// ==UserScript== // @name 远景小助手 // @namespace http://tampermonkey.net/ // @version 11.0.0.9 // @description 远景论坛自定义小功能~ 优化你的访问体验。常用功能: 一键领取任务与奖励,快捷发言-自定义常用语,可选功能: 屏蔽指定用户的发言,隐藏等级 | 徽章 | 签名 | 默认黄色小老虎表情显示等。 // @homepage https://lalaki.cn // @author lalaki // @match https://*.pcbeta.com/* // @icon https://lalaki.cn/p/?i=pbi // @grant GM_setValue // @grant GM_getValue // @license MIT // @supportURL https://lalaki.cn/rp // @downloadURL none // ==/UserScript== (function () { "use strict"; const FINAL_VERSION = "20"; const pluginName = "远景小助手"; const style = document.createElement("style"); const denyUsers = []; style.innerHTML = ` .la-blue{ color:blue !important; } .la-green{ color:#6dff02 !important; } .la-bg-active{ background:#2ca10a; } .la-error{ color:#ffc107; } .fwinmask{ z-index:2147483647 !important; } `; document.head.appendChild(style); const ui = document.createElement("div"); ui.setAttribute("hidden", "hidden"); ui.style = "user-select:none;color:inherit;background-color:transparent;font-size:150%;position:fixed;left:0;top:0;z-index:2147483646"; document.body.append(ui); const shadow = ui.attachShadow({ mode: "open" }); const cont = document.createElement("div"); const h0 = "display:none"; function tryBlockUsers() { 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; } } }); } //UI界面布局 cont.innerHTML = `
问题反馈/功能建议: 请在这里提交
", "notice", "提示" ); }; if (isScrollTop) { let scrollTop = document.querySelector("#scrolltop"); if (scrollTop != null) { function scrollBtnFix() { let rect = scrollTop.getBoundingClientRect(); let st0 = rect.left + rect.width; let st1 = rect.top + rect.height; let mWidth = window.innerWidth; let mHeight = window.innerHeight; let sData = GM_getValue("sl", "UNSET"); let hasData = false; let sDataSplit = []; if (sData.indexOf(";") != -1) { sDataSplit = sData.split(";"); hasData = sDataSplit.length > 1; } if (st0 > mWidth) { scrollTop.style.left = mWidth - 1.5 * rect.width + "px"; } else if (hasData) { let saveLeft = parseInt(sDataSplit[0]) + rect.width; if (saveLeft < mWidth) { scrollTop.style.left = saveLeft - rect.width + "px"; } } if (st1 > mHeight) { scrollTop.style.top = mHeight - 1.5 * rect.height + "px"; } else if (hasData) { let saveTop = parseInt(sDataSplit[1]) + rect.height; if (saveTop < mHeight) { scrollTop.style.top = saveTop - rect.height + "px"; } } } window.addEventListener("scroll", scrollBtnFix); window.addEventListener("resize", scrollBtnFix); scrollTop.addEventListener("mousedown", (e) => { if (e.button === 0) { let rect0 = scrollTop.getBoundingClientRect(); offsetX = e.clientX - rect0.left; offsetY = e.clientY - rect0.top; document.addEventListener("mousemove", mouseMoveHandler); document.addEventListener("mouseup", mouseUpHandler); e.preventDefault(); } }); scrollTop.style.backgroundImage = "url('https://ps.w.org/scroll-top/assets/icon-128x128.png')"; scrollTop.style.backgroundSize = "contain"; scrollTop.style.borderRadius = "7px"; scrollTop.style.zIndex = 9999; function mouseMoveHandler(e) { let sLeft = `${e.clientX - offsetX}px`; let sTop = `${e.clientY - offsetY}px`; scrollTop.style.left = sLeft; scrollTop.style.top = sTop; scrollTop.style.cursor = "move"; GM_setValue("sl", sLeft + ";" + sTop); } let sData = GM_getValue("sl", "UNSET"); if (sData.indexOf(";") != -1) { let sDataSplit = sData.split(";"); if (sDataSplit.length > 1) { scrollTop.style.left = sDataSplit[0]; scrollTop.style.top = sDataSplit[1]; } } function mouseUpHandler() { scrollTop.style.cursor = "pointer"; document.removeEventListener("mousemove", mouseMoveHandler); document.removeEventListener("mouseup", mouseUpHandler); } } } cont.querySelectorAll(".custom_avas").forEach((ca) => { ca.onclick = (e0) => { let imgUri = e0.target.src; let url = GM_getValue("imgurls", "NUL"); if (e0.target.className.indexOf("la-bg-active") == -1) { e0.target.className += " la-bg-active"; if ((url + "").trim() == "" || url == "NUL") { GM_setValue("imgurls", imgUri); } else { GM_setValue("imgurls", url + ";" + imgUri); } } else { e0.target.classList.remove("la-bg-active"); if ((url + "").trim() == "" || url == "NUL") { return; } else { let newUri = url.replaceAll(imgUri, ""); GM_setValue("imgurls", newUri.replaceAll(";;", ";")); } } }; }); function createAddFrientDom(url) { let fastFriend = document.createElement("a"); fastFriend.innerHTML = "加好友"; fastFriend.style = "cursor:pointer;margin:0 0 0 16px"; fastFriend.onclick = () => { let result = new URLSearchParams(url); let uid = result.get("touid"); if (fastFriend.innerHTML != "等待通过") { fetch( "https://bbs.pcbeta.com/home.php?mod=spacecp&ac=friend&op=add&uid=" + uid, { method: "GET", credentials: "include", } ) .then(async (res) => ({ status: res.status, buffer: await res.arrayBuffer(), })) .then(({ status, buffer }) => { if (status == 200) { let decoder = new TextDecoder("gbk"); let html = decoder.decode(buffer); if (html.indexOf("不存在") == -1) { let dom = document.createElement("div"); dom.innerHTML = html; let addForm = dom.querySelector("#addform_" + uid); if (addForm != null) { let px = addForm.querySelector(".px"); if (px != null) { px.value = "Hello"; } if (addForm != null) { fetch(addForm.action, { method: "POST", body: new FormData(addForm), }) .then(async (res) => ({ status: res.status, buffer: await res.arrayBuffer(), })) .then(({ status, buffer }) => { if (status == 200) { fastFriend.innerHTML = "等待通过"; } else { alert("添加失败"); } }); } } else { let msg = dom.querySelector("#messagetext p"); if (msg != null) { alert(msg.innerHTML); } } } } }); } }; return fastFriend; } if (location.href.indexOf("viewthread") != -1) { document.querySelectorAll(".imicn a").forEach((it) => { let atext = (it.innerHTML + "").trim(); if (atext == "发消息") { it.after(createAddFrientDom(it.href)); } }); } let fsDom = document.querySelector(".bm .mtm .bm_c"); if (fsDom != null) { fsDom.style.marginTop = "20px"; fsDom.style.display = "flex"; let fsInput = fsDom.querySelector(".px.vm"); if (fsInput != null) { fsInput.style.flexGrow = 1; fsInput.parentNode.style.display = "contents"; fsInput.style.marginRight = "5px"; } } if (autoPgs && location.href.indexOf("viewthread") != -1) { let pages = document.querySelectorAll("#pgt .pgt .pg a"); if (pages.length != 0 && pages.length < 10) { let realPages = []; pages.forEach((pg) => { if ((pg.className + "").trim() == "") { realPages.push(pg.href); } }); let index = 0; let getIndex = document.querySelector(".pgs .pg strong"); if (getIndex != null) { let testIndex = (getIndex.innerHTML + "").trim(); let testIndex1 = parseInt(testIndex); if (testIndex1 > 0) { index = testIndex1 - 1; } } if (index == 0) { document.querySelectorAll(".pgs .pg").forEach((it) => (it.style = h0)); } window.reading = true; window.addEventListener("scroll", async function () { const scrollTop = window.scrollY || document.documentElement.scrollTop; const windowHeight = window.innerHeight; const documentHeight = document.documentElement.scrollHeight; if ( scrollTop + windowHeight >= documentHeight - 480 && window.reading ) { if (index == realPages.length) { return; } window.reading = false; let url = realPages[index]; let twoReading = true; while (twoReading) { let resp = await fetch(url, { method: "GET", credentials: "include", }); if (resp.ok) { twoReading = false; index++; setTimeout(() => { window.reading = true; }, 50); let decoder = new TextDecoder("gbk"); const buffer = await resp.arrayBuffer(); let html = decoder.decode(buffer); let dom = document.createElement("div"); dom.innerHTML = html; let postList = dom.querySelector("#postlist"); postList.querySelectorAll(".showmenu").forEach((it) => { if ((it.innerHTML + "").trim() == "使用道具") { it.style = h0; } }); if (postList != null) { let addDom = []; postList.childNodes.forEach((ph) => { if (("" + ph.id).trim().startsWith("post_")) { let insertDom = null; let parentDom = document.querySelector("#postlistreply"); if (parentDom != null) { insertDom = parentDom.previousSibling; } if (insertDom == null) { parentDom = document.querySelector("#postlist"); if (parentDom != null) { parentDom.childNodes.forEach((ist) => { if ((ist.id + "").startsWith("post_")) { insertDom = ist; } }); } } if (insertDom != null) { ph.querySelectorAll(".aimg").forEach((it) => { let imgSrc = it.getAttribute("file"); if (it.src.indexOf("none")) { it.src = imgSrc; } }); insertDom.after(ph); addDom.push(ph); addBlockBtns(ph.id, ph); ph.querySelectorAll(".imicn a").forEach((it) => { let atext = (it.innerHTML + "").trim(); if (atext == "发消息") { it.after(createAddFrientDom(it.href)); } }); } } }); if (hideDetails) { hideUInfoFunc(); } if (hideStar) { hideStarFunc(); } if (hideAva) { hideAvaFunc(); } if (hideExp) { hideExpFunc(); } if (hideSign) { hideSignFunc(); } if (hideIp) { hideIpFunc(); } if (hideAvas) { addDom.forEach((ph1) => { ph1.querySelectorAll(".pil.cl").forEach((ckme) => { let dom0 = ckme.parentNode.querySelector(".authi a"); if (dom0 != null) { let ifMe = dom0.innerHTML.trim(); if (ifMe == me && me != "") { ckme.after(window.bava.cloneNode(true)); } } }); }); } if (denyUsers.length > 0) { tryBlockUsers(); } if (isNotNewWindow) { openUrlWithoutNewWindow(); } } } } } }); } } if ((location.search + "").indexOf("mod=logging&action=login") != -1) { document.querySelectorAll("input").forEach((it) => { it.setAttribute("autocomplete", "on"); }); document.querySelectorAll("form").forEach((it) => { it.setAttribute("autocomplete", "on"); }); } cont.querySelector("#update_tips").removeAttribute("hidden"); let vers = cont.querySelector(".la-li-item4"); vers.style = "display:flex;justify-content:center;text-indent:0px;padding:7px 0 7px 0;"; vers.innerHTML = "版本号: v" + FINAL_VERSION; let lastUpdate = GM_getValue("last_update", "0"); let currentTime = new Date().getTime(); if (currentTime - parseInt(lastUpdate) > 50000) { fetch("https://lalaki.cn/up/") .then(async (res) => ({ status: res.status, body: await res.text(), })) .then(({ status, body }) => { if (status == 200) { if (body != FINAL_VERSION) { vers.innerHTML = "检测到新版本,可前往更新