-
-
Save madmox/4fd0b144e857ee5bf0afc3b4b95415c4 to your computer and use it in GitHub Desktop.
Filter out a user's posts from MagicVille forum threads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name MV_PostsFilter | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Filter out a user's posts from MagicVille forum threads | |
// @author Madmox | |
// @match http*://*.magic-ville.com/fr/forum/sujet?ref=* | |
// @match http*://*.magic-ville.fr/fr/forum/sujet?ref=* | |
// @match http*://*.magic-ville.eu/fr/forum/sujet?ref=* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
/*** | |
THIS IS WHERE YOU WANT TO PUT BLACKLISTED USERNAMES | |
E.g. if you want to filter out users foo and bar: | |
let blacklist = [ "foo", "bar" ]; | |
***/ | |
let blacklist = [ ]; | |
/*** | |
The text content that will replace each blocked user's message. | |
Leave empty to simply remove the message's content. | |
***/ | |
let replacementMessage = "pouet"; | |
/*** | |
Set to false so that the original message doesn't show up when clicking the post. | |
***/ | |
let displayOriginalMessageOnClick = true; | |
var mvContent = document.getElementById("MV_content"); | |
if (typeof mvContent !== "undefined") { | |
for (let username of blacklist) { | |
let posts = document.evaluate("./div[div/div/table/tbody/tr/td[1]//a[@href='../register/perso?user=" + escapeXPathString(username) + "']]", mvContent, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (let i = 0; i < posts.snapshotLength; i++) { | |
let post = posts.snapshotItem(i); | |
/*** | |
If you want to remove the post entirely, replace the following lines with: | |
post.style.display = "none"; | |
***/ | |
let postContent = document.evaluate("./div/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div", post, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
let fakeChild = postContent.cloneNode(false); | |
fakeChild.textContent = replacementMessage; | |
if (displayOriginalMessageOnClick) { | |
fakeChild.addEventListener("click", event => { | |
postContent.parentNode.removeChild(event.target); | |
postContent.style.display = "block"; | |
}); | |
} | |
postContent.style.display = "none"; | |
postContent.parentNode.appendChild(fakeChild); | |
/*** | |
End of the section to replace. | |
***/ | |
} | |
} | |
} | |
function escapeXPathString(str) { | |
return str.replace("'", "' + \"'\" + '"); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment