Decode Hex strings on Voz

Decode Hex, Base64

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

  1. // ==UserScript==
  2. // @name Decode Hex strings on Voz
  3. // @namespace Decode Hex strings on Voz
  4. // @version 3.0
  5. // @icon https://www.google.com/s2/favicons?sz=64&domain=voz.vn
  6. // @author kylyte
  7. // @description Decode Hex, Base64
  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. hexString = hexString.replace(/\s+/g, '');
  18. if (!/^[0-9A-Fa-f]{2,}$/.test(hexString)) return hexString;
  19. let hexStr = '';
  20. try {
  21. for (let i = 0; i < hexString.length; i += 2) {
  22. hexStr += String.fromCharCode(parseInt(hexString.substr(i, 2), 16));
  23. }
  24. if (/^[\x20-\x7E]*$/.test(hexStr) && hexStr.length > 3) {
  25. return hexStr;
  26. } else {
  27. return hexString;
  28. }
  29. } catch {
  30. return hexString;
  31. }
  32. }
  33.  
  34. function decodeBase64(base64String) {
  35. if (!/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(base64String)) return base64String;
  36. try {
  37. let binaryString = atob(base64String);
  38. if (/^[\x20-\x7E]*$/.test(binaryString) && binaryString.length > 3) {
  39. return binaryString;
  40. } else {
  41. return base64String;
  42. }
  43. } catch {
  44. return base64String;
  45. }
  46. }
  47.  
  48. function decodeContent(elements, regex, decodeFunc) {
  49. elements.forEach(element => {
  50. if (element.closest('.fr-box.bbWrapper.fr-ltr.fr-basic.fr-top') || element.closest('.tooltip.tooltip--basic')) return;
  51. let walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null, false);
  52. let textNode;
  53. while (textNode = walker.nextNode()) {
  54. let content = textNode.nodeValue;
  55. let matches = content.match(regex);
  56. if (matches) {
  57. matches.forEach(match => {
  58. content = content.replace(new RegExp(escapeRegExp(match), 'g'), decodeFunc(match));
  59. });
  60. textNode.nodeValue = content;
  61. }
  62. }
  63. });
  64. }
  65.  
  66. function escapeRegExp(string) {
  67. return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  68. }
  69.  
  70. function main() {
  71. let elements = document.querySelectorAll('.bbWrapper');
  72. decodeContent(elements, /\b([0-9A-Fa-f]{2}\s*){4,}\b/g, decodeHex);
  73. decodeContent(elements, /(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})/g, decodeBase64);
  74. }
  75.  
  76. main();
  77. })();