Advertisement
Guest User

Verizonifier

a guest
Feb 27th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Verizonifier
  3. // @namespace      
  4. // @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)
  5. // @description    Based on JoeSimmons's Replace Text on Webpages userscript (http://userscripts.org/users/23652)
  6. // @include        http://*
  7. // @include        https://*
  8. // @include        file://*
  9. // @exclude        http://userscripts.org/scripts/review/*
  10. // @exclude        http://userscripts.org/scripts/edit/*
  11. // @exclude        http://userscripts.org/scripts/edit_src/*
  12. // @exclude        https://userscripts.org/scripts/review/*
  13. // @exclude        https://userscripts.org/scripts/edit/*
  14. // @exclude        https://userscripts.org/scripts/edit_src/*
  15. // @copyright      CEnnis91
  16. // @version        1.0.0
  17. // @license        http://creativecommons.org/licenses/by-nc-nd/3.0/us/
  18. // ==/UserScript==
  19. (function () {
  20.     'use strict';
  21.  
  22.  
  23.     /*
  24.         NOTE:
  25.             You can use \\* to match actual asterisks instead of using it as a wildcard!
  26.             The examples below show a wildcard in use and a regular asterisk replacement.
  27.     */
  28.  
  29.     var words = {
  30.     ///////////////////////////////////////////////////////
  31.  
  32.  
  33.         // Syntax: 'Search word' : 'Replace word',
  34.         '/[aA]/g' : '.-',
  35.         '/[bB]/g' : '-...',
  36.         '/[cC]/g' : '-.-.',
  37.         '/[dD]/g' : '-..',
  38.         '/[eE]/g' : '.',
  39.         '/[fF]/g' : '..-.',
  40.         '/[gG]/g' : '--.',
  41.         '/[hH]/g' : '....',
  42.         '/[iI]/g' : '..',
  43.         '/[jJ]/g' : '.---',
  44.         '/[kK]/g' : '-.-',
  45.         '/[lL]/g' : '.-..',
  46.         '/[mM]/g' : '--',
  47.         '/[nN]/g' : '-.',
  48.         '/[oO]/g' : '---',
  49.         '/[pP]/g' : '.--.',
  50.         '/[qQ]/g' : '--.-',
  51.         '/[rR]/g' : '.-.',
  52.         '/[sS]/g' : '...',
  53.         '/[tT]/g' : '-',
  54.         '/[uU]/g' : '..-',
  55.         '/[vV]/g' : '...-',
  56.         '/[wW]/g' : '.--',
  57.         '/[xX]/g' : '-..-',
  58.         '/[yY]/g' : '-.--',
  59.         '/[zZ]/g' : '--..',
  60.         '/[0]/g' : '-----',
  61.         '/[1]/g' : '.----',
  62.         '/[2]/g' : '..---',
  63.         '/[3]/g' : '...--',
  64.         '/[4]/g' : '....-',
  65.         '/[5]/g' : '.....',
  66.         '/[6]/g' : '-....',
  67.         '/[7]/g' : '--...',
  68.         '/[8]/g' : '---..',
  69.         '/[9]/g' : '----.',
  70.         '/\\,/g' : '--..--',
  71.         '/\\!/g' : '..--.',
  72.         '/\\:/g' : '---...',
  73.         '/\\"/g' : '.-..-.',
  74.         '/\'/g' : '.----.',
  75.         '/\\=/g' : '-...-',
  76.         '/\//g' : '-..-.',
  77.         '/[()]/g' : '-.--.-',
  78.         '/[@]/g' : '.--.-.',
  79.         '/[$]/g' : '...-..-',
  80.         '/[\\[\\]]/g' : '-.--.-',
  81.         '/[_]/g' : '..--.-',
  82.         '?' : '..--..',
  83.         '\\.' : '.-.-.-',
  84.        
  85.        
  86.        
  87.  
  88.     ///////////////////////////////////////////////////////
  89.     '':''};
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.     //////////////////////////////////////////////////////////////////////////////
  101.     // This is where the real code is
  102.     // Don't edit below this
  103.     //////////////////////////////////////////////////////////////////////////////
  104.  
  105.     var regexs = [], replacements = [],
  106.         tagsWhitelist = ['PRE', 'BLOCKQUOTE', 'CODE', 'INPUT', 'BUTTON', 'TEXTAREA'],
  107.         rIsRegexp = /^\/(.+)\/([gim]+)?$/,
  108.         word, text, texts, i, userRegexp;
  109.  
  110.     // prepareRegex by JoeSimmons
  111.     // used to take a string and ready it for use in new RegExp()
  112.     function prepareRegex(string) {
  113.         return string.replace(/([\[\]\^\&\$\.\(\)\?\/\\\+\{\}\|])/g, '\\$1');
  114.     }
  115.  
  116.     // function to decide whether a parent tag will have its text replaced or not
  117.     function isTagOk(tag) {
  118.         return tagsWhitelist.indexOf(tag) === -1;
  119.     }
  120.  
  121.     delete words['']; // so the user can add each entry ending with a comma,
  122.                       // I put an extra empty key/value pair in the object.
  123.                       // so we need to remove it before continuing
  124.  
  125.     // convert the 'words' JSON object to an Array
  126.     for (word in words) {
  127.         if ( typeof word === 'string' && words.hasOwnProperty(word) ) {
  128.             userRegexp = word.match(rIsRegexp);
  129.  
  130.             // add the search/needle/query
  131.             if (userRegexp) {
  132.                 regexs.push(
  133.                     new RegExp(userRegexp[1], 'g')
  134.                 );
  135.             } else {
  136.                 regexs.push(
  137.                     new RegExp(prepareRegex(word).replace(/\\?\*/g, function (fullMatch) {
  138.                         return fullMatch === '\\*' ? '*' : '[^ ]*';
  139.                     }), 'g')
  140.                 );
  141.             }
  142.  
  143.             // add the replacement
  144.             replacements.push( words[word] );
  145.         }
  146.     }
  147.  
  148.     // do the replacement
  149.     texts = document.evaluate('//body//text()[ normalize-space(.) != "" ]', document, null, 6, null);
  150.     for (i = 0; text = texts.snapshotItem(i); i += 1) {
  151.         if ( isTagOk(text.parentNode.tagName) ) {
  152.             regexs.forEach(function (value, index) {
  153.                 text.data = text.data.replace( value, replacements[index] );
  154.             });
  155.         }
  156.     }
  157.  
  158. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement