68
|
1 // ==UserScript==
|
|
2 // @name suruga-ya fixes
|
|
3 // @namespace https://myconan.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
|
82
|
9 // @downloadURL https://hg.myconan.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
|
108
|
15 (function () {
|
|
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 }
|
108
|
23 })();
|
68
|
24
|
105
|
25 // skip loading image through php which seems to take forever
|
108
|
26 (function () {
|
|
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);
|
|
63 })();
|