UnURLencode

Decode percent-encoded text on visited web pages

  1. // ==UserScript==
  2. // @name UnURLencode
  3. // @namespace lainscripts_unurlencode
  4. // @version 0.2
  5. // @description Decode percent-encoded text on visited web pages
  6. // @author lainverse
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. let pctdetect = /%[0-9A-F][0-9A-F]/,
  14. pctmatch = /(%[0-9A-F][0-9A-F])+/g;
  15. function crawler(node) {
  16. switch (node.nodeType) {
  17. case Node.ELEMENT_NODE:
  18. for (let child of node.childNodes) {
  19. if (pctdetect.test(child.textContent)) {
  20. crawler(child);
  21. }
  22. }
  23. break;
  24. case Node.TEXT_NODE:
  25. node.nodeValue = node.nodeValue.replace(pctmatch, function(match){
  26. try {
  27. return decodeURIComponent(match);
  28. } catch(ignore) {
  29. return match;
  30. }
  31. });
  32. }
  33. }
  34. crawler(document.documentElement);
  35.  
  36. let o = new MutationObserver(function(mutations) {
  37. let mutation, node;
  38. for (mutation of mutations) {
  39. for (node of mutation.addedNodes) {
  40. crawler(node);
  41. }
  42. }
  43. });
  44. o.observe(document.documentElement, {
  45. childList: true,
  46. characterData: true,
  47. subtree: true
  48. });
  49. })();