Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Verizonifier
- // @namespace
- // @description Makes all websites look like Verizon's view of the internet (http://publicpolicy.verizon.com/blog/entry/fccs-throwback-thursday-move-imposes-1930s-rules-on-the-internet)
- // @description Based on JoeSimmons's Replace Text on Webpages userscript (http://userscripts.org/users/23652)
- // @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 CEnnis91
- // @version 1.0.0
- // @license http://creativecommons.org/licenses/by-nc-nd/3.0/us/
- // ==/UserScript==
- (function () {
- 'use strict';
- /*
- NOTE:
- You can use \\* to match actual asterisks instead of using it as a wildcard!
- The examples below show a wildcard in use and a regular asterisk replacement.
- */
- var words = {
- ///////////////////////////////////////////////////////
- // Syntax: 'Search word' : 'Replace word',
- '/[aA]/g' : '.-',
- '/[bB]/g' : '-...',
- '/[cC]/g' : '-.-.',
- '/[dD]/g' : '-..',
- '/[eE]/g' : '.',
- '/[fF]/g' : '..-.',
- '/[gG]/g' : '--.',
- '/[hH]/g' : '....',
- '/[iI]/g' : '..',
- '/[jJ]/g' : '.---',
- '/[kK]/g' : '-.-',
- '/[lL]/g' : '.-..',
- '/[mM]/g' : '--',
- '/[nN]/g' : '-.',
- '/[oO]/g' : '---',
- '/[pP]/g' : '.--.',
- '/[qQ]/g' : '--.-',
- '/[rR]/g' : '.-.',
- '/[sS]/g' : '...',
- '/[tT]/g' : '-',
- '/[uU]/g' : '..-',
- '/[vV]/g' : '...-',
- '/[wW]/g' : '.--',
- '/[xX]/g' : '-..-',
- '/[yY]/g' : '-.--',
- '/[zZ]/g' : '--..',
- '/[0]/g' : '-----',
- '/[1]/g' : '.----',
- '/[2]/g' : '..---',
- '/[3]/g' : '...--',
- '/[4]/g' : '....-',
- '/[5]/g' : '.....',
- '/[6]/g' : '-....',
- '/[7]/g' : '--...',
- '/[8]/g' : '---..',
- '/[9]/g' : '----.',
- '/\\,/g' : '--..--',
- '/\\!/g' : '..--.',
- '/\\:/g' : '---...',
- '/\\"/g' : '.-..-.',
- '/\'/g' : '.----.',
- '/\\=/g' : '-...-',
- '/\//g' : '-..-.',
- '/[()]/g' : '-.--.-',
- '/[@]/g' : '.--.-.',
- '/[$]/g' : '...-..-',
- '/[\\[\\]]/g' : '-.--.-',
- '/[_]/g' : '..--.-',
- '?' : '..--..',
- '\\.' : '.-.-.-',
- ///////////////////////////////////////////////////////
- '':''};
- //////////////////////////////////////////////////////////////////////////////
- // 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] );
- });
- }
- }
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement