HF - Enable Swearing

A plugin that lets you swear again :)

  1. // ==UserScript==
  2. // @name HF - Enable Swearing
  3. // @namespace HF - Enable Swearing
  4. // @description A plugin that lets you swear again :)
  5. // @include http://*
  6. // @include https://*
  7. // @author Who Soup
  8. // @version 1.1.0
  9.  
  10. // ==/UserScript==
  11. (function () {
  12. 'use strict';
  13.  
  14.  
  15. var words = {
  16.  
  17. 'Clay Davis' : 'shit',
  18. 'bullsnap' : 'bullshit',
  19. 'kitten' : 'cunt',
  20. 'mommyfugger' : 'motherfucker',
  21. 'fugg' : 'fuck',
  22.  
  23. '':''};
  24.  
  25. var regexs = [], replacements = [],
  26. tagsWhitelist = ['PRE', 'BLOCKQUOTE', 'CODE', 'INPUT', 'BUTTON', 'TEXTAREA'],
  27. rIsRegexp = /^\/(.+)\/([gim]+)?$/,
  28. word, text, texts, i, userRegexp;
  29.  
  30.  
  31. function prepareRegex(string) {
  32. return string.replace(/([\[\]\^\&\$\.\(\)\?\/\\\+\{\}\|])/g, '\\$1');
  33. }
  34.  
  35.  
  36. function isTagOk(tag) {
  37. return tagsWhitelist.indexOf(tag) === -1;
  38. }
  39.  
  40. delete words[''];
  41.  
  42.  
  43.  
  44.  
  45. for (word in words) {
  46. if ( typeof word === 'string' && words.hasOwnProperty(word) ) {
  47. userRegexp = word.match(rIsRegexp);
  48.  
  49.  
  50. if (userRegexp) {
  51. regexs.push(
  52. new RegExp(userRegexp[1], 'g')
  53. );
  54. } else {
  55. regexs.push(
  56. new RegExp(prepareRegex(word).replace(/\\?\*/g, function (fullMatch) {
  57. return fullMatch === '\\*' ? '*' : '[^ ]*';
  58. }), 'g')
  59. );
  60. }
  61.  
  62.  
  63. replacements.push( words[word] );
  64. }
  65. }
  66.  
  67.  
  68. texts = document.evaluate('//body//text()[ normalize-space(.) != "" ]', document, null, 6, null);
  69. for (i = 0; text = texts.snapshotItem(i); i += 1) {
  70. if ( isTagOk(text.parentNode.tagName) ) {
  71. regexs.forEach(function (value, index) {
  72. text.data = text.data.replace( value, replacements[index] );
  73. });
  74. }
  75. }
  76.  
  77. }());