68
|
1 // ==UserScript==
|
|
2 // @name suruga-ya fixes
|
109
|
3 // @namespace https://nanaya.net
|
107
|
4 // @version 2.0.2
|
105
|
5 // @description Show all products with fast image
|
68
|
6 // @author nanaya
|
|
7 // @match https://www.suruga-ya.jp/*
|
|
8 // @grant none
|
109
|
9 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/surugaya-fixes.user.js
|
68
|
10 // ==/UserScript==
|
|
11
|
108
|
12 'use strict';
|
105
|
13
|
|
14 // always inject adult consent cookie
|
109
|
15 function alwaysConsent () {
|
108
|
16 const hasAdultCookie = document.cookie.split('; ').includes('adult=1');
|
105
|
17 if (!hasAdultCookie) {
|
108
|
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();
|
105
|
22 }
|
109
|
23 }
|
68
|
24
|
105
|
25 // skip loading image through php which seems to take forever
|
109
|
26 function directImage () {
|
108
|
27 const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/;
|
105
|
28 function fix (image) {
|
108
|
29 const origSrc = image.getAttribute('src');
|
|
30 if (origSrc == null) return;
|
|
31 const found = origSrc.match(itemImageRegexp);
|
|
32 if (found == null) return;
|
105
|
33
|
108
|
34 const src = `https://www.suruga-ya.jp/database/pics_light/game/${found[1].toLowerCase()}.jpg`;
|
105
|
35 const setNotFound = () => {
|
108
|
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) {
|
108
|
44 if (!(node instanceof window.HTMLElement)) return;
|
105
|
45
|
108
|
46 fix(node);
|
105
|
47 for (const image of node.querySelectorAll('img')) {
|
108
|
48 fix(image);
|
105
|
49 }
|
|
50 }
|
|
51
|
|
52 function onMutate (mutations) {
|
|
53 for (const mutation of mutations) {
|
|
54 for (const node of mutation.addedNodes) {
|
108
|
55 run(node);
|
105
|
56 }
|
|
57 }
|
|
58 }
|
|
59
|
108
|
60 const observer = new window.MutationObserver(onMutate);
|
|
61 observer.observe(document, { childList: true, subtree: true });
|
|
62 run(document.body);
|
109
|
63 }
|
|
64
|
|
65 alwaysConsent();
|
|
66 directImage();
|