Makima 发表于 2026-1-4 12:17:00

【脚本】只看本人


在帖子主楼添加只看本人的按键
按shift+ctrl+c,可更换uid


@Name @Match
// ==UserScript==
// @name         只看本人
// @version      0.1
// @description在只看该作者旁边添加只看本人功能
// @author       MKM
// @match      https://www.gamemale.com/*
// ==/UserScript==

(function() {
    'use strict';

    const STORAGE_KEY = 'discuz_my_authorid';

    function init() {
      addStyles();
      const firstPostLink = findFirstPostOnlyLink();
      if (firstPostLink) {
            addViewMeButton(firstPostLink);
      }
    }

    function findFirstPostOnlyLink() {
      const links = document.querySelectorAll('a');
      for (let i = 0; i < links.length; i++) {
            if (links.textContent === '只看该作者') {
                return links;
            }
      }
      return null;
    }

    function addViewMeButton(onlyPostLink) {
      const viewMeLink = document.createElement('a');
      viewMeLink.href = 'javascript:;';
      viewMeLink.textContent = '只看本人';
      viewMeLink.className = 'view-me-link';
      viewMeLink.addEventListener('click', function(e) {
            e.preventDefault();
            handleViewMeClick(onlyPostLink);
      });
      const separator = document.createElement('span');
      separator.className = 'pipe';
      separator.textContent = '|';
      onlyPostLink.parentNode.insertBefore(separator, onlyPostLink.nextSibling);
      onlyPostLink.parentNode.insertBefore(viewMeLink, separator.nextSibling);
    }

    function addStyles() {
      const style = document.createElement('style');
      style.textContent = '.view-me-link{color:#369;text-decoration:none;margin:0 3px}.view-me-link:hover{text-decoration:underline;color:#f60}.authorid-input-dialog{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:white;padding:20px;border:2px solid #369;border-radius:5px;box-shadow:0 0 10px rgba(0,0,0,0.3);z-index:99999}.authorid-input-dialog input{width:200px;padding:5px;margin:10px 0}.authorid-input-dialog button{padding:5px 15px;margin:0 5px;cursor:pointer}';
      document.head.appendChild(style);
    }

    function handleViewMeClick(onlyPostLink) {
      const savedAuthorId = localStorage.getItem(STORAGE_KEY);
      if (!savedAuthorId) {
            const currentAuthorId = extractAuthorIdFromUrl(onlyPostLink.href);
            showAuthorIdInputDialog(currentAuthorId);
      } else {
            navigateToAuthorPosts(savedAuthorId, onlyPostLink);
      }
    }

    function extractAuthorIdFromUrl(url) {
      const match = url.match(/authorid=(\d+)/);
      return match ? match : null;
    }

    function showAuthorIdInputDialog(defaultAuthorId) {
      const dialog = document.createElement('div');
      dialog.className = 'authorid-input-dialog';
      dialog.innerHTML = '<p>首次使用,请输入您的UID:</p><input type="text" id="authorid-input" value="' + (defaultAuthorId || '') + '" placeholder="输入UID"><div><button id="save-authorid">保存并使用</button><button id="cancel-input">取消</button></div><p style="font-size:12px;color:#666;">空间链接内的数字即为uid,如“uid-679483”</p>';
      document.body.appendChild(dialog)
      const input = dialog.querySelector('#authorid-input');
      input.focus();
      input.select();
      dialog.querySelector('#save-authorid').addEventListener('click', function() {
            const authorId = input.value.trim();
            if (authorId && /^\d+$/.test(authorId)) {
                localStorage.setItem(STORAGE_KEY, authorId);
                document.body.removeChild(dialog);
                navigateToAuthorPosts(authorId, document.querySelector('a'));
            } else {
                alert('请输入有效的UID');
                input.focus();
                input.select();
            }
      });
      dialog.querySelector('#cancel-input').addEventListener('click', function() {
            document.body.removeChild(dialog);
      });
      input.addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                dialog.querySelector('#save-authorid').click();
            }
      });
      dialog.addEventListener('click', function(e) {
            if (e.target === dialog) {
                document.body.removeChild(dialog);
            }
      });
    }

    function navigateToAuthorPosts(authorId, onlyPostLink) {
      const baseUrl = onlyPostLink.href.replace(/authorid=\d+/, 'authorid=' + authorId);
      window.location.href = baseUrl;
    }

    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', init);
    } else {
      init();
    }

    document.addEventListener('keydown', function(e) {
      if (e.ctrlKey && e.shiftKey && e.key === 'C') {
            localStorage.removeItem(STORAGE_KEY);
            alert('已清除保存的UID');
      }
    });
})();

娱乐法师火布偶 发表于 2026-1-4 12:26:35

很实用的功能了,尤其是在回帖类的全局活动帖子中找自己的位置

Burry 发表于 2026-1-4 12:34:07

挺方便的功能,这样能快速找到自己那个贴。

莱多拉斯 发表于 2026-1-4 12:37:14

终于不用翻半天才能找到自己的回复,方便多了,已用{:6_200:}

凯诺斯 发表于 2026-1-4 12:39:02

只看本人还是很有用的惹,可以屏蔽掉别人的回复感觉功能更完善了

AlenL 发表于 2026-1-4 12:49:32

阿巴阿巴,感觉很实用,努力理解ing

reober3 发表于 2026-1-4 12:56:43

这下在各种需要编辑自己回帖的活动里就能挺快找到自己的楼噜
不过之前装了帖内检测有没有回帖的脚本,点它也能跳转自己楼~



                  

毛茸茸兽兽 发表于 2026-1-4 13:00:38

喔⊙ω⊙方便找到自己的楼层欸~咱之前都是记第几页的

crino66666 发表于 2026-1-4 13:03:26

回帖神奇脚本也有类似的功能呢

wdhgzdhcxb 发表于 2026-1-4 13:19:55

首次使用要自己输入uid吗?那我用无痕浏览岂不是每次用都要手动输入一次{:4_89:}

PURO_ 发表于 2026-1-4 13:26:09

这样活动贴可以精准找到自己的回复了,之前都是靠网页收藏找自己的回帖https://img.gamemale.com/album/202508/31/092111u1rzt6h6tzeezd11.jpg

x14443 发表于 2026-1-4 13:43:31

真的好有用 有次活动我忘了 在第几页要一页页找

被宽恕的色欲 发表于 2026-1-4 13:50:22

很实用的功能啊,这样在活动贴找自己的回复就容易多了

狂野哈士奇 发表于 2026-1-4 13:51:29

很有用,像上次钓鱼下注活动那个都要重新复制网址比较不方便,这个能很好解决

小晨风 发表于 2026-1-4 14:08:12

这个真的很实用呢,先收藏了,以后再参加活动可以试试~

Rg26 发表于 2026-1-4 14:56:19

这个好棒,活动的时候可以拿来找自己的帖子回復好方便

Styphon 发表于 2026-1-4 15:58:17

这个真的好适合活动找自己的帖子位置,以前都要特意记一下自己发的在哪一页评论

lyrt1996 发表于 2026-1-4 16:17:10

确实是很好用诶,找自己的回复会很方便

万俟 发表于 2026-1-4 16:44:58

感觉这个比较合适勋章投稿的帖子,别的可以用直接跳转

XLK 发表于 2026-1-4 16:50:46

这个脚本在活动贴还挺有用,经常找不到自己的楼层
页: [1] 2 3
查看完整版本: 【脚本】只看本人