Skip to content

Instantly share code, notes, and snippets.

@xim
Created February 5, 2025 09:02

Revisions

  1. xim revised this gist Feb 5, 2025. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions weebcentral-gap-persisting.user.js
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@
    // @description Script that remembers the "gap" setting per manga
    // @author xim
    // @match https://weebcentral.com/chapters/*
    // @downloadURL https://gist.github.com/xim/TODO/raw/weebcentral-gap-persisting.user.js
    // @updateURL https://gist.github.com/xim/TODO/raw/weebcentral-gap-persisting.user.js
    // @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
  2. xim created this gist Feb 5, 2025.
    62 changes: 62 additions & 0 deletions weebcentral-gap-persisting.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    // ==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/TODO/raw/weebcentral-gap-persisting.user.js
    // @updateURL https://gist.github.com/xim/TODO/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();
    }
    })();