# HG changeset patch # User nanaya # Date 1673794016 -32400 # Node ID 0e108a9dc6d74cbefdb87261e021d42b3b534d41 # Parent 7774174022af0e5a7e3f00476379b7a2de1eeaf6 Split suruga-ya scripts diff -r 7774174022af -r 0e108a9dc6d7 surugaya-always-consent.user.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/surugaya-always-consent.user.js Sun Jan 15 23:46:56 2023 +0900 @@ -0,0 +1,20 @@ +// ==UserScript== +// @name suruga-ya always consent +// @namespace https://nanaya.net +// @version 2.0.2 +// @description always inject adult consent cookie +// @author nanaya +// @match https://www.suruga-ya.jp/* +// @grant none +// @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/surugaya-always-consent.user.js +// ==/UserScript== + +'use strict'; + +const hasAdultCookie = document.cookie.split('; ').includes('adult=1'); +if (!hasAdultCookie) { + const d = new Date(); + d.setTime(d.getTime() + (100 * 24 * 60 * 60 * 1000)); + document.cookie = `adult=1; expires=${d.toGMTString()}; path=/`; + window.location.reload(); +} diff -r 7774174022af -r 0e108a9dc6d7 surugaya-direct-image.user.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/surugaya-direct-image.user.js Sun Jan 15 23:46:56 2023 +0900 @@ -0,0 +1,49 @@ +// ==UserScript== +// @name suruga-ya direct image +// @namespace https://nanaya.net +// @version 2.0.3 +// @description skip loading image through php which seems to take forever +// @author nanaya +// @match https://www.suruga-ya.jp/* +// @grant none +// @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/surugaya-fixes.user.js +// ==/UserScript== + +'use strict'; + +const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/; +function fix (image) { + const origSrc = image.getAttribute('src'); + if (origSrc == null) return; + const found = origSrc.match(itemImageRegexp); + if (found == null) return; + + const src = `https://www.suruga-ya.jp/database/pics_light/game/${found[1].toLowerCase()}.jpg`; + const setNotFound = () => { + image.removeEventListener('error', setNotFound); + image.setAttribute('src', 'https://www.suruga-ya.jp/database/images/no_photo.jpg'); + }; + image.addEventListener('error', setNotFound); + image.setAttribute('src', src); +} + +function run (node) { + if (!(node instanceof window.HTMLElement)) return; + + fix(node); + for (const image of node.querySelectorAll('img')) { + fix(image); + } +} + +function onMutate (mutations) { + for (const mutation of mutations) { + for (const node of mutation.addedNodes) { + run(node); + } + } +} + +const observer = new window.MutationObserver(onMutate); +observer.observe(document, { childList: true, subtree: true }); +run(document.body); diff -r 7774174022af -r 0e108a9dc6d7 surugaya-fixes.user.js --- a/surugaya-fixes.user.js Sun Jan 15 23:43:44 2023 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -// ==UserScript== -// @name suruga-ya fixes -// @namespace https://nanaya.net -// @version 2.0.2 -// @description Show all products with fast image -// @author nanaya -// @match https://www.suruga-ya.jp/* -// @grant none -// @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/surugaya-fixes.user.js -// ==/UserScript== - -'use strict'; - -// always inject adult consent cookie -function alwaysConsent () { - const hasAdultCookie = document.cookie.split('; ').includes('adult=1'); - if (!hasAdultCookie) { - const d = new Date(); - d.setTime(d.getTime() + (100 * 24 * 60 * 60 * 1000)); - document.cookie = `adult=1; expires=${d.toGMTString()}; path=/`; - window.location.reload(); - } -} - -// skip loading image through php which seems to take forever -function directImage () { - const itemImageRegexp = /photo\.php\?shinaban=([0-9A-Z]+)/; - function fix (image) { - const origSrc = image.getAttribute('src'); - if (origSrc == null) return; - const found = origSrc.match(itemImageRegexp); - if (found == null) return; - - const src = `https://www.suruga-ya.jp/database/pics_light/game/${found[1].toLowerCase()}.jpg`; - const setNotFound = () => { - image.removeEventListener('error', setNotFound); - image.setAttribute('src', 'https://www.suruga-ya.jp/database/images/no_photo.jpg'); - }; - image.addEventListener('error', setNotFound); - image.setAttribute('src', src); - } - - function run (node) { - if (!(node instanceof window.HTMLElement)) return; - - fix(node); - for (const image of node.querySelectorAll('img')) { - fix(image); - } - } - - function onMutate (mutations) { - for (const mutation of mutations) { - for (const node of mutation.addedNodes) { - run(node); - } - } - } - - const observer = new window.MutationObserver(onMutate); - observer.observe(document, { childList: true, subtree: true }); - run(document.body); -} - -alwaysConsent(); -directImage();