Mercurial > ec-userscripts
comparison mandarake-direct-link.user.js @ 117:d9dc190bccaf
Undo combining fixes into single script per site
author | nanaya <me@nanaya.net> |
---|---|
date | Sun, 15 Jan 2023 23:49:35 +0900 |
parents | ef21ef445fc6 |
children | 8de2d53a4cb1 |
comparison
equal
deleted
inserted
replaced
116:0e108a9dc6d7 | 117:d9dc190bccaf |
---|---|
11 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/mandarake-direct-link.user.js | 11 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/mandarake-direct-link.user.js |
12 // ==/UserScript== | 12 // ==/UserScript== |
13 | 13 |
14 'use strict'; | 14 'use strict'; |
15 | 15 |
16 function directLink () { | 16 const r18ConfirmLink = '#adult_confirm'; |
17 const r18ConfirmLink = '#adult_confirm'; | 17 function fixR18Link (link) { |
18 function fixR18Link (link) { | 18 if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return; |
19 if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return; | |
20 | 19 |
21 link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`); | 20 link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`); |
22 link.removeAttribute('class'); | 21 link.removeAttribute('class'); |
22 } | |
23 | |
24 function removeR18Mark (node) { | |
25 if (node.classList.contains('r18mark')) { | |
26 node.remove(); | |
27 return true; | |
23 } | 28 } |
24 | 29 |
25 function removeR18Mark (node) { | 30 for (const mark of node.querySelectorAll('.r18mark')) { |
26 if (node.classList.contains('r18mark')) { | 31 mark.remove(); |
27 node.remove(); | 32 } |
28 return true; | 33 } |
29 } | |
30 | 34 |
31 for (const mark of node.querySelectorAll('.r18mark')) { | 35 function run (node) { |
32 mark.remove(); | 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 | |
45 function onMutate (mutations) { | |
46 for (const mutation of mutations) { | |
47 for (const node of mutation.addedNodes) { | |
48 run(node); | |
33 } | 49 } |
34 } | 50 } |
35 | |
36 function run (node) { | |
37 if (!(node instanceof window.HTMLElement)) return; | |
38 if (removeR18Mark(node)) return; | |
39 | |
40 fixR18Link(node); | |
41 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) { | |
42 fixR18Link(link); | |
43 } | |
44 } | |
45 | |
46 function onMutate (mutations) { | |
47 for (const mutation of mutations) { | |
48 for (const node of mutation.addedNodes) { | |
49 run(node); | |
50 } | |
51 } | |
52 } | |
53 | |
54 const observer = new window.MutationObserver(onMutate); | |
55 observer.observe(document, { childList: true, subtree: true }); | |
56 run(document.body); | |
57 } | 51 } |
58 | 52 |
59 directLink(); | 53 const observer = new window.MutationObserver(onMutate); |
54 observer.observe(document, { childList: true, subtree: true }); | |
55 run(document.body); |