Created
February 5, 2025 09:02
-
-
Save xim/8cdd8252aebceda600d7ce6ea612a036 to your computer and use it in GitHub Desktop.
userscript that remembers the "gap" setting per manga on weebcentral.com
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 WeebCentral page gap persisting | |
// @namespace https://gist.github.com/xim | |
// @version 2025-02-05 | |
// @description Script that remembers the "gap" setting per manga | |
// @author xim | |
// @match https://weebcentral.com/chapters/* | |
// @downloadURL https://gist.github.com/xim/8cdd8252aebceda600d7ce6ea612a036/raw/weebcentral-gap-persisting.user.js | |
// @updateURL https://gist.github.com/xim/8cdd8252aebceda600d7ce6ea612a036/raw/weebcentral-gap-persisting.user.js | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=weebcentral.com | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// ==/UserScript== | |
function set_gap(manga, gap) { | |
console.log('set_gap', manga, gap); | |
var data = JSON.parse(GM_getValue('pageGaps', '{}')); | |
data[manga] = gap; | |
GM_setValue('pageGaps', JSON.stringify(data)); | |
} | |
(function() { | |
'use strict'; | |
const manga = document.querySelector('a[href^="https://weebcentral.com/series/"]:not([href="https://weebcentral.com/series/random"])').href.split('/').at(-1); | |
console.log(manga); | |
if (!manga) { | |
console.log('Unable to determine manga name'); | |
return; | |
} | |
const button = document.querySelector('input[x-model="gap"]'); | |
var gap = button.checked; | |
const clone = button.cloneNode(true); | |
function toggle() { | |
button.click(); | |
clone.checked = button.checked; | |
} | |
clone.onclick = function() { | |
gap = !gap; | |
set_gap(manga, gap); | |
toggle(); | |
}; | |
button.style.setProperty('display', 'none', 'important'); | |
button.insertAdjacentElement('afterend', clone); | |
document.addEventListener("keyup", e => { | |
if (e.key === 'g' && !(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) { | |
gap = !gap; | |
set_gap(manga, gap); | |
} | |
}); | |
const data = JSON.parse(GM_getValue('pageGaps', "{}")); | |
if (data[manga] !== undefined && data[manga] !== gap) { | |
gap = data[manga]; | |
console.log('Setting', manga, 'gap to', gap, 'because of persisted data'); | |
toggle(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment