AniBrain: replace JavaScript links

Replaces JS links using proper links that allow 'Right-click > Open in new tab' and other stuff

  1. // ==UserScript==
  2. // @name AniBrain: replace JavaScript links
  3. // @version 2023-12-31
  4. // @description Replaces JS links using proper links that allow 'Right-click > Open in new tab' and other stuff
  5. // @author thepbone
  6. // @match https://anibrain.ai/*
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=anibrain.ai
  8. // @grant none
  9. // @license GPLv3
  10. // @run-at document-idle
  11. // @namespace https://greasyfork.org/users/174601
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17.  
  18. function fixLinks() {
  19. console.log("Fixing links");
  20.  
  21. var mangaDivs = document.getElementsByTagName("div");
  22.  
  23.  
  24. for (var i = mangaDivs.length -1 ; i >=0; i--) {
  25. var div = mangaDivs[i];
  26. if(!div.id.startsWith("mrc-Manga-")) {
  27. console.log("skip " + div.id);
  28. continue;
  29. }
  30.  
  31. console.log("DONE " + div.id);
  32.  
  33. var p = document.createElement("a");
  34. p.setAttribute("href", div.id.match(/\d/g).join(''));
  35. var newDiv = div.cloneNode(true);
  36. newDiv.removeAttribute("id");
  37. p.appendChild(newDiv);
  38. div.parentNode.insertBefore(p, div);
  39. div.parentNode.removeChild(div);
  40. }
  41. }
  42.  
  43. var count = 0;
  44.  
  45. var currentInterval = 0;
  46. var x = new MutationObserver(function (e) {
  47. if(count >= 10) {
  48. x.disconnect();
  49. }
  50.  
  51. if (e[0].addedNodes) {
  52. if(currentInterval != 0) {
  53. clearInterval(currentInterval);
  54. }
  55.  
  56. currentInterval = setInterval(function(){
  57. currentInterval = 0;
  58. fixLinks();
  59. }, 1000);
  60.  
  61. count++;
  62. }
  63. });
  64.  
  65. x.observe(document.getElementsByTagName('main')[0], { childList: true, subTree: true });
  66. })();