hide articles of specific users on the front page
目前為
// ==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;
}
aElem
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;");
});
const metaContainer = blogPostListItem.querySelector(".stamp-meta");
metaContainer.appendChild(document.createTextNode(" • "));
metaContainer.appendChild(userSpan);
metaContainer.appendChild(document.createTextNode(" • "));
metaContainer.appendChild(blockButton);
});
});
})();