udo80 / gs-form-hide

// ==UserScript==
// @namespace https://openuser.js.org/users/udo80
// @name      gs-form-hide
// @description Hide form elements
// @copyright 2018, Udo Woitek (https://openuserjs.org/users/udo80)
// @license   Apache-2.0
// @version   0.0.2
// @include https://www.geocaching.com/pocket/gcquery.aspx*
// @grant     none
// @run-at    document-idle
// ==/UserScript==


(function () {
    function getDate() {
        var year = Number(endDateYear.value).valueOf();
        var month = Number(endDateMonth.selectedIndex).valueOf();
        var day = Number(endDateDay.value).valueOf();
        return new Date(year, month, day);
    }
    function changeDate(date, offset) {
        date.setDate(date.getDate() + offset);
        return date;
    }
    function changeDateSelectors(offset) {
        var current = getDate();
        console.log("got date: ", current);
        current = changeDate(current, offset);
        console.log("changed date: ", current);
        var d = current.getDate();
        var m = current.getMonth();
        var y = current.getFullYear();
        console.log("d-m-y", d, m, y);
        endDateDay.selectedIndex = d - 1;
        endDateMonth.selectedIndex = m;
        endDateYear.selectedIndex = endDateYear.options.length - (y - 2000) - 1;
        btnSubmit.click();
    }
    function createButton(offset) {
        var plusDayBtn = document.createElement("button");
        plusDayBtn.type = "button";
        plusDayBtn.textContent = offset;
        plusDayBtn.addEventListener("click", function (e) {
            changeDateSelectors(Number(offset).valueOf());
            e.stopImmediatePropagation();
            e.stopPropagation();
        });
        return plusDayBtn;
    }
    function createNewStartDateButton() {
        var newButton = document.createElement("button");
        newButton.type = "button";
        newButton.textContent = "<==";
        newButton.addEventListener("click", function (ev) {
            var d = changeDate(getDate(), +1);
            beginDateDay.selectedIndex = d.getDate() - 1;
            beginDateMonth.selectedIndex = d.getMonth();
            beginDateYear.selectedIndex = beginDateYear.options.length - (d.getFullYear() - 2000) - 1;
            var d2 = changeDate(getDate(), +40);
            endDateDay.selectedIndex = d2.getDate() - 1;
            endDateMonth.selectedIndex = d2.getMonth();
            endDateYear.selectedIndex = endDateYear.options.length - (d2.getFullYear() - 2000) - 1;
        });
        return newButton;
    }
    var fieldsets = document.querySelectorAll("fieldset.BottomSpacing");
    for (var i = 0; i < fieldsets.length; ++i) {
        if (i !== 6) {
            fieldsets[i].style.display = "none";
        }
    }
    var btnSubmit = document.getElementById("ctl00_ContentBody_btnSubmit");
    var endDateDay = document.getElementById("ctl00_ContentBody_DateTimeEnd_Day");
    var endDateMonth = document.getElementById("ctl00_ContentBody_DateTimeEnd_Month");
    var endDateYear = document.getElementById("ctl00_ContentBody_DateTimeEnd_Year");
    var beginDateDay = document.getElementById("ctl00_ContentBody_DateTimeBegin_Day");
    var beginDateMonth = document.getElementById("ctl00_ContentBody_DateTimeBegin_Month");
    var beginDateYear = document.getElementById("ctl00_ContentBody_DateTimeBegin_Year");
    var form = document.getElementsByTagName("form")[0];
    btnSubmit.parentElement.insertBefore(createButton("-10"), btnSubmit);
    btnSubmit.parentElement.insertBefore(createButton("-5"), btnSubmit);
    btnSubmit.parentElement.insertBefore(createButton("-1"), btnSubmit);
    btnSubmit.parentElement.insertBefore(createButton("+1"), btnSubmit);
    btnSubmit.parentElement.insertBefore(createButton("+5"), btnSubmit);
    btnSubmit.parentElement.insertBefore(createButton("+10"), btnSubmit);
    btnSubmit.parentElement.insertBefore(document.createElement("p"), btnSubmit);
    btnSubmit.parentElement.insertBefore(createNewStartDateButton(), btnSubmit);
    btnSubmit.parentElement.insertBefore(document.createElement("p"), btnSubmit);
})();
//# sourceMappingURL=main.js.map