Skip to content

Instantly share code, notes, and snippets.

@pastak
Last active March 1, 2021 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pastak/bf3ac6fb523a3730a571f9e0edcf3353 to your computer and use it in GitHub Desktop.
Save pastak/bf3ac6fb523a3730a571f9e0edcf3353 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name コミックDAYSのイラストを実寸表示できるようにする
// @namespace pastak.net.comic-days.illustration.zooming
// @description
// @match https://comic-days.com/illustration/*
// @includes https://comic-days.com/illustration/*
// ==/UserScript==
'use strict';
function waitForSelector (selectors) {
return new Promise((resolve) => {
const timerId = setInterval(() => {
if (document.querySelector(selectors.join(','))) {
clearInterval(timerId);
resolve();
}
}, 100);
});
};
(async () => {
if (!location.href.startsWith('https://comic-days.com/illustration/')) return;
const renderIllustSelectors = [
'.illustration-viewer-content .illustration-pages canvas',
'.illustration-viewer-content .illustration-pages img'
];
await waitForSelector(renderIllustSelectors);
const s = document.createElement('style');
document.head.appendChild(s);
const fullSizingSelectors = renderIllustSelectors.map((selector) => `${selector}.full-size`).join(', ');
s.innerHTML = (`
${renderIllustSelectors.join(',')} {
cursor: zoom-in;
pointer-events: auto;
}
${fullSizingSelectors} {
max-height: none;
max-width: none;
cursor: zoom-out;
}
`);
document.querySelectorAll(renderIllustSelectors.join(',')).forEach((elm) => {
let isFullSized = false;
elm.addEventListener('click', () => {
isFullSized = !isFullSized;
elm.classList.toggle('full-size', isFullSized);
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment