OFans.party IPFS gateway replacer

Replaces the currently-broken IPFS gateway used by ofans.party with a different, working one.

  1. // ==UserScript==
  2. // @name OFans.party IPFS gateway replacer
  3. // @namespace https://greasyfork.org/users/390979-parliament
  4. // @description Replaces the currently-broken IPFS gateway used by ofans.party with a different, working one.
  5. // @version 0.1
  6. // @author parliament
  7. // @match https://ofans.party/
  8. // @run-at document-idle
  9. // ==/UserScript==
  10.  
  11. 'use strict';
  12.  
  13. function replaceAllUris() {
  14. let links = document.getElementsByTagName("a");
  15. let images = document.getElementsByTagName("img");
  16.  
  17. for (let link of links) {
  18. let uri = link.getAttribute("href");
  19. let fixedUri = uri.replace(/ipfs\.greyh\.at/, "ninetailed.ninja");
  20. link.setAttribute("href", fixedUri);
  21. }
  22.  
  23. for (let image of images) {
  24. let uri = image.getAttribute("src");
  25. let fixedUri = uri.replace(/ipfs\.greyh\.at/, "ninetailed.ninja");
  26. image.setAttribute("src", fixedUri);
  27.  
  28. console.log("Old URI: " + uri);
  29. console.log("New URI: " + fixedUri);
  30. }
  31. }
  32.  
  33. var lastTimeout;
  34. let observer = new MutationObserver((changes, observer) => {
  35. if (lastTimeout !== undefined) {
  36. window.clearTimeout(lastTimeout);
  37. }
  38.  
  39. lastTimeout = window.setTimeout(replaceAllUris, 200);
  40. });
  41. observer.observe(document, {childList: true, subtree: true});