]> gitweb @ CieloNegro.org - imenu-relinker.git/blob - imenu-relinker.user.js
Run the script at document-end
[imenu-relinker.git] / imenu-relinker.user.js
1 // ==UserScript==
2 // @name         ime.nu relinker
3 // @namespace    http://cielonegro.org/
4 // @description  Fix links on 5ch.net BBS.
5 // @author       PHO
6 // @version      1.0.1
7 // @license      CC0
8 // @run-at       document-end
9 // @include      https://*.5ch.net/*
10 // ==/UserScript==
11 (function () {
12     function relink_all() {
13         var anchors = document.getElementsByTagName("a");
14         for (var i = 0; i < anchors.length; i++) {
15             var href = anchors[i].href;
16
17             /* http://jump.5ch.net/? */
18             href = href.replace(/^http:\/\/jump\.5ch\.net\/\?/, "");
19
20             anchors[i].href = href;
21         }
22     }
23
24     function remove_ad_footer() {
25         // Starting from 2021-02-08, 5ch.net shows an iframe ad
26         // contained in several nested div elements. Dunno which
27         // script is doing it. -> Found. It was "ad.js"
28         var iframes = document.querySelectorAll("iframe");
29         for (var iframe of iframes.values()) {
30             if ((iframe.getAttribute("src") || "").startsWith("//stab.thench.net/")) {
31                 // Found an iframe to be removed.
32                 if (iframe.parentNode && iframe.parentNode.parentNode) {
33                     iframe.parentNode.parentNode.remove();
34                 }
35             }
36         }
37     }
38
39     // Pop-up windows shown when hovered on >>n links are dynamically
40     // inserted to the DOM. Relink anchors in them as well.
41     let observer = new MutationObserver(relink_all);
42     observer.observe(document.querySelector("body"), {subtree: true, childList: true});
43
44     relink_all();
45     remove_ad_footer();
46 })();