FMHY Base64 Rentry Decoder-Linkifier

Decode base64-encoded the FMHY Rentry page and make URLs clickable

当前为 2024-01-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name FMHY Base64 Rentry Decoder-Linkifier
  3. // @version 1.0
  4. // @description Decode base64-encoded the FMHY Rentry page and make URLs clickable
  5. // @match https://rentry.co/fmhybase64*
  6. // @match https://rentry.co/FMHYBase64*
  7. // @match https://rentry.org/fmhybase64*
  8. // @match https://rentry.org/FMHYBase64*
  9. // @grant none
  10. // @namespace https://greasyfork.org/users/980489
  11. // ==/UserScript==
  12.  
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to decode base64 string
  18. function decodeBase64(encodedString) {
  19. return atob(encodedString);
  20. }
  21.  
  22. // Function to check if a string is a URL
  23. function isURL(string) {
  24. try {
  25. new URL(string);
  26. return true;
  27. } catch (_) {
  28. return false;
  29. }
  30. }
  31.  
  32. // Select all <code> elements
  33. var codeElements = document.querySelectorAll('code');
  34.  
  35. // Loop through each <code> element
  36. codeElements.forEach(function(codeElement) {
  37. // Get the content of the <code> element
  38. var encodedString = codeElement.textContent.trim();
  39.  
  40. // Decode the base64-encoded string
  41. var decodedString = decodeBase64(encodedString);
  42.  
  43. // If the decoded string is a URL, create a clickable link
  44. if (isURL(decodedString)) {
  45. var link = document.createElement('a');
  46. link.href = decodedString;
  47. link.textContent = decodedString;
  48. link.target = '_blank'; // Open link in a new tab
  49. codeElement.textContent = ''; // Clear the content of <code> element
  50. codeElement.appendChild(link); // Append the link to the <code> element
  51. } else {
  52. // Replace the content of the <code> element with the decoded string
  53. codeElement.textContent = decodedString;
  54. }
  55. });
  56. })();