MyFigureCollection Article Blocker

hide articles of specific users on the front page

当前为 2021-03-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MyFigureCollection Article Blocker
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  hide articles of specific users on the front page
// @author       IxianNavigator
// @match        https://myfigurecollection.net/
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  const blockedUsers = localStorage.blockedUsers ? JSON.parse(localStorage.blockedUsers) : [];

  Array.from(document.querySelectorAll('.stamp-anchor > a[href*="myfigurecollection.net/blog/"')).forEach((aElem) => {
    const url = aElem.getAttribute('href');
    if (!url.match(/myfigurecollection\.net\/blog\/\d+$/)) {
      return;
    }
    const blogPostListItem = aElem.closest("li.listing-item");
    if (!blogPostListItem) {
      return;
    }

    fetch(url).then((response) => response.text()).then((responseText) => {
      const regex = /<a class="anchor user\-anchor user-access-rank-(\d+) user-honorific-rank-(\d+)" href="https:\/\/myfigurecollection\.net\/profile\/(\S+)">/;
      const match = responseText.match(regex);
      if (!match) {
        console.log('no-match', url);
        return;
      }
      const userName = match[3];
      console.log('match', userName);
      if (blockedUsers.includes(userName)) {
        blogPostListItem.setAttribute("style", "display: none;");
        return;
      }
      const userSpan = document.createElement('span');
      userSpan.innerHTML = userName;
      const blockButton = document.createElement('span');
      blockButton.innerHTML = "×";
      blockButton.setAttribute("title", "block user");
      blockButton.setAttribute("role", "button");
      blockButton.setAttribute("style", "cursor: pointer;");
      blockButton.classList.add("block-user-button");
      blockButton.addEventListener("click", function() {
        blockedUsers.push(userName);
        localStorage.blockedUsers = JSON.stringify(blockedUsers);
        blogPostListItem.setAttribute("style", "display: none;");
        addBlockedUsersList();
      });
      const metaContainer = blogPostListItem.querySelector(".stamp-meta");
      metaContainer.appendChild(document.createTextNode(" • "));
      metaContainer.appendChild(userSpan);
      metaContainer.appendChild(document.createTextNode(" • "));
      metaContainer.appendChild(blockButton);
    });
  });
  function addBlockedUsersList() {
    const existingBlockedUsersList = document.querySelector(".blocked-users-list");
    if (existingBlockedUsersList) {
      existingBlockedUsersList.remove();
    }
    const blockedUsersList = document.createElement("div");
    blockedUsersList.classList.add("blocked-users-list");
    document.querySelector(".copyright").after(blockedUsersList);
    blockedUsers.forEach((userName, i) => {
      const userSpan = document.createElement("span");
      userSpan.setAttribute("role", "button");
      userSpan.setAttribute("style", "cursor: pointer;");
      userSpan.innerHTML = userName;
      userSpan.addEventListener("click", function() {
        const index = blockedUsers.indexOf(userName);
        if (index > -1) {
          blockedUsers.splice(index, 1);
        }
        localStorage.blockedUsers = JSON.stringify(blockedUsers);
        addBlockedUsersList();
      });
      blockedUsersList.appendChild(userSpan);
      if (i < blockedUsers.length - 1) {
        blockedUsersList.appendChild(document.createTextNode(" • "));
      }
    });
  }
  addBlockedUsersList();

})();