|
在此基础上,主要加了菜单,方便修改设置 我原本是想如果浏览器打开了“提醒”网页,就不自动关闭和自动跳转,方便回复别人的,但是那样脚本就太慢了
搞了两种菜单的显示形式 第一种:显示在网页右下角 能实时更新
第二种:在油猴的菜单里 因为油猴选项需要刷新网页才能更新,所以我改成了点击之后新建一个 例如: (当然,刷新之后又会正常显示三个选项) 嗯,第一种方便一点,第二张美观一点?
需要点击设置,修改成自己的uid 需要点击设置,修改成自己的uid 需要点击设置,修改成自己的uid
第一种
//@Name
- // ==UserScript==
- // @name:zh-CN 我水贴了吗
- // @name Am_I_+2?
- // @include https://www.gamemale.com/*
- // ==/UserScript==
- (async () => {
- "use strict";
- let userId = 679483; // 你的用户 ID
- let autoCloseReplied = true; // 已回帖的网站是否自动关闭
- let autoJumpForum = true; // 是否自动跳转到帖子第一页
- let autoCloseDelay = 10; // 自动关闭页面的延迟时间,单位为毫秒
- const menuAll = `
- <div id="am-i-plus2-menu" style="position: fixed; bottom: 10px; right: 10px; z-index: 999;">
- <div>
- <span>自动关闭:</span>
- <span id="auto-close">${autoCloseReplied ? "✅" : "❌"}</span>
- </div>
- <div>
- <span>自动跳转:</span>
- <span id="auto-jump">${autoJumpForum ? "✅" : "❌"}</span>
- </div>
- <div>
- <span id="settings-btn"><i class="fas fa-cog"></i>设置#️⃣</span>
- </div>
- </div>
- `;
- const setSettings = () => {
- const savedSettings = localStorage.getItem("am-i-plus2-settings");
- let savedUserId = userId;
- let savedAutoCloseDelay = autoCloseDelay;
- if (savedSettings) {
- const { userId: savedUserIdFromStorage, autoCloseDelay: savedAutoCloseDelayFromStorage } = JSON.parse(savedSettings);
- savedUserId = savedUserIdFromStorage;
- savedAutoCloseDelay = savedAutoCloseDelayFromStorage;
- }
- const userIdInput = prompt("请输入用户ID", savedUserId);
- if (userIdInput !== null) {
- userId = Number(userIdInput);
- }
- const autoCloseDelayInput = prompt("请输入自动关闭时间(毫秒)", savedAutoCloseDelay);
- if (autoCloseDelayInput !== null) {
- autoCloseDelay = Number(autoCloseDelayInput);
- }
- localStorage.setItem("am-i-plus2-settings", JSON.stringify({ userId, autoCloseReplied, autoJumpForum, autoCloseDelay }));
- };
- const setAutoClose = () => {
- autoCloseReplied = !autoCloseReplied;
- autoCloseBtn.textContent = autoCloseReplied ? "✅" : "❌";
- localStorage.setItem("am-i-plus2-settings", JSON.stringify({ userId, autoCloseReplied, autoJumpForum, autoCloseDelay }));
- };
- const setAutoJump = () => {
- autoJumpForum = !autoJumpForum;
- autoJumpBtn.textContent = autoJumpForum ? "✅" : "❌";
- localStorage.setItem("am-i-plus2-settings", JSON.stringify({ userId, autoCloseReplied, autoJumpForum, autoCloseDelay }));
- };
- document.body.insertAdjacentHTML("beforeend", menuAll);
- const autoCloseBtn = document.querySelector("#auto-close");
- const autoJumpBtn = document.querySelector("#auto-jump");
- const settingsBtn = document.querySelector("#settings-btn");
- autoCloseBtn.addEventListener("click", setAutoClose);
- autoJumpBtn.addEventListener("click", setAutoJump);
- settingsBtn.addEventListener("click", setSettings);
- const savedSettings = localStorage.getItem("am-i-plus2-settings");
- if (savedSettings) {
- const { userId: savedUserId, autoCloseReplied: savedAutoCloseReplied, autoJumpForum: savedAutoJumpForum, autoCloseDelay: savedAutoCloseDelay } = JSON.parse(savedSettings);
- userId = savedUserId;
- autoCloseReplied = savedAutoCloseReplied;
- autoJumpForum = savedAutoJumpForum;
- autoCloseDelay = savedAutoCloseDelay;
- autoCloseBtn.textContent = autoCloseReplied ? "✅" : "❌";
- autoJumpBtn.textContent = autoJumpForum ? "✅" : "❌";
- }
- const isDiscuz = typeof discuz_uid !== "undefined";
- let testUrl = location.href;
- if (/^https:\/\/www\.gamemale\.com\/forum\.php\?mod=viewthread&tid=\d+/.test(testUrl)) {
- const tid = testUrl.match(/tid=(\d+)/)[1];
- testUrl = `https://www.gamemale.com/thread-${tid}-1-1.html`;
- }
- try {
- const res = await fetch(`https://www.gamemale.com/forum.php?mod=viewthread&tid=${tid}&page=1&authorid=${userId}`);
- const html = await res.text();
- const replied = html.includes("发表于");
- if (replied) {
- if (autoCloseReplied) {
- setTimeout(() => {
- window.close();
- }, autoCloseDelay);
- }
- }
- if (isDiscuz) {
- const btnArea = document.querySelector("#postlist td.plc div.authi>span.none") ?? document.querySelector("#postlist td.plc div.authi>span.pipe");
- const tips = document.createElement("a");
- tips.textContent = replied ? "✅已回帖" : "❌没回贴";
- tips.style.marginLeft = "10px";
- tips.style.color = replied ? "green" : "red";
- btnArea.insertBefore(tips, btnArea.lastElementChild);
- } else {
- const btnArea = document.querySelector("#postlist > div:first-child .authi");
- const tips = document.createElement("span");
- tips.textContent = replied ? "✅已回帖" : "❌没回贴";
- tips.style.marginLeft = "10px";
- tips.style.color = replied ? "green" : "red";
- btnArea.appendChild(tips);
- }
- if (autoJumpForum && !replied) {
- const topUrl = `https://www.gamemale.com/thread-${tid}-1-1.html#top`;
- location.href = topUrl;
- }
- } catch (error) {
- console.error(error);
- }
- })();
复制代码
第二种
//@Name
- // ==UserScript==
- // @name Am_I_+2
- // @name:zh-CN 我水贴了吗 ?
- // @include https://www.gamemale.com/*
- // @grant GM_registerMenuCommand
- // @grant GM_setValue
- // @grant GM_getValue
- // ==/UserScript==
- (async () => {
- "use strict";
- const userId = GM_getValue("userid", 679483); // 你的用户 ID
- const autoCloseReplied = GM_getValue("autoClose", true); // 已回帖的网站是否自动关闭
- const autoJumpForum = GM_getValue("autoJump", true); // 是否自动跳转到帖子第一页
- const autoCloseDelay = GM_getValue("autoCloseDelay", 10); // 自动关闭页面的延迟时间,单位为毫秒
- const setSettings = () => {
- const savedUserId = GM_getValue("userid", userId);
- const savedAutoCloseDelay = GM_getValue("autoCloseDelay", autoCloseDelay);
- const userIdInput = prompt("请输入用户ID", savedUserId);
- if (userIdInput !== null) {
- GM_setValue("userid", Number(userIdInput));
- }
- const autoCloseDelayInput = prompt("请输入自动关闭时间(毫秒)", savedAutoCloseDelay);
- if (autoCloseDelayInput !== null) {
- GM_setValue("autoCloseDelay", Number(autoCloseDelayInput));
- }
- };
- const setAutoClose = () => {
- const newAutoCloseReplied = !autoCloseReplied;
- GM_setValue("autoClose", newAutoCloseReplied);
- const icon = newAutoCloseReplied ? "✅" : "❌";
- const menuText = `自动关闭:${icon} ${newAutoCloseReplied ? "已开启" : "已关闭"}`;
- GM_registerMenuCommand(menuText, setAutoClose);
- const tips = document.querySelector("#autoCloseTips");
- tips.textContent = `${icon} ${newAutoCloseReplied ? "已开启" : "已关闭"}`;
- };
- const setAutoJump = () => {
- const newAutoJumpForum = !autoJumpForum;
- GM_setValue("autoJump", newAutoJumpForum);
- const icon = newAutoJumpForum ? "✅" : "❌";
- const menuText = `自动跳转:${icon} ${newAutoJumpForum ? "已开启" : "已关闭"}`;
- GM_registerMenuCommand(menuText, setAutoJump);
- const tips = document.querySelector("#autoJumpTips");
- tips.textContent = `${icon} ${newAutoJumpForum ? "已开启" : "已关闭"}`;
- };
- const autoCloseIcon = autoCloseReplied ? "✅" : "❌";
- const autoCloseColor = autoCloseReplied ? "green" : "red";
- GM_registerMenuCommand(`自动关闭:${autoCloseIcon} ${autoCloseReplied ? "已开启" : "已关闭"}`, setAutoClose);
- const autoJumpIcon = autoJumpForum ? "✅" : "❌";
- const autoJumpColor = autoJumpForum ? "green" : "red";
- GM_registerMenuCommand(`自动跳转:${autoJumpIcon} ${autoJumpForum ? "已开启" : "已关闭"}`, setAutoJump);
- GM_registerMenuCommand("设置", setSettings);
- const isDiscuz = typeof discuz_uid !== "undefined";
- let testUrl = location.href;
- if (/^https:\/\/www\.gamemale\.com\/forum\.php\?mod=viewthread&tid=\d+/.test(testUrl)) {
- const tid = testUrl.match(/tid=(\d+)/)[1];
- testUrl = `https://www.gamemale.com/thread-${tid}-1-1.html`;
- }
- try {
- const res = await fetch(`https://www.gamemale.com/forum.php?mod=viewthread&tid=${tid}&page=1&authorid=${userId}`);
- const html = await res.text();
- const replied = html.includes("发表于");
- if (replied && autoCloseReplied) {
- setTimeout(() => {
- window.close();
- }, autoCloseDelay);
- }
- const btnArea = isDiscuz ? document.querySelector("#postlist td.plc div.authi>span.none") ?? document.querySelector("#postlist td.plc div.authi>span.pipe") : document.querySelector("#postlist > div:first-child .authi");
- const tips = document.createElement(isDiscuz ? "a" : "span");
- tips.textContent = `${replied ? "✅" : "❌"} ${replied ? "已回帖" : "未回帖"}`;
- tips.style.marginLeft = "10px";
- tips.style.color = replied ? "green" : "red";
- btnArea.appendChild(tips);
- if (!replied && autoJumpForum) {
- const topUrl = `https://www.gamemale.com/thread-${tid}-1-1.html#top`;
- location.href = topUrl;
- }
- const autoCloseTips = document.createElement("span");
- autoCloseTips.id = "autoCloseTips";
- autoCloseTips.textContent = `${autoCloseIcon} ${autoCloseReplied ? "已开启" : "已关闭"}`;
- autoCloseTips.style.marginLeft = "10px";
- autoCloseTips.style.color = autoCloseColor;
- btnArea.appendChild(autoCloseTips);
- const autoJumpTips = document.createElement("span");
- autoJumpTips.id = "autoJumpTips";
- autoJumpTips.textContent = `${autoJumpIcon} ${autoJumpForum ? "已开启" : "已关闭"}`;
- autoJumpTips.style.marginLeft = "10px";
- autoJumpTips.style.color = autoJumpColor;
- btnArea.appendChild(autoJumpTips);
- } catch (error) {
- console.error(error);
- }
- })();
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
查看全部评分
|