Last active
June 17, 2022 15:37
-
-
Save fearthecowboy/6e6303bb9cb30faaeb3fbd6cf1474ecd to your computer and use it in GitHub Desktop.
Tampermonkey script to turn Bitcoin into "Dutch Tulip Bulbs"
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 Replace 'Bitcoin' On Webpages | |
// @namespace https://gist.github.com/fearthecowboy | |
// @description Replaces bitcoin on websites. | |
// @include http://* | |
// @include https://* | |
// @include file://* | |
// @exclude http://userscripts.org/scripts/review/* | |
// @exclude http://userscripts.org/scripts/edit/* | |
// @exclude http://userscripts.org/scripts/edit_src/* | |
// @exclude https://userscripts.org/scripts/review/* | |
// @exclude https://userscripts.org/scripts/edit/* | |
// @exclude https://userscripts.org/scripts/edit_src/* | |
// @copyright JoeSimmons | |
// @version 1.1.0 | |
// @license http://creativecommons.org/licenses/by-nc-nd/3.0/us/ | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
var words = { | |
/////////////////////////////////////////////////////// | |
// Syntax: 'Search word' : 'Replace word', | |
'bitcoin' : 'dutch tulip bulbs', | |
'BITCOIN' : 'Dutch Tulip Bulbs', | |
'Bitcoin' : 'Dutch Tulip Bulbs', | |
'BitCoin' : 'Dutch Tulip Bulbs', | |
'btc' : 'tulip bulbs', | |
/////////////////////////////////////////////////////// | |
'':''}; | |
var activate = ()=>{ | |
////////////////////////////////////////////////////////////////////////////// | |
// This is where the real code is | |
// Don't edit below this | |
////////////////////////////////////////////////////////////////////////////// | |
var regexs = [], replacements = [], | |
tagsWhitelist = ['PRE', 'BLOCKQUOTE', 'CODE', 'INPUT', 'BUTTON', 'TEXTAREA'], | |
rIsRegexp = /^\/(.+)\/([gim]+)?$/, | |
word, text, texts, i, userRegexp; | |
// prepareRegex by JoeSimmons | |
// used to take a string and ready it for use in new RegExp() | |
function prepareRegex(string) { | |
return string.replace(/([\[\]\^\&\$\.\(\)\?\/\\\+\{\}\|])/g, '\\$1'); | |
} | |
// function to decide whether a parent tag will have its text replaced or not | |
function isTagOk(tag) { | |
return tagsWhitelist.indexOf(tag) === -1; | |
} | |
delete words['']; // so the user can add each entry ending with a comma, | |
// I put an extra empty key/value pair in the object. | |
// so we need to remove it before continuing | |
// convert the 'words' JSON object to an Array | |
for (word in words) { | |
if ( typeof word === 'string' && words.hasOwnProperty(word) ) { | |
userRegexp = word.match(rIsRegexp); | |
// add the search/needle/query | |
if (userRegexp) { | |
regexs.push( | |
new RegExp(userRegexp[1], 'g') | |
); | |
} else { | |
regexs.push( | |
new RegExp(prepareRegex(word).replace(/\\?\*/g, function (fullMatch) { | |
return fullMatch === '\\*' ? '*' : '[^ ]*'; | |
}), 'g') | |
); | |
} | |
// add the replacement | |
replacements.push( words[word] ); | |
} | |
} | |
// do the replacement | |
texts = document.evaluate('//body//text()[ normalize-space(.) != "" ]', document, null, 6, null); | |
for (i = 0; text = texts.snapshotItem(i); i += 1) { | |
if ( isTagOk(text.parentNode.tagName) ) { | |
regexs.forEach(function (value, index) { | |
text.data = text.data.replace( value, replacements[index] ); | |
// if we found some hits, let's resubscribe for another run in a few seconds. | |
setTimeout(activate,3000); | |
}); | |
} | |
} | |
}; | |
setTimeout(activate,500); | |
setTimeout(activate,2500); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment