2 // @name ime.nu relinker
3 // @namespace http://cielonegro.org/
4 // @description Fix links on 5ch.net BBS.
8 // @run-at document-idle
9 // @include https://*.5ch.net/*
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;
17 /* http://jump.5ch.net/? */
18 href = href.replace(/^http:\/\/jump\.5ch\.net\/\?/, "");
20 anchors[i].href = href;
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.
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();
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});