xkcd 1418

Replaces the word "force" with "horse" everywhere. Is expandable with other replacements.

  1. // ==UserScript==
  2. // @name xkcd 1418
  3. // @name:ru xkcd 1418
  4. // @namespace http://xkcd.com/1418
  5. // @license MIT
  6. // @description Replaces the word "force" with "horse" everywhere. Is expandable with other replacements.
  7. // @description:ru Заменяет слово "force" на "horse". Можно добавлять свои замены.
  8. // @version 4
  9. // @include *
  10. // @exclude https://gf.qytechs.cn/*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. /*
  15. * Copyright (c) 2015-2023 Andrei Rybak
  16. *
  17. * Permission is hereby granted, free of charge, to any person obtaining a copy
  18. * of this software and associated documentation files (the "Software"), to deal
  19. * in the Software without restriction, including without limitation the rights
  20. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  21. * copies of the Software, and to permit persons to whom the Software is
  22. * furnished to do so, subject to the following conditions:
  23. *
  24. * The above copyright notice and this permission notice shall be included in all
  25. * copies or substantial portions of the Software.
  26. *
  27. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  29. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  30. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  31. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  32. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35.  
  36. /*
  37. * Based on http://bitcoinshell.mooo.com/users/noiob/dev/horse.user.js
  38. * and https://www.techradar.com/news/internet/the-beginner-s-guide-to-greasemonkey-scripting-598247/4
  39. */
  40.  
  41. const replacements = [
  42. ['Force', 'Horse'],
  43. ['FORCE', 'HORSE'],
  44. ['force', 'horse']
  45. // add your own replacements here (e.g. ['the cloud', 'my butt']).
  46. // don't forget to add commas to the list
  47. // ru:можно добавлять свои замены здесь, например, ['the cloud', 'my butt']
  48. // ru:не забывайте добавить запятые к списку
  49. ];
  50.  
  51. const textNodes = document.evaluate("//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  52.  
  53. function xkcd_replace(source, replace) {
  54. var searchRE = new RegExp(source, 'g');
  55. for (var i = 0; i < textNodes.snapshotLength; i++) {
  56. const node = textNodes.snapshotItem(i);
  57. node.data = node.data.replace(searchRE, replace);
  58. }
  59. }
  60.  
  61. for (var i = 0; i < replacements.length; ++i) {
  62. xkcd_replace(replacements[i][0], replacements[i][1]);
  63. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址