(转载)【工具】—屏蔽烦你的id和版面文章的脚本

版主: huangchong

头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 3998
帖子: 60159
注册时间: 2022年 7月 22日 01:22

#1 (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 huangchong(净坛使者)楼主 »

此帖转自 牛河梁 在 加州华人 的帖子:【工具】—屏蔽烦你的id和版面文章的脚本

修改了一下黄版的屏蔽脚本。能够屏蔽包括id被推荐文章十大文章等。也能屏蔽烦你的版面的文章。

具体而言,要在首页屏蔽哪一个版面的文章只需手动编辑“黑名单”把版面名像id一样加入黑名单即可。

举例说,要屏蔽“加州华人”版,将“加州华人”这个名字(不带双引号)加入“黑名单”。注意,需要全名。如果版名有()注释,则这部分也要加上。

同理,要屏蔽“牛河梁”这个id的所有帖子,包括首页的帖子链接,将“牛河梁”这个名字(不带双引号)加入“黑名单”即可。

插件安装指南请见:viewtopic.php?t=9560

修改的代码如下:

代码: 全选

      // ==UserScript==
      // @name         NewMitbbs-bot-blocker
      // @namespace    http://tampermonkey.net/
      // @version      0.2
      // @description  Manages and blocks bot generated content. Shamelessly modified from chunjuan's script at https://greasyfork.org/en/scripts/29195-mitbbs-bot-blocker/code, which was inspired by Smalltalk80's original GM script, http://userscripts-mirror.org/scripts/review/78633
      // @author       Sagittarius A*,modified by 牛河梁
      // @match        http://newmitbbs.com/*
      // @match        https://newmitbbs.com/*
      // @grant        GM_addStyle
      // @run-at       document-idle
      // ==/UserScript==
      // debugger;
      (function() {
        'use strict';

        var storageKey = 'new.mitbbs.blocklist';

        function getBlocklist() {
          var blockList = localStorage.getItem(storageKey);
          if (blockList === null) {
            setBlocklist([]);
            blockList = localStorage.getItem(storageKey);
          }

          try {
            blockList = JSON.parse(blockList);
          } catch (error) {
            blockList = [];
            setBlocklist(blockList);
          }

          blockList = Array.isArray(blockList) ? blockList : [];
          return blockList;
        }

        function setBlocklist(idNameList) {
          // remove duplicate items
          // todo: babel output for this one doesn't really work, have to revert back to old fashion way
          // idNameList = [...new Set(idNameList)]
          var uniqueidNameList = idNameList.filter(function (elem, index, self) {
            return index === self.indexOf(elem);
          });
          uniqueidNameList = uniqueidNameList.sort(function (a, b) {
            // defer from localeCompare for better browser support
            if (a.toLowerCase() < b.toLowerCase()) return -1;
            if (a.toLowerCase() > b.toLowerCase()) return 1;
            return 0;
          });
          localStorage.setItem(storageKey, JSON.stringify(uniqueidNameList));
          document.getElementById('blockListInput').value = uniqueidNameList;
        }

        function getBlockFlag() {
          var blockFlag = localStorage.getItem(storageKey + '.flag');
          if (blockFlag === null) {
            setBlockFlag(0);
            blockFlag = localStorage.getItem(storageKey + '.flag');
          }
          //  js, just being js
          return parseInt(blockFlag);
        }

        function setBlockFlag(flag) {
          localStorage.setItem(storageKey + '.flag', flag);
        }

        function changeRowVisibility() {
            var blockList = getBlocklist();
            var flag = getBlockFlag();
            var counter = 0;
            if (blockList) {
                document.querySelectorAll('li.row').forEach(r => {
                    r.style.display = '';
                    if (flag) {
                        if (blockList.indexOf(r.querySelector('span.username')?.textContent) > -1 ||
                            blockList.indexOf(r.querySelector('div.responsive-show')?.querySelector('a')?.textContent) > -1) {
                            r.style.display = 'none';
                            counter += 1;
                        }
                    }
                });
            }
            counter = flag ? counter : 0;
            document.getElementById('blockCounter').innerHTML = counter;
        }

        function changePostVisibility() {
          var blockList = getBlocklist();
          var flag = getBlockFlag();
          var counter = 0;
          // if list is not empty
          if (blockList) {
            // yeah yeah yeah magic number, whatever
            // this will miss the first one though, nice try langfang coder
            document.querySelector('div.forumbg:not(.announcement)')
                    .querySelectorAll('li.row')
                    .forEach(function (td) {
              // damn, now i miss jquery/zepto
              var id = td.querySelector('div.responsive-show').querySelector('span.username').textContent;
              //  reset all reply to visible. This is a hack-ish method to fix content not being displayed after userID has been removed from blocklist.
              //  TODO: maybe in the near future, we should keep a local copy of blocklist so that we can compare the changes and show/hide content intelligently, maybe
              td.style.display = '';
              //  yeah, nested if statements
              if (blockList.indexOf(id) > -1) {
                if (flag) {
                  td.style.display = 'none';
                  counter += 1;
                } else {
                  td.style.display = '';
                }
              }
            });
            counter = flag ? counter : 0;
            document.getElementById('blockCounter').innerHTML = counter;
          }
        }

        function changeReplyVisibility() {
          //  now we on individual post page
          var blockList = getBlocklist();
          var flag = getBlockFlag();
          var counter = 0;
          var sideBarBG = document.querySelectorAll('div.post.has-profile');
          sideBarBG.forEach(function (reply) {
            // var post = reply.parentElement.parentElement.parentElement.parentElement.parentElement;
            var userID = reply.querySelector('span.username').textContent;
            //  another magic number!
            var userMenu = reply.querySelector('strong');
            var hasButton = userMenu.querySelector('span.button') !== null;
            if (!hasButton) {
              var blockButton = document.createElement('span');
              blockButton.setAttribute('class', 'button');
              blockButton.innerHTML = '&nbsp;&nbsp;<button class="addToBlock" title="' + userID + '">屏蔽!</button>';
              userMenu.appendChild(blockButton);
            }
            if(!flag) userMenu.querySelector('span.button').style.display = 'none';
            else userMenu.querySelector('span.button').style.display = '';
            //  reset all reply to visible. This is a hack-ish method to fix content not being displayed after userID has been removed from blocklist.
            //  TODO: maybe in the near future, we should keep a local copy of blocklist so that we can compare the changes and show/hide content intelligently, maybe
            reply.style.display = '';
            if (blockList.indexOf(userID) > -1) {
              if (flag) {
                reply.style.display = 'none';
                counter += 1;
              } else {
                reply.style.display = '';
              }
            }
            counter = flag ? counter : 0;
            document.getElementById('blockCounter').innerHTML = counter;
          });

          var allBlockButton = document.querySelectorAll('.addToBlock');
          Array.from(allBlockButton).forEach(function (button) {
            var userID = button.getAttribute('title');
            button.addEventListener('click', function () {
              var yesBlock = confirm('Block ' + userID + ' ?');
              if (yesBlock) {
                blockList.push(userID);
                setBlocklist(blockList);
                document.getElementById('blockListInput').value = getBlocklist().join();
                // toggleBlockedContent();
                // copy & paste from above code to refresh the page with newly added id
                sideBarBG.forEach(function (reply) {
                  // var post = reply.parentElement.parentElement.parentElement.parentElement.parentElement;
                  var userID = reply.querySelector('span.username').textContent;
                  //  another magic number!
                  var userMenu = reply.querySelector('strong');
                  var hasButton = userMenu.querySelector('span.button') !== null;
                  if (!hasButton) {
                    var blockButton = document.createElement('span');
                    blockButton.setAttribute('class', 'button');
                    blockButton.innerHTML = '&nbsp;&nbsp;<button class="addToBlock" title="' + userID + '">屏蔽!</button>';
                    userMenu.appendChild(blockButton);
                  }
                  if(!flag) userMenu.querySelector('span.button').style.display = 'none';
                  else userMenu.querySelector('span.button').style.display = '';
                  //  reset all reply to visible. This is a hack-ish method to fix content not being displayed after userID has been removed from blocklist.
                  //  TODO: maybe in the near future, we should keep a local copy of blocklist so that we can compare the changes and show/hide content intelligently, maybe
                  reply.style.display = '';
                  if (blockList.indexOf(userID) > -1) {
                    if (flag) {
                      reply.style.display = 'none';
                      counter += 1;
                    } else {
                      reply.style.display = '';
                    }
                  }
                  counter = flag ? counter : 0;
                  document.getElementById('blockCounter').innerHTML = counter;
                });
              }
            });
          });
        }

        function toggleBlockedContent() {
          document.getElementById('isBlocking').checked ? setBlockFlag(1) : setBlockFlag(0);
          changeRowVisibility();
          var pageType = locationGuesser();
          switch (pageType) {
            case 1:
              changeReplyVisibility();
              break;
            case -1:
//              changePostVisibility();
              changeRowVisibility();
              break;
            case 0:
              changeRowVisibility();
              break;
          }
        }

        function locationGuesser() {
          var pageType = void 0;
          var url = window.location.href;
          if (url.indexOf('viewtopic') > -1) {
            pageType = 1;
          } else if (url.indexOf('viewforum') > -1) {
            pageType = -1;
          } else {
            pageType = 0;
          }

          return pageType;
        }

        // callback for when clicking 黑名单 button
        function changeBlockListVisibility() {
          var notVisible = document.getElementById('blockListPop').style.display === 'none';
          if (notVisible) {
            // show block list pop up
            document.getElementById('blockListInput').value = getBlocklist().join();
            document.getElementById('blockListPop').style.display = '';
          } else {
            // close block list pop up
            document.getElementById('blockListPop').style.display = 'none';
            // update blocklist when closing the pop up
            updateBlockList();
          }
        }

        function updateBlockList() {
          var newBlockList = document.getElementById('blockListInput').value;
          //  remove line break, space, trailing comma
          newBlockList = newBlockList.replace(/(\r\n|\n|\r)/gm, '').replace(/\s/g, '').replace(/,+$/, '');
          newBlockList = newBlockList.split(',');
          setBlocklist(newBlockList);

          // re-filter existing content
          toggleBlockedContent();
        }

        function hideBlockList() {
          document.getElementById('blockListPop').style.display = 'none';
        }

        function prepPage() {
          var flag = getBlockFlag();
          getBlocklist();
          if (flag) {
            document.getElementById('isBlocking').checked = true;
            toggleBlockedContent();
          }
        }

        function pageOnLoad() {
          //  build blocker control gui
          var blockerDiv = document.createElement('div');
          blockerDiv.innerHTML = '<button id="showBlocklist" class="button">黑名单</button><input type="checkbox" id="isBlocking" /><span id="blockCounter" title="Currently Blocked"></span>';
          blockerDiv.style.cssText = 'position:fixed; bottom:2em; right:0.5em; width:9em; padding:0.5em; border-radius:0.25em; background-color:#D7EAF9; box-shadow:2px 2px 4px 0px rgba(0,0,0,0.5); text-align:center; cursor:pointer;';
          document.body.appendChild(blockerDiv);

          document.getElementById('showBlocklist').addEventListener('click', changeBlockListVisibility);
          document.getElementById('blockCounter').style.cssText = 'padding:0 4px; font-weight:bold';
          document.getElementById('isBlocking').addEventListener('change', toggleBlockedContent);

          //  block list
          var blockListDiv = document.createElement('div');
          blockListDiv.setAttribute('id', 'blockListPop');
          blockListDiv.innerHTML = '<span>修改ID,用逗号分隔,大小写敏感!</span>' + '<br/>' + '<textarea rows="10" cols="40" id="blockListInput" style="background-color:orange;color:black;font-size:10pt;"></textarea>' + '<br/>' + '<button id="updateBlockList">Update</button><span style="width:2em"></span><button id="closePop">Close</button>';
          blockListDiv.style.cssText = 'position:fixed; bottom:5.3em; right:0.5em; padding:0.5em; border-radius:0.25em; background-color:#D7EAF9; box-shadow:2px 2px 4px 0px rgba(0,0,0,0.5); text-align:center; display:none';
          document.body.appendChild(blockListDiv);
          document.getElementById('updateBlockList').addEventListener('click', updateBlockList);
          document.getElementById('closePop').addEventListener('click', hideBlockList);

          prepPage();
        }

        function ready(fn) {
          if (document.readyState !== 'loading') {
            fn();
          } else {
            document.addEventListener('DOMContentLoaded', fn);
          }
        }

        ready(pageOnLoad);
        })();
