Last active
February 12, 2022 14:38
-
-
Save fredgido/7909794195d65d1f923876cc7503dde5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name I see cute girls | |
// @namespace ISCG | |
// @version 0.00000001 | |
// @description ... | |
// @author made by fredgy-kun | |
// @match https://*.donmai.us/posts* | |
// @match https://*.donmai.us/ | |
// @exclude https://*.donmai.us/posts/* | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
let tsize = localStorage.getItem(`tsize`)|0; | |
tsize = tsize > 0 ? tsize : 483; | |
let tcheck = localStorage.getItem(`tcheck`) !== `false`; | |
const extWhitelist = new Set([`.png`, `.jpg`, `.gif`]); | |
let thumbsParent =document.getElementsByClassName('post-gallery-grid')[0]; | |
let iscgControls; | |
if (!document.getElementById(`iscgControls`)) { | |
document.getElementById(`subnav-menu`).insertAdjacentHTML(`beforeend`, | |
`<li id='iscgControls' style='--iscg-tsize-str:"";'> | |
<input type='range' min='150' max='700' value='${tsize|0}' id='iscgSlider' style='width: 200px;'> | |
<input type='checkbox' ${tcheck ? `checked` : ``} id='iscgCheckbox'> | |
<span id='iscgOutput'></span> | |
</li>`); | |
document.head.insertAdjacentHTML(`beforeend`, | |
`<style id='iscgStylesheet'> | |
.iscgEnabled article.post-preview img{ | |
height: auto !important; | |
width: auto !important; | |
} | |
.iscgEnabled article.post-preview img { | |
max-width: var(--iscg-tsize) !important; | |
max-height: var(--iscg-tsize) !important; | |
display: inline-table; | |
} | |
.post-gallery-grid.post-gallery-150 .posts-container { | |
grid-template-columns: repeat(auto-fill, minmax(var(--iscg-tsize), 1fr)); | |
} | |
.post-preview img { | |
border: 3px !important; | |
} | |
#iscgOutput::before { | |
content: var(--iscg-tsize-str); | |
} | |
</style>`); | |
iscgControls = document.getElementById(`iscgControls`); | |
} | |
document.getElementById(`iscgSlider`).oninput = function () { | |
tsize = this.value; | |
if (tcheck){ | |
applyTsize(); | |
} | |
localStorage.setItem(`tsize`, tsize); | |
} | |
document.getElementById(`iscgCheckbox`).onclick = function () { | |
tsize = localStorage.getItem(`tsize`); | |
tcheck = this.checked; | |
if (!tcheck) { | |
tsize = 150;} | |
alterThumbs(); | |
applyTsize(); | |
localStorage.setItem(`tcheck`, tcheck); | |
}; | |
function applyTsize() { | |
thumbsParent.classList.toggle(`iscgEnabled`, tcheck); | |
thumbsParent.style.setProperty(`--iscg-tsize`, `${tsize|0}px`); | |
iscgControls.style.setProperty(`--iscg-tsize-str`, `'${tsize|0}px'`); | |
} | |
function alterThumbs() { | |
for (let thumb of thumbsParent.getElementsByClassName(`post-preview`)) { | |
let url = null; | |
if (tcheck) {/* use samples: */ | |
let sampUrl = tryParseHref(thumb.dataset.largeFileUrl); | |
if (sampUrl && extWhitelist.has(sampUrl.pathname.slice(-4).toLowerCase())) { | |
url = sampUrl;} | |
} else {/* revert back to thumbnails: */ | |
url = tryParseHref(thumb.dataset.previewFileUrl); | |
} | |
if (url) { | |
let el = thumb.querySelectorAll("img")[0]; | |
if(el){ | |
el.src = url; | |
} | |
/*for (let s of thumb.querySelectorAll("img")[0]) { | |
s.srcset = url.href;} | |
*/ | |
/* load-balancing idea: | |
= sampUrl.href.replace(/(:\/\/\w+\.)/, [ "://shima.", "://saitou.", "://kagamihara."][Math.floor(Math.random() * 3)]);}) */ | |
} | |
} | |
} | |
function initialise() { | |
if (tcheck) {alterThumbs();} | |
applyTsize(); | |
} | |
initialise(); | |
$(document).on(`danbooru:post-preview-updated`, initialise); //breakes if not inside unrelated https://stackoverflow.com/a/524721 | |
function tryParseHref(href) { | |
try { | |
return new URL(href); | |
} catch (x) { | |
return null;}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script is no longer working. 😭
Can you please update it?