]> gitweb @ CieloNegro.org - imenu-relinker.git/blobdiff - imenu-relinker.user.js
Run the script at document-end
[imenu-relinker.git] / imenu-relinker.user.js
index 79c8fe05160c465014999ef15766a9eb9629d8ce..e9fb624355d6a20bd5703e1041a22f302e3a6c87 100644 (file)
@@ -3,9 +3,9 @@
 // @namespace    http://cielonegro.org/
 // @description  Fix links on 5ch.net BBS.
 // @author       PHO
-// @version      1.0
+// @version      1.0.1
 // @license      CC0
-// @run-at       document-idle
+// @run-at       document-end
 // @include      https://*.5ch.net/*
 // ==/UserScript==
 (function () {
         }
     }
 
+    function remove_ad_footer() {
+        // Starting from 2021-02-08, 5ch.net shows an iframe ad
+        // contained in several nested div elements. Dunno which
+        // script is doing it. -> Found. It was "ad.js"
+        var iframes = document.querySelectorAll("iframe");
+        for (var iframe of iframes.values()) {
+            if ((iframe.getAttribute("src") || "").startsWith("//stab.thench.net/")) {
+                // Found an iframe to be removed.
+                if (iframe.parentNode && iframe.parentNode.parentNode) {
+                    iframe.parentNode.parentNode.remove();
+                }
+            }
+        }
+    }
+
+    // Pop-up windows shown when hovered on >>n links are dynamically
+    // inserted to the DOM. Relink anchors in them as well.
+    let observer = new MutationObserver(relink_all);
+    observer.observe(document.querySelector("body"), {subtree: true, childList: true});
+
     relink_all();
+    remove_ad_footer();
 })();