comparison mandarake-direct-link.user.js @ 104:93e21738b588

Run fix on whole body on start There's no guarantee the script loads before document.
author nanaya <me@nanaya.net>
date Sun, 25 Dec 2022 11:52:30 +0900
parents b2d0b37f945f
children 2c4470b73ad9
comparison
equal deleted inserted replaced
103:b2d0b37f945f 104:93e21738b588
1 // ==UserScript== 1 // ==UserScript==
2 // @name mandarake direct link 2 // @name mandarake direct link
3 // @namespace https://myconan.net 3 // @namespace https://myconan.net
4 // @version 2.0.0 4 // @version 2.0.1
5 // @description Make proper link on mandarake pages 5 // @description Make proper link on mandarake pages
6 // @author nanaya 6 // @author nanaya
7 // @match https://order.mandarake.co.jp/* 7 // @match https://order.mandarake.co.jp/*
8 // @match http://order.mandarake.co.jp/* 8 // @match http://order.mandarake.co.jp/*
9 // @grant none 9 // @grant none
30 for (const mark of node.querySelectorAll('.r18mark')) { 30 for (const mark of node.querySelectorAll('.r18mark')) {
31 mark.remove() 31 mark.remove()
32 } 32 }
33 } 33 }
34 34
35 function run (node) {
36 if (!(node instanceof window.HTMLElement)) return
37 if (removeR18Mark(node)) return
38
39 fixR18Link(node)
40 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) {
41 fixR18Link(link)
42 }
43 }
44
35 function onMutate (mutations) { 45 function onMutate (mutations) {
36 for (const mutation of mutations) { 46 for (const mutation of mutations) {
37 for (const node of mutation.addedNodes) { 47 for (const node of mutation.addedNodes) {
38 if (node instanceof window.HTMLElement) { 48 run(node)
39 if (removeR18Mark(node)) continue
40
41 fixR18Link(node)
42 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) {
43 fixR18Link(link)
44 }
45 }
46 } 49 }
47 } 50 }
48 } 51 }
49 52
50 const observer = new window.MutationObserver(onMutate) 53 const observer = new window.MutationObserver(onMutate)
51 observer.observe(document, { childList: true, subtree: true }) 54 observer.observe(document, { childList: true, subtree: true })
55 run(document.body)