头像
ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI)
已冻结已冻结
帖子互动: 127
帖子: 1352
注册时间: 2024年 9月 27日 23:57

#2 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI) »

图片

为什么要重新造一遍轮子?
¡qooq ƃᴉq ɐ ǝɹɐ no⅄
头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 3998
帖子: 60159
注册时间: 2022年 7月 22日 01:22

#3 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 huangchong(净坛使者)楼主 »

ɓuoɥɔɓuɐnɥ 写了: 2025年 3月 25日 10:01 图片

为什么要重新造一遍轮子?
这种情况 是不是 人家把你fork了?
头像
mmking(上水)
论坛支柱
论坛支柱
帖子互动: 1469
帖子: 10826
注册时间: 2023年 1月 25日 05:10

#4 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 mmking(上水) »

@wh 你看,这种对美心的封禁结果,就是大家的情绪无处发泄,最后是整个论坛完蛋。

川宝的行为导致的现实生活的turmoil不是班规就可以抚平的
ɓuoɥɔɓuɐnɥ 写了: 2025年 3月 25日 10:01 图片

为什么要重新造一遍轮子?

如果你家被人烧杀抢掠了,你把这个故事告诉你子孙就是仇恨教育,那么跟随施暴者一起贴这个标签的xx和施暴者一样可恶

