Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
@badjokebot censoring userscript
// ==UserScript==
// @name @badjokebot answer blocker
// @version 0.1
// @description blacks out badjokebot answers, shows on hover
// @match https://*.twitter.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @copyright whatever
// ==/UserScript==
// TODO: doesn't work for tweets loaded on scrolldown
function blackoutAnswer(text) {
return text.substring(0, text.lastIndexOf("A:") + 3) +
"<span style='background: #333; color: #333; display: inline-block; width: 8em;'>" +
text.substring(text.lastIndexOf("A:") + 3, text.length) +
"</span>";
};
$("div[data-screen-name=badjokebot] .js-tweet-text").each(
function () { $(this).html(blackoutAnswer( $(this).html() )) }
);
$("body").on("click", function() {
$("div[data-screen-name=badjokebot] .js-tweet-text:not(:contains(<span))").each(
function () { $(this).html(blackoutAnswer( $(this).html() )) }
);
});
$("div[data-screen-name=badjokebot] .js-tweet-text").on("mouseenter", function() {
$(this).html($(this).text());
});
$("div[data-screen-name=badjokebot] .js-tweet-text").on("mouseleave", function() {
$(this).html(blackoutAnswer( $(this).html() ));
});
// TODO: lol ok this event handling should NOT be necessary and i'm doing something wrong
$("body").on("click", function() {
$("div[data-screen-name=badjokebot] .js-tweet-text:not(:contains(<span))").on("mouseenter", function() {
$(this).html($(this).text());
});
$("div[data-screen-name=badjokebot] .js-tweet-text:not(:contains(<span))").on("mouseleave", function() {
$(this).html(blackoutAnswer( $(this).html() ));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment