Decode Hex strings on Voz

Decode hex strings on Voz

当前为 2024-08-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Decode Hex strings on Voz
  3. // @namespace Decode Hex strings on Voz
  4. // @version 1.1
  5. // @icon https://www.google.com/s2/favicons?sz=64&domain=voz.vn
  6. // @author kylyte
  7. // @description Decode hex strings on Voz
  8. // @match https://voz.vn/t/*
  9. // @run-at document-idle
  10. // @license GPL-3.0
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function decodeHex(hexString) {
  17. var hex = hexString.toString();
  18. var str = '';
  19. for (var i = 0; i < hex.length; i += 2)
  20. str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
  21. return str;
  22. }
  23.  
  24. function decodeHexInBbWrapper() {
  25. var elements = document.getElementsByClassName('bbWrapper');
  26. for (var i = 0; i < elements.length; i++) {
  27. if (elements[i].querySelector('.bbMediaJustifier')) {
  28. continue;
  29. }
  30.  
  31. var content = elements[i].innerHTML;
  32. var regex = /([0-9A-Fa-f]{2}){8,}/g;
  33. var matches = content.match(regex);
  34. if (matches) {
  35. matches.forEach(function(hexString) {
  36. var decodedText = decodeHex(hexString);
  37. content = content.replace(hexString, decodedText);
  38. });
  39. elements[i].innerHTML = content;
  40. }
  41. }
  42. }
  43.  
  44. decodeHexInBbWrapper();
  45.  
  46. var observer = new MutationObserver(function(mutationsList) {
  47. for (var mutation of mutationsList) {
  48. if (mutation.type === 'childList' && mutation.target.classList.contains('bbWrapper')) {
  49. decodeHexInBbWrapper();
  50. break;
  51. }
  52. }
  53. });
  54.  
  55. observer.observe(document.documentElement, {
  56. childList: true,
  57. subtree: true
  58. });
  59.  
  60. })();