凡所有相,皆是虚妄

viewtopic.php?t=864957

图片

头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 3998
帖子: 60159
注册时间: 2022年 7月 22日 01:22

#5 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 huangchong(净坛使者)楼主 »

mmking 写了: 2025年 3月 25日 10:07 @wh 你看,这种对美心的封禁结果,就是大家的情绪无处发泄,最后是整个论坛完蛋。

川宝的行为导致的现实生活的turmoil不是班规就可以抚平的
啥 美心又出事了?
图片
x1 图片
上次由 huangchong 在 2025年 3月 25日 10:10 修改。
原因: 未提供修改原因
头像
ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI)
已冻结已冻结
帖子互动: 127
帖子: 1352
注册时间: 2024年 9月 27日 23:57

#6 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI) »

mmking 写了: 2025年 3月 25日 10:07 @wh 你看,这种对美心的封禁结果,就是大家的情绪无处发泄,最后是整个论坛完蛋。

川宝的行为导致的现实生活的turmoil不是班规就可以抚平的
都能纵容拿钱发帖的搅屎棍

我们自带干粮还不能自行清理下版面啊

又没有篡改服务器端数据
¡qooq ƃᴉq ɐ ǝɹɐ no⅄
头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 3998
帖子: 60159
注册时间: 2022年 7月 22日 01:22

#7 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 huangchong(净坛使者)楼主 »

ɓuoɥɔɓuɐnɥ 写了: 2025年 3月 25日 10:10 都能纵容拿钱发帖的搅屎棍

我们自带干粮还不能自行清理下版面啊

又没有篡改服务器端数据
他是跟wh喊话呢
头像
ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI)
已冻结已冻结
帖子互动: 127
帖子: 1352
注册时间: 2024年 9月 27日 23:57

#8 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI) »

huangchong 写了: 2025年 3月 25日 10:11 他是跟wh喊话呢
🤐
¡qooq ƃᴉq ɐ ǝɹɐ no⅄
头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 3998
帖子: 60159
注册时间: 2022年 7月 22日 01:22

#9 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 huangchong(净坛使者)楼主 »

ɓuoɥɔɓuɐnɥ 写了: 2025年 3月 25日 10:12 🤐
回到正题:你觉得被fork是快乐的事情吗?
头像
YouHi
论坛元老
论坛元老
YouHi 的博客
帖子互动: 2823
帖子: 37619
注册时间: 2022年 7月 22日 22:36

#10 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 YouHi »

ɓuoɥɔɓuɐnɥ 写了: 2025年 3月 25日 10:01 图片

为什么要重新造一遍轮子?
不明觉厉
著名网友名单
🇺🇸 NC CHINESE AMERICANS FOR TRUMP 🛩️
你也是Trump U毕业的吗???
头像
ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI)
已冻结已冻结
帖子互动: 127
帖子: 1352
注册时间: 2024年 9月 27日 23:57

#11 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI) »

huangchong 写了: 2025年 3月 25日 10:14 回到正题:你觉得被fork是快乐的事情吗?
无所谓,本来也是chunjuan老师那里直接整来改吧改吧的
¡qooq ƃᴉq ɐ ǝɹɐ no⅄
头像
ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI)
已冻结已冻结
帖子互动: 127
帖子: 1352
注册时间: 2024年 9月 27日 23:57

#12 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI) »

