Last active
February 9, 2019 10:26
-
-
Save CapnSparrow/d1f4f3d48c776279895a497a2eabe266 to your computer and use it in GitHub Desktop.
Removes comments with ads in signature on the https://bitcointalk.org forum.
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 BitcoinTalk Poor Comment Blocker | |
// @version 1.0 | |
// @author CapnSparrow@BitcoinTalk | |
// @description Removes comments with ads in signature on the https://bitcointalk.org forum. | |
// @include https://bitcointalk.org/index.php?topic=* | |
// @require https://code.jquery.com/jquery-3.3.1.min.js | |
// @run-at document-end | |
// ==/UserScript== | |
// Configuration. | |
//============================================================================ | |
/* | |
* Define block words here. Each item is a regex. Case is ignored. | |
*/ | |
var blockWords = [ | |
"telegram" | |
, "whitepaper" | |
, "discount" | |
, "\\bjoin\\b" | |
, "be part of" | |
, "pre-?sale" | |
, "\\bico\\b" | |
, "token" | |
, "empower" | |
, "casino" | |
, "fortune" | |
, "\\bdice\\b" | |
]; | |
/* | |
* We won't block these phrases. Each item is a regex. Case is ignored. | |
*/ | |
var exceptionalWords = [ | |
"HoweyCoins" // Not a real ICO but a joke. See https://bitcointalk.org/index.php?topic=3920469.0 | |
]; | |
/* | |
* If a user has more than this number of merits we will never block him/her in any case. | |
*/ | |
var minMeritsToBypassBlocking = 1000; | |
//============================================================================ | |
blockWords = new RegExp(blockWords.join("|"), "i"); | |
exceptionalWords = new RegExp(exceptionalWords.join("|"), "ig"); | |
$(".signature").each(function () { | |
var $this = $(this); | |
// Fetch number of merits. | |
var match = /merit:\s*(\d+)/i.exec($this.parents("td.windowbg, td.windowbg2").find(".poster_info").text()); | |
var meritsCount = match[1]; | |
var signatureContent = $this.html(); | |
// Clean up. | |
signatureContent = signatureContent.replace(exceptionalWords, ""); | |
if (meritsCount < minMeritsToBypassBlocking && blockWords.test(signatureContent)) { | |
hidePost($this); | |
} | |
}); | |
insertCss( | |
".hidden-post-container {" | |
+ "background-color: #ECEDF3;" | |
+ "}" | |
+ ".hidden-post-inner {" | |
+ "opacity: 0.05;" | |
+ "transition: 0.2s opacity;" | |
+ "}" | |
+ ".hidden-post-inner:hover {" | |
+ "opacity: 1;" | |
+ "transition-delay: 0.5s;" | |
+ "}" | |
); | |
function hidePost($signature) { | |
$signature.parents("td.windowbg, td.windowbg2").addClass("hidden-post-inner").parent().addClass("hidden-post-container"); | |
} | |
function insertCss(css) { | |
var style = document.createElement("style"); | |
style.type = "text/css"; | |
style.innerHTML = css; | |
document.head.appendChild(style); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whitelisting would be a helpful feauture. It can be stored in the browser offline. There is such an implementation here:
https://github.com/Tiramisu77/Bitcointalk-Post-Filter/blob/d4442f635099692a294b916d27a2ec6c509fe5d3/Bitcointalk-Post-Filter.user.js