Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name FOK!Rust
- // @namespace https://forum.fok.nl/
- // @version 1.3.1
- // @description Verbergt MikeyTT-reacties en quotes op FOK!.
- // @match *://forum.fok.nl/*
- // @run-at document-end
- // @noframes
- // @grant none
- // ==/UserScript==
- (function () {
- "use strict";
- var BLOCKED_USER = "mikeytt";
- var HIDDEN_ATTRIBUTE = "data-fok-rust-hidden";
- var POST_SELECTOR = ".post[data-member], .post [data-member][data-postid]";
- var observer = null;
- function normalizeUserName(value) {
- return String(value || "").replace(/^\s+|\s+$/g, "").toLowerCase();
- }
- function isBlockedName(value) {
- return normalizeUserName(value) === BLOCKED_USER;
- }
- function matchesSelector(element, selector) {
- var matches = element.matches
- || element.msMatchesSelector
- || element.webkitMatchesSelector;
- return matches ? matches.call(element, selector) : false;
- }
- function closestByClass(element, className) {
- while (element && element.nodeType === 1) {
- if ((" " + element.className + " ").indexOf(" " + className + " ") !== -1) {
- return element;
- }
- element = element.parentNode;
- }
- return null;
- }
- function getPostElement(element) {
- if ((" " + element.className + " ").indexOf(" post ") !== -1) {
- return element;
- }
- return closestByClass(element, "post");
- }
- function getMemberName(post) {
- var nested = post.querySelector("[data-member][data-postid]");
- return post.getAttribute("data-member")
- || (nested ? nested.getAttribute("data-member") : "")
- || "";
- }
- function getPostContent(post) {
- return post.querySelector(".postmain_right.contents");
- }
- function getQuotedMemberNames(post) {
- var content = getPostContent(post);
- var quotedMembers = [];
- var blockquotes;
- var boldTexts;
- var profileLinks;
- var blockquoteIndex;
- var boldIndex;
- var linkIndex;
- var boldText;
- var match;
- if (!content) {
- return quotedMembers;
- }
- blockquotes = content.querySelectorAll("blockquote");
- for (blockquoteIndex = 0; blockquoteIndex < blockquotes.length; blockquoteIndex += 1) {
- boldTexts = blockquotes[blockquoteIndex].querySelectorAll("b");
- for (boldIndex = 0; boldIndex < boldTexts.length; boldIndex += 1) {
- boldText = boldTexts[boldIndex];
- profileLinks = boldText.querySelectorAll('a[href*="/user/profile/"]');
- for (linkIndex = 0; linkIndex < profileLinks.length; linkIndex += 1) {
- quotedMembers.push(profileLinks[linkIndex].textContent);
- }
- match = boldText.textContent.match(/\bschreef\s+(.+?)\s+het volgende:/i);
- if (match) {
- quotedMembers.push(match[1]);
- }
- }
- }
- return quotedMembers;
- }
- function hasBlockedQuote(post) {
- var quotedMembers = getQuotedMemberNames(post);
- var i;
- for (i = 0; i < quotedMembers.length; i += 1) {
- if (isBlockedName(quotedMembers[i])) {
- return true;
- }
- }
- return false;
- }
- function hideElement(element) {
- element.setAttribute(HIDDEN_ATTRIBUTE, "true");
- element.style.setProperty("display", "none", "important");
- }
- function processPost(post) {
- if (isBlockedName(getMemberName(post)) || hasBlockedQuote(post)) {
- hideElement(post);
- }
- }
- function pushUnique(items, item) {
- if (item && items.indexOf(item) === -1) {
- items.push(item);
- }
- }
- function findPosts(root) {
- var matches = [];
- var elements;
- var i;
- var post;
- if (root && root.nodeType === 1 && matchesSelector(root, POST_SELECTOR)) {
- pushUnique(matches, getPostElement(root));
- }
- if (root && root.querySelectorAll) {
- elements = root.querySelectorAll(POST_SELECTOR);
- for (i = 0; i < elements.length; i += 1) {
- post = getPostElement(elements[i]);
- pushUnique(matches, post);
- }
- }
- return matches;
- }
- function applyBlockList(root) {
- var posts = findPosts(root || document);
- var i;
- for (i = 0; i < posts.length; i += 1) {
- processPost(posts[i]);
- }
- }
- function startObserver() {
- if (observer || typeof MutationObserver === "undefined") {
- return;
- }
- observer = new MutationObserver(function (mutations) {
- var mutationIndex;
- var nodeIndex;
- var addedNodes;
- for (mutationIndex = 0; mutationIndex < mutations.length; mutationIndex += 1) {
- addedNodes = mutations[mutationIndex].addedNodes;
- for (nodeIndex = 0; nodeIndex < addedNodes.length; nodeIndex += 1) {
- applyBlockList(addedNodes[nodeIndex]);
- }
- }
- });
- observer.observe(document.documentElement, {
- childList: true,
- subtree: true
- });
- }
- function init() {
- if (!document.body) {
- window.setTimeout(init, 50);
- return;
- }
- applyBlockList(document);
- startObserver();
- }
- try {
- init();
- } catch (error) {
- console.error("FOK!Rust kon niet starten.", error);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment