comparison 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
comparison
equal deleted inserted replaced
102:3fded109e23a 103:b2d0b37f945f
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 1.3.6 4 // @version 2.0.0
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
10 // @downloadURL https://hg.myconan.net/ec-userscripts/raw-file/tip/mandarake-direct-link.user.js 10 // @run-at document-start
11 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/mandarake-direct-link.user.js
11 // ==/UserScript== 12 // ==/UserScript==
12 13
13 /* global $ */ 14 'use strict'
14 ;(function () {
15 'use strict'
16 15
17 $('.r18mark').remove() 16 const r18ConfirmLink = '#adult_confirm'
18 $(".r18item ~ a[href^='#adult_confirm']").remove() 17 function fixR18Link (link) {
18 if (!(link instanceof window.HTMLAnchorElement) || link.getAttribute('href') !== r18ConfirmLink) return
19 19
20 const fixR18Link = function (_i, el) { 20 link.setAttribute('href', `/order/detailPage/item?itemCode=${link.id}`)
21 const url = `/order/detailPage/item?itemCode=${el.id}` 21 link.removeAttribute('class')
22 }
22 23
23 el.setAttribute('href', url) 24 function removeR18Mark (node) {
24 el.setAttribute('class', '') 25 if (node.classList.contains('r18mark')) {
26 node.remove()
27 return true
25 } 28 }
26 29
27 $("[href^='#adult_confirm']").each(fixR18Link) 30 for (const mark of node.querySelectorAll('.r18mark')) {
31 mark.remove()
32 }
33 }
28 34
29 const currentQuery = new URLSearchParams(window.location.search) 35 function onMutate (mutations) {
30 const fixSearchLink = function (_i, el) { 36 for (const mutation of mutations) {
31 const query = new URLSearchParams(el.search) 37 for (const node of mutation.addedNodes) {
38 if (node instanceof window.HTMLElement) {
39 if (removeR18Mark(node)) continue
32 40
33 for (const [key, value] of currentQuery) { 41 fixR18Link(node)
34 if (!query.has(key)) { 42 for (const link of node.querySelectorAll(`a[href='${r18ConfirmLink}']`)) {
35 query.set(key, value) 43 fixR18Link(link)
44 }
36 } 45 }
37 } 46 }
47 }
48 }
38 49
39 el.setAttribute('href', `/order/listPage/list?${query.toString()}`) 50 const observer = new window.MutationObserver(onMutate)
40 } 51 observer.observe(document, { childList: true, subtree: true })
41
42 $("[href^='/order/listPage/list?']").each(fixSearchLink)
43 }).call()