annotate mandarake-direct-link.user.js @ 103:b2d0b37f945f

Update mandarake script - update download url - remove iife - run at document start - use observer - remove search link fixer (seems to be fixed already)
author nanaya <me@nanaya.net>
date Sat, 24 Dec 2022 22:10:30 +0900
parents 9c8cde985caf
children 93e21738b588
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
Edho Arief <me@myconan.net>
parents:
diff changeset
1 // ==UserScript==
Edho Arief <me@myconan.net>
parents:
diff changeset
2 // @name mandarake direct link
Edho Arief <me@myconan.net>
parents:
diff changeset
3 // @namespace https://myconan.net
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
4 // @version 2.0.0
16
Edho Arief <me@myconan.net>
parents:
diff changeset
5 // @description Make proper link on mandarake pages
Edho Arief <me@myconan.net>
parents:
diff changeset
6 // @author nanaya
Edho Arief <me@myconan.net>
parents:
diff changeset
7 // @match https://order.mandarake.co.jp/*
18
Edho Arief <me@myconan.net>
parents: 17
diff changeset
8 // @match http://order.mandarake.co.jp/*
16
Edho Arief <me@myconan.net>
parents:
diff changeset
9 // @grant none
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
10 // @run-at document-start
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
11 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/mandarake-direct-link.user.js
16
Edho Arief <me@myconan.net>
parents:
diff changeset
12 // ==/UserScript==
Edho Arief <me@myconan.net>
parents:
diff changeset
13
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
14 'use strict'
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
15
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
16 const r18ConfirmLink = '#adult_confirm'
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
17 function fixR18Link (link) {
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
18 if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return
51
f0d5a5d80bfd Remove extra element
nanaya <me@nanaya.pro>
parents: 49
diff changeset
19
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
20 link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`)
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
21 link.removeAttribute('class')
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
22 }
51
f0d5a5d80bfd Remove extra element
nanaya <me@nanaya.pro>
parents: 49
diff changeset
23
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
24 function removeR18Mark (node) {
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
25 if (node.classList.contains('r18mark')) {
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
26 node.remove()
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
27 return true
66
444b17e657be Standardize code style
nanaya <me@nanaya.pro>
parents: 58
diff changeset
28 }
16
Edho Arief <me@myconan.net>
parents:
diff changeset
29
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
30 for (const mark of node.querySelectorAll('.r18mark')) {
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
31 mark.remove()
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
32 }
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
33 }
48
b60f0fd9c417 Update mandarake script
nanaya <me@nanaya.pro>
parents: 35
diff changeset
34
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
35 function onMutate (mutations) {
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
36 for (const mutation of mutations) {
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
37 for (const node of mutation.addedNodes) {
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
38 if (node instanceof window.HTMLElement) {
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
39 if (removeR18Mark(node)) continue
48
b60f0fd9c417 Update mandarake script
nanaya <me@nanaya.pro>
parents: 35
diff changeset
40
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
41 fixR18Link(node)
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
42 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) {
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
43 fixR18Link(link)
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
44 }
48
b60f0fd9c417 Update mandarake script
nanaya <me@nanaya.pro>
parents: 35
diff changeset
45 }
b60f0fd9c417 Update mandarake script
nanaya <me@nanaya.pro>
parents: 35
diff changeset
46 }
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
47 }
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
48 }
48
b60f0fd9c417 Update mandarake script
nanaya <me@nanaya.pro>
parents: 35
diff changeset
49
103
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
50 const observer = new window.MutationObserver(onMutate)
b2d0b37f945f Update mandarake script
nanaya <me@nanaya.net>
parents: 85
diff changeset
51 observer.observe(document, { childList: true, subtree: true })