PurSiC

Fix Bug font Google Chrome - User Script

Feb 25th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Replace Text On Webpages
  3. // @namespace      https://userscripts-mirror.org/users/23652
  4. // @description    Replaces text on websites. Now supports wildcards in search queries. Won't replace text in certain tags like links and code blocks
  5. // @include        http://*
  6. // @include        https://*
  7. // @include        file://*
  8. // @exclude        https://userscripts-mirror.org/scripts/review/*
  9. // @exclude        https://userscripts-mirror.org/scripts/edit/*
  10. // @exclude        https://userscripts-mirror.org/scripts/edit_src/*
  11. // @exclude        https://userscripts-mirror.org/scripts/review/*
  12. // @exclude        https://userscripts-mirror.org/scripts/edit/*
  13. // @exclude        https://userscripts-mirror.org/scripts/edit_src/*
  14. // @copyright      JoeSimmons
  15. // @version        1.1.0
  16. // @license        http://creativecommons.org/licenses/by-nc-nd/3.0/us/
  17. // @downloadURL    https://userscripts-mirror.org/scripts/source/41369.user.js
  18. // @updateURL      https://userscripts-mirror.org/scripts/source/41369.meta.js
  19. // ==/UserScript==
  20. (function () {
  21.     'use strict';
  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.         '๐Ÿงจ' : '',
  35.  
  36.  
  37.     ///////////////////////////////////////////////////////
  38.     '':''};
  39.  
  40.     //////////////////////////////////////////////////////////////////////////////
  41.     // This is where the real code is
  42.     // Don't edit below this
  43.     //////////////////////////////////////////////////////////////////////////////
  44.  
  45.     var regexs = [], replacements = [],
  46.         tagsWhitelist = ['PRE', 'BLOCKQUOTE', 'CODE', 'INPUT', 'BUTTON', 'TEXTAREA'],
  47.         rIsRegexp = /^\/(.+)\/([gim]+)?$/,
  48.         word, text, texts, i, userRegexp;
  49.  
  50.     // prepareRegex by JoeSimmons
  51.     // used to take a string and ready it for use in new RegExp()
  52.     function prepareRegex(string) {
  53.         return string.replace(/([\[\]\^\&\$\.\(\)\?\/\\\+\{\}\|])/g, '\\$1');
  54.     }
  55.  
  56.     // function to decide whether a parent tag will have its text replaced or not
  57.     function isTagOk(tag) {
  58.         return tagsWhitelist.indexOf(tag) === -1;
  59.     }
  60.  
  61.     delete words['']; // so the user can add each entry ending with a comma,
  62.                       // I put an extra empty key/value pair in the object.
  63.                       // so we need to remove it before continuing
  64.  
  65.     // convert the 'words' JSON object to an Array
  66.     for (word in words) {
  67.         if ( typeof word === 'string' && words.hasOwnProperty(word) ) {
  68.             userRegexp = word.match(rIsRegexp);
  69.  
  70.             // add the search/needle/query
  71.             if (userRegexp) {
  72.                 regexs.push(
  73.                     new RegExp(userRegexp[1], 'g')
  74.                 );
  75.             } else {
  76.                 regexs.push(
  77.                     new RegExp(prepareRegex(word).replace(/\\?\*/g, function (fullMatch) {
  78.                         return fullMatch === '\\*' ? '*' : '[^ ]*';
  79.                     }), 'g')
  80.                 );
  81.             }
  82.  
  83.             // add the replacement
  84.             replacements.push( words[word] );
  85.         }
  86.     }
  87.  
  88.     // do the replacement
  89.     texts = document.evaluate('//html//text()[ normalize-space(.) != "" ]', document, null, 6, null);
  90.     for (i = 0; text = texts.snapshotItem(i); i += 1) {
  91.         if ( isTagOk(text.parentNode.tagName) ) {
  92.             regexs.forEach(function (value, index) {
  93.                 text.data = text.data.replace( value, replacements[index] );
  94.             });
  95.         }
  96.     }
  97.  
  98. }());
Add Comment
Please, Sign In to add comment