Skip to content

Instantly share code, notes, and snippets.

@aequabit
Last active May 13, 2020 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aequabit/7b3a07aebe9a9d244d7db2bf223202d7 to your computer and use it in GitHub Desktop.
Save aequabit/7b3a07aebe9a9d244d7db2bf223202d7 to your computer and use it in GitHub Desktop.
#FreePr0
// ==UserScript==
// @name XenForo 2 FreePr0
// @version 1.0
// @description Uncensors pr0 URLs
// @author aequabit
// @match *://*/*
// @grant unsafeWindow
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
// ==/UserScript==
const replacements = {
'https://****************/': 'https://img.pr0gramm.com/'
};
const replaceMessage = element => {
for (const [search, replace] of Object.entries(replacements)) {
if (element.innerHTML.indexOf(search) !== -1) {
const messageContent = $(element).children('.shoutbox-message-content').first();
if (messageContent.length > 0) {
const final = messageContent[0].innerText.split(' ').map(word => {
if (word.startsWith(search)) {
const fixed = word.split(search).join(replace);
return '<a href="' + fixed + '" class="link link--external" rel="nofollow" target="_blank">' + fixed + '</a>';
} else {
return final.push(word);
}
});
messageContent[0].innerHTML = final.join(' ');
}
}
}
};
$(document).ready(() => {
if (unsafeWindow.XF === undefined) {
return;
}
console.log('xf_free_pr0: XenForo detected');
$('.shoutbox-messages').children().each((_, element) => {
replaceMessage(element);
});
$('.shoutbox-messages').bind('DOMNodeInserted', async event => {
replaceMessage(event.target);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment