Toffu

Autofills Woffu schedule

目前為 2022-01-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Toffu
// @namespace    http://yelidmod.com/trendier
// @version      0.4
// @description  Autofills Woffu schedule
// @author       DonNadie
// @match        https://*.woffu.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const autofillFields = () => {
        const $modal = document.getElementById('diary-edit');

        $modal.querySelectorAll('input').forEach((input, i) => {
            if (input.value.length < 1) {
                input.focus();
                input.value = input.placeholder.substr(0, 5); // from 19:00:00 to 19:00
                input.dispatchEvent(new Event('change'));
            }
        });
    };

    window.addEventListener('load', () => {
        const observer = new MutationObserver(() => {
            autofillFields();

            setTimeout(autofillFields, 2000); // does not always seem to work at first, so just retry it again
        });
        const $modal = document.getElementById('diary-edit');

        if ($modal != null) {
            observer.observe($modal, {
                childList: true,
                subtree: true
            });
        }
    }, false);
})();