Mercurial > ec-userscripts
comparison surugaya-fixes.user.js @ 109:ef21ef445fc6
Cleanups
- wrap everything in function and call them last
- fix namespace and update url
author | nanaya <me@nanaya.net> |
---|---|
date | Sun, 15 Jan 2023 23:33:41 +0900 |
parents | 2c4470b73ad9 |
children |
comparison
equal
deleted
inserted
replaced
108:2c4470b73ad9 | 109:ef21ef445fc6 |
---|---|
1 // ==UserScript== | 1 // ==UserScript== |
2 // @name suruga-ya fixes | 2 // @name suruga-ya fixes |
3 // @namespace https://myconan.net | 3 // @namespace https://nanaya.net |
4 // @version 2.0.2 | 4 // @version 2.0.2 |
5 // @description Show all products with fast image | 5 // @description Show all products with fast image |
6 // @author nanaya | 6 // @author nanaya |
7 // @match https://www.suruga-ya.jp/* | 7 // @match https://www.suruga-ya.jp/* |
8 // @grant none | 8 // @grant none |
9 // @downloadURL https://hg.myconan.net/ec-userscripts/raw-file/tip/surugaya-fixes.user.js | 9 // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/surugaya-fixes.user.js |
10 // ==/UserScript== | 10 // ==/UserScript== |
11 | 11 |
12 'use strict'; | 12 'use strict'; |
13 | 13 |
14 // always inject adult consent cookie | 14 // always inject adult consent cookie |
15 (function () { | 15 function alwaysConsent () { |
16 const hasAdultCookie = document.cookie.split('; ').includes('adult=1'); | 16 const hasAdultCookie = document.cookie.split('; ').includes('adult=1'); |
17 if (!hasAdultCookie) { | 17 if (!hasAdultCookie) { |
18 const d = new Date(); | 18 const d = new Date(); |
19 d.setTime(d.getTime() + (100 * 24 * 60 * 60 * 1000)); | 19 d.setTime(d.getTime() + (100 * 24 * 60 * 60 * 1000)); |
20 document.cookie = `adult=1; expires=${d.toGMTString()}; path=/`; | 20 document.cookie = `adult=1; expires=${d.toGMTString()}; path=/`; |
21 window.location.reload(); | 21 window.location.reload(); |
22 } | 22 } |
23 })(); | 23 } |
24 | 24 |
25 // skip loading image through php which seems to take forever | 25 // skip loading image through php which seems to take forever |
26 (function () { | 26 function directImage () { |
27 const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/; | 27 const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/; |
28 function fix (image) { | 28 function fix (image) { |
29 const origSrc = image.getAttribute('src'); | 29 const origSrc = image.getAttribute('src'); |
30 if (origSrc == null) return; | 30 if (origSrc == null) return; |
31 const found = origSrc.match(itemImageRegexp); | 31 const found = origSrc.match(itemImageRegexp); |
58 } | 58 } |
59 | 59 |
60 const observer = new window.MutationObserver(onMutate); | 60 const observer = new window.MutationObserver(onMutate); |
61 observer.observe(document, { childList: true, subtree: true }); | 61 observer.observe(document, { childList: true, subtree: true }); |
62 run(document.body); | 62 run(document.body); |
63 })(); | 63 } |
64 | |
65 alwaysConsent(); | |
66 directImage(); |