Toffu

Autofills Woffu schedule

目前為 2023-09-08 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Toffu
// @namespace    http://yelidmod.com/trendier
// @version      0.5
// @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');
        const $inputs = $modal.querySelectorAll('input');
        const timeMap = {
            0: "08:00",
            1: "13:00",
            2: "14:00",
            3: "17:00",
        };

        if($inputs.length === 2){
            $modal.querySelector("a.ng-binding").click();
        }

        $inputs.forEach((input, i) => {

            if (input.value.length < 1) {
                input.focus();

                if (typeof timeMap[i] !== "undefined") {
                    input.value = timeMap[i];
                    input.dispatchEvent(new Event('change'));
                }
            }
        });
    };

    window.addEventListener('load', () => {
        setInterval(autofillFields, 500);
    });
})();