68
|
1 // ==UserScript==
|
|
2 // @name suruga-ya fixes
|
|
3 // @namespace https://myconan.net
|
105
|
4 // @version 2.0.0
|
|
5 // @description Show all products with fast image
|
68
|
6 // @author nanaya
|
|
7 // @match https://www.suruga-ya.jp/*
|
|
8 // @grant none
|
82
|
9 // @downloadURL https://hg.myconan.net/ec-userscripts/raw-file/tip/surugaya-fixes.user.js
|
68
|
10 // ==/UserScript==
|
|
11
|
105
|
12 'use strict'
|
|
13
|
|
14 // always inject adult consent cookie
|
68
|
15 ;(function () {
|
|
16 const hasAdultCookie = document.cookie.split('; ').includes('adult=1')
|
105
|
17 if (!hasAdultCookie) {
|
|
18 const d = new Date()
|
|
19 d.setTime(d.getTime() + (100 * 24 * 60 * 60 * 1000))
|
|
20 document.cookie = `adult=1; expires=${d.toGMTString()}; path=/`
|
|
21 window.location.reload()
|
|
22 }
|
|
23 })()
|
68
|
24
|
105
|
25 // skip loading image through php which seems to take forever
|
|
26 ;(function () {
|
|
27 const itemImageRegexp = /photo\.php\?shinaban=(\d+)/
|
|
28 function fix (image) {
|
|
29 const origSrc = image.getAttribute('src')
|
|
30 if (origSrc == null) return
|
|
31 const found = origSrc.match(itemImageRegexp)
|
|
32 if (found == null) return
|
|
33
|
|
34 const src = `https://www.suruga-ya.jp/database/pics_light/game/${found[1]}.jpg`
|
|
35 const setNotFound = () => {
|
|
36 image.removeEventListener('error', setNotFound)
|
|
37 image.setAttribute('src', 'https://www.suruga-ya.jp/database/images/no_photo.jpg')
|
|
38 }
|
|
39 image.addEventListener('error', setNotFound)
|
|
40 image.setAttribute('src', src)
|
68
|
41 }
|
|
42
|
105
|
43 function run (node) {
|
|
44 if (!(node instanceof window.HTMLElement)) return
|
|
45
|
|
46 fix(node)
|
|
47 for (const image of node.querySelectorAll('img')) {
|
|
48 fix(image)
|
|
49 }
|
|
50 }
|
|
51
|
|
52 function onMutate (mutations) {
|
|
53 for (const mutation of mutations) {
|
|
54 for (const node of mutation.addedNodes) {
|
|
55 run(node)
|
|
56 }
|
|
57 }
|
|
58 }
|
|
59
|
|
60 const observer = new window.MutationObserver(onMutate)
|
|
61 observer.observe(document, { childList: true, subtree: true })
|
|
62 run(document.body)
|
|
63 })()
|