YouHi 写了: 2025年 3月 25日 10:18不明觉厉
就是原插件,在首页就会显示这个选项
¡qooq ƃᴉq ɐ ǝɹɐ no⅄
头像
YouHi
论坛元老
论坛元老
YouHi 的博客
帖子互动: 2823
帖子: 37619
注册时间: 2022年 7月 22日 22:36

#13 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 YouHi »

huangchong 写了: 2025年 3月 25日 10:04 这种情况 是不是 人家把你fork了?
fork是灵感的起源
著名网友名单
🇺🇸 NC CHINESE AMERICANS FOR TRUMP 🛩️
你也是Trump U毕业的吗???
头像
牛河梁(别问我是谁)
论坛元老
论坛元老
2023年度十大优秀网友
2024年度优秀版主
牛河梁 的博客
帖子互动: 1702
帖子: 29318
注册时间: 2022年 11月 17日 21:21
联系:

#14 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 牛河梁(别问我是谁) »

ɓuoɥɔɓuɐnɥ 写了: 2025年 3月 25日 10:19 就是原插件,在首页就会显示这个选项
在哪里?没见到。老牛用/改错版本了?
头像
ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI)
已冻结已冻结
帖子互动: 127
帖子: 1352
注册时间: 2024年 9月 27日 23:57

#15 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI) »

牛河梁 写了: 2025年 3月 25日 10:46 在哪里?没见到。老牛用/改错版本了?
挂在原帖的code就是最新的

“只在首页才会显示这个选项”
¡qooq ƃᴉq ɐ ǝɹɐ no⅄
头像
牛河梁(别问我是谁)
论坛元老
论坛元老
2023年度十大优秀网友
2024年度优秀版主
牛河梁 的博客
帖子互动: 1702
帖子: 29318
注册时间: 2022年 11月 17日 21:21
联系:

#16 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 牛河梁(别问我是谁) »

ɓuoɥɔɓuɐnɥ 写了: 2025年 3月 25日 10:53 挂在原帖的code就是最新的

“只在首页才会显示这个选项”
哦。试用了一下。和老牛的版本/思路完全不同。

1/ 老牛版不屏蔽板块入口。因为站方已经把板块入口可以折叠。有兴趣的可以自行去打开寻找版面或者自己可以收藏版面进入。所以没必要重新发明轮子。

2/ 老牛版屏蔽的是ID和指定版面上首页的文章(标题/链接/入口)。包括“最新帖子”,“今日十大热门话题”,“版主推荐主题”以及将来首页可能有的新板块里的文章链接。解决了有网友投诉首页不干净问题。这个功能开发的时候还没有“版主推荐主题”。“版主推荐主题”出来的时候很好地兼容自动覆盖了。

如果大家有兴趣。老牛考虑增加关键词过滤。举例说,可以把标题里含有指定关键字,如“逼”、“完了”等等,的文章从首页屏蔽掉。
上次由 牛河梁 在 2025年 3月 25日 11:43 修改。
Strong
职业作家
职业作家
帖子互动: 41
帖子: 528
注册时间: 2022年 10月 16日 15:17

#17 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 Strong »

huangchong 写了: 2025年 3月 25日 02:20 此帖转自 牛河梁 在 加州华人 的帖子:【工具】—屏蔽烦你的id和版面文章的脚本

修改了一下黄版的屏蔽脚本。能够屏蔽包括id被推荐文章十大文章等。也能屏蔽烦你的版面的文章。

具体而言,要在首页屏蔽哪一个版面的文章只需手动编辑“黑名单”把版面名像id一样加入黑名单即可。

举例说,要屏蔽“加州华人”版,将“加州华人”这个名字(不带双引号)加入“黑名单”。注意,需要全名。如果版名有()注释,则这部分也要加上。

同理,要屏蔽“牛河梁”这个id的所有帖子,包括首页的帖子链接,将“牛河梁”这个名字(不带双引号)加入“黑名单”即可。

插件安装指南请见:viewtopic.php?t=9560

修改的代码如下:

代码: 全选

      // ==UserScript==
      // @name         NewMitbbs-bot-blocker
      // @namespace    http://tampermonkey.net/
      // @version      0.2
      // @description  Manages and blocks bot generated content. Shamelessly modified from chunjuan's script at https://greasyfork.org/en/scripts/29195-mitbbs-bot-blocker/code, which was inspired by Smalltalk80's original GM script, http://userscripts-mirror.org/scripts/review/78633
      // @author       Sagittarius A*,modified by 牛河梁
      // @match        http://newmitbbs.com/*
      // @match        https://newmitbbs.com/*
      // @grant        GM_addStyle
      // @run-at       document-idle
      // ==/UserScript==
      // debugger;
      (function() {
        'use strict';

        var storageKey = 'new.mitbbs.blocklist';

        function getBlocklist() {
          var blockList = localStorage.getItem(storageKey);
          if (blockList === null) {
            setBlocklist([]);
            blockList = localStorage.getItem(storageKey);
          }

          try {
            blockList = JSON.parse(blockList);
          } catch (error) {
            blockList = [];
            setBlocklist(blockList);
          }

          blockList = Array.isArray(blockList) ? blockList : [];
          return blockList;
        }

        function setBlocklist(idNameList) {
          // remove duplicate items
          // todo: babel output for this one doesn't really work, have to revert back to old fashion way
          // idNameList = [...new Set(idNameList)]
          var uniqueidNameList = idNameList.filter(function (elem, index, self) {
            return index === self.indexOf(elem);
          });
          uniqueidNameList = uniqueidNameList.sort(function (a, b) {
            // defer from localeCompare for better browser support
            if (a.toLowerCase() < b.toLowerCase()) return -1;
            if (a.toLowerCase() > b.toLowerCase()) return 1;
            return 0;
          });
          localStorage.setItem(storageKey, JSON.stringify(uniqueidNameList));
          document.getElementById('blockListInput').value = uniqueidNameList;
        }

        function getBlockFlag() {
          var blockFlag = localStorage.getItem(storageKey + '.flag');
          if (blockFlag === null) {
            setBlockFlag(0);
            blockFlag = localStorage.getItem(storageKey + '.flag');
          }
          //  js, just being js
          return parseInt(blockFlag);
        }

        function setBlockFlag(flag) {
          localStorage.setItem(storageKey + '.flag', flag);
        }

        function changeRowVisibility() {
            var blockList = getBlocklist();
            var flag = getBlockFlag();
            var counter = 0;
            if (blockList) {
                document.querySelectorAll('li.row').forEach(r => {
                    r.style.display = '';
                    if (flag) {
                        if (blockList.indexOf(r.querySelector('span.username')?.textContent) > -1 ||
                            blockList.indexOf(r.querySelector('div.responsive-show')?.querySelector('a')?.textContent) > -1) {
                            r.style.display = 'none';
                            counter += 1;
                        }
                    }
                });
            }
            counter = flag ? counter : 0;
            document.getElementById('blockCounter').innerHTML = counter;
        }

        function changePostVisibility() {
          var blockList = getBlocklist();
          var flag = getBlockFlag();
          var counter = 0;
          // if list is not empty
          if (blockList) {
            // yeah yeah yeah magic number, whatever
            // this will miss the first one though, nice try langfang coder
            document.querySelector('div.forumbg:not(.announcement)')
                    .querySelectorAll('li.row')
                    .forEach(function (td) {
              // damn, now i miss jquery/zepto
              var id = td.querySelector('div.responsive-show').querySelector('span.username').textContent;
              //  reset all reply to visible. This is a hack-ish method to fix content not being displayed after userID has been removed from blocklist.
              //  TODO: maybe in the near future, we should keep a local copy of blocklist so that we can compare the changes and show/hide content intelligently, maybe
              td.style.display = '';
              //  yeah, nested if statements
              if (blockList.indexOf(id) > -1) {
                if (flag) {
                  td.style.display = 'none';
                  counter += 1;
                } else {
                  td.style.display = '';
                }
              }
            });
            counter = flag ? counter : 0;
            document.getElementById('blockCounter').innerHTML = counter;
          }
        }

        function changeReplyVisibility() {
          //  now we on individual post page
          var blockList = getBlocklist();
          var flag = getBlockFlag();
          var counter = 0;
          var sideBarBG = document.querySelectorAll('div.post.has-profile');
          sideBarBG.forEach(function (reply) {
            // var post = reply.parentElement.parentElement.parentElement.parentElement.parentElement;
            var userID = reply.querySelector('span.username').textContent;
            //  another magic number!
            var userMenu = reply.querySelector('strong');
            var hasButton = userMenu.querySelector('span.button') !== null;
            if (!hasButton) {
              var blockButton = document.createElement('span');
              blockButton.setAttribute('class', 'button');
              blockButton.innerHTML = '&nbsp;&nbsp;<button class="addToBlock" title="' + userID + '">屏蔽!</button>';
              userMenu.appendChild(blockButton);
            }
            if(!flag) userMenu.querySelector('span.button').style.display = 'none';
            else userMenu.querySelector('span.button').style.display = '';
            //  reset all reply to visible. This is a hack-ish method to fix content not being displayed after userID has been removed from blocklist.
            //  TODO: maybe in the near future, we should keep a local copy of blocklist so that we can compare the changes and show/hide content intelligently, maybe
            reply.style.display = '';
            if (blockList.indexOf(userID) > -1) {
              if (flag) {
                reply.style.display = 'none';
                counter += 1;
              } else {
                reply.style.display = '';
              }
            }
            counter = flag ? counter : 0;
            document.getElementById('blockCounter').innerHTML = counter;
          });

          var allBlockButton = document.querySelectorAll('.addToBlock');
          Array.from(allBlockButton).forEach(function (button) {
            var userID = button.getAttribute('title');
            button.addEventListener('click', function () {
              var yesBlock = confirm('Block ' + userID + ' ?');
              if (yesBlock) {
                blockList.push(userID);
                setBlocklist(blockList);
                document.getElementById('blockListInput').value = getBlocklist().join();
                // toggleBlockedContent();
                // copy & paste from above code to refresh the page with newly added id
                sideBarBG.forEach(function (reply) {
                  // var post = reply.parentElement.parentElement.parentElement.parentElement.parentElement;
                  var userID = reply.querySelector('span.username').textContent;
                  //  another magic number!
                  var userMenu = reply.querySelector('strong');
                  var hasButton = userMenu.querySelector('span.button') !== null;
                  if (!hasButton) {
                    var blockButton = document.createElement('span');
                    blockButton.setAttribute('class', 'button');
                    blockButton.innerHTML = '&nbsp;&nbsp;<button class="addToBlock" title="' + userID + '">屏蔽!</button>';
                    userMenu.appendChild(blockButton);
                  }
                  if(!flag) userMenu.querySelector('span.button').style.display = 'none';
                  else userMenu.querySelector('span.button').style.display = '';
                  //  reset all reply to visible. This is a hack-ish method to fix content not being displayed after userID has been removed from blocklist.
                  //  TODO: maybe in the near future, we should keep a local copy of blocklist so that we can compare the changes and show/hide content intelligently, maybe
                  reply.style.display = '';
                  if (blockList.indexOf(userID) > -1) {
                    if (flag) {
                      reply.style.display = 'none';
                      counter += 1;
                    } else {
                      reply.style.display = '';
                    }
                  }
                  counter = flag ? counter : 0;
                  document.getElementById('blockCounter').innerHTML = counter;
                });
              }
            });
          });
        }

        function toggleBlockedContent() {
          document.getElementById('isBlocking').checked ? setBlockFlag(1) : setBlockFlag(0);
          changeRowVisibility();
          var pageType = locationGuesser();
          switch (pageType) {
            case 1:
              changeReplyVisibility();
              break;
            case -1:
//              changePostVisibility();
              changeRowVisibility();
              break;
            case 0:
              changeRowVisibility();
              break;
          }
        }

        function locationGuesser() {
          var pageType = void 0;
          var url = window.location.href;
          if (url.indexOf('viewtopic') > -1) {
            pageType = 1;
          } else if (url.indexOf('viewforum') > -1) {
            pageType = -1;
          } else {
            pageType = 0;
          }

          return pageType;
        }

        // callback for when clicking 黑名单 button
        function changeBlockListVisibility() {
          var notVisible = document.getElementById('blockListPop').style.display === 'none';
          if (notVisible) {
            // show block list pop up
            document.getElementById('blockListInput').value = getBlocklist().join();
            document.getElementById('blockListPop').style.display = '';
          } else {
            // close block list pop up
            document.getElementById('blockListPop').style.display = 'none';
            // update blocklist when closing the pop up
            updateBlockList();
          }
        }

        function updateBlockList() {
          var newBlockList = document.getElementById('blockListInput').value;
          //  remove line break, space, trailing comma
          newBlockList = newBlockList.replace(/(\r\n|\n|\r)/gm, '').replace(/\s/g, '').replace(/,+$/, '');
          newBlockList = newBlockList.split(',');
          setBlocklist(newBlockList);

          // re-filter existing content
          toggleBlockedContent();
        }

        function hideBlockList() {
          document.getElementById('blockListPop').style.display = 'none';
        }

        function prepPage() {
          var flag = getBlockFlag();
          getBlocklist();
          if (flag) {
            document.getElementById('isBlocking').checked = true;
            toggleBlockedContent();
          }
        }

        function pageOnLoad() {
          //  build blocker control gui
          var blockerDiv = document.createElement('div');
          blockerDiv.innerHTML = '<button id="showBlocklist" class="button">黑名单</button><input type="checkbox" id="isBlocking" /><span id="blockCounter" title="Currently Blocked"></span>';
          blockerDiv.style.cssText = 'position:fixed; bottom:2em; right:0.5em; width:9em; padding:0.5em; border-radius:0.25em; background-color:#D7EAF9; box-shadow:2px 2px 4px 0px rgba(0,0,0,0.5); text-align:center; cursor:pointer;';
          document.body.appendChild(blockerDiv);

          document.getElementById('showBlocklist').addEventListener('click', changeBlockListVisibility);
          document.getElementById('blockCounter').style.cssText = 'padding:0 4px; font-weight:bold';
          document.getElementById('isBlocking').addEventListener('change', toggleBlockedContent);

          //  block list
          var blockListDiv = document.createElement('div');
          blockListDiv.setAttribute('id', 'blockListPop');
          blockListDiv.innerHTML = '<span>修改ID,用逗号分隔,大小写敏感!</span>' + '<br/>' + '<textarea rows="10" cols="40" id="blockListInput" style="background-color:orange;color:black;font-size:10pt;"></textarea>' + '<br/>' + '<button id="updateBlockList">Update</button><span style="width:2em"></span><button id="closePop">Close</button>';
          blockListDiv.style.cssText = 'position:fixed; bottom:5.3em; right:0.5em; padding:0.5em; border-radius:0.25em; background-color:#D7EAF9; box-shadow:2px 2px 4px 0px rgba(0,0,0,0.5); text-align:center; display:none';
          document.body.appendChild(blockListDiv);
          document.getElementById('updateBlockList').addEventListener('click', updateBlockList);
          document.getElementById('closePop').addEventListener('click', hideBlockList);

          prepPage();
        }

        function ready(fn) {
          if (document.readyState !== 'loading') {
            fn();
          } else {
            document.addEventListener('DOMContentLoaded', fn);
          }
        }

        ready(pageOnLoad);
        })();
弄一个可以屏蔽广告的吧。
版面广告太烦人了
头像
ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI)
已冻结已冻结
帖子互动: 127
帖子: 1352
注册时间: 2024年 9月 27日 23:57

#18 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI) »

Strong 写了: 2025年 3月 25日 11:38 弄一个可以屏蔽广告的吧。
版面广告太烦人了
我一直在说,没有adblock上网等于裸体上网

整一个ublock,世界都清静了
¡qooq ƃᴉq ɐ ǝɹɐ no⅄
头像
YouHi
论坛元老
论坛元老
YouHi 的博客
帖子互动: 2823
帖子: 37619
注册时间: 2022年 7月 22日 22:36

#19 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 YouHi »

ɓuoɥɔɓuɐnɥ 写了: 2025年 3月 25日 11:42 我一直在说,没有adblock上网等于裸体上网

整一个ublock,世界都清静了
我大吃一斤。我还以为所有人都用AdBlock呢。
著名网友名单
🇺🇸 NC CHINESE AMERICANS FOR TRUMP 🛩️
你也是Trump U毕业的吗???
头像
ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI)
已冻结已冻结
帖子互动: 127
帖子: 1352
注册时间: 2024年 9月 27日 23:57

#20 Re: (转载)【工具】—屏蔽烦你的id和版面文章的脚本

帖子 ɓuoɥɔɓuɐnɥ(poɓᴉuɯO pǝʇɹǝʌuI) »

YouHi 写了: 2025年 3月 25日 11:44 我大吃一斤。我还以为所有人都用AdBlock呢。
据我观察有不少原教旨主义上网的
¡qooq ƃᴉq ɐ ǝɹɐ no⅄
回复

回到 “肚皮舞运动(Joke)”