diff options
| -rw-r--r-- | misc/usps-fill-out-scheduled-pickup.user.js | 105 |
1 files changed, 71 insertions, 34 deletions
diff --git a/misc/usps-fill-out-scheduled-pickup.user.js b/misc/usps-fill-out-scheduled-pickup.user.js index 2328fe7..414eaba 100644 --- a/misc/usps-fill-out-scheduled-pickup.user.js +++ b/misc/usps-fill-out-scheduled-pickup.user.js @@ -2,43 +2,83 @@ // @name Fill out usps scheduled pickup // @namespace Violentmonkey Scripts // @match https://tools.usps.com/schedule-pickup-steps.htm* -// @grant none -// @version 1.0 +// @grant GM_getValue +// @grant GM_setValue +// @grant GM_registerMenuCommand +// @downloadURL https://git.tjkeller.xyz/userscripts/plain/misc/usps-fill-out-scheduled-pickup.user.js +// @version 2.0 // @author tjkeller.xyz // @description 2/11/2024, 7:23:34 PM // ==/UserScript== -/* First page config */ -const fill = { - emailAddress: "youremail@example.com", - phoneNumber: "777-777-7777", - zipCode: "60606", - state: "IL", - city: "CHICAGO", - addressLineOne: "701 My Lovely Home St.", - lastName: "Smith", - firstName: "John" +/* Save/load data */ +const initialFields = [ + "addressLineOne", + "addressLineTwo", + "city", + "emailAddress", + "firstName", + "isBusinessAddress", + "lastName", + "middleInitial", + "phoneExt", + "phoneNumber", + "state", + "zipCode", +] +const otherFields = [ + "first-radio-verification", + "packageLocation", + "second-radio-verification", + "step-two-desc-item-textarea", +] +function isCheckable(input) { return input.type == "checkbox" || input.type == "radio" } +function saveFilledData(key, fieldNames) { + const data = {} + for (let fieldName of fieldNames) { + const input = document.getElementById(fieldName) + if (!input) { + //alert(`Failed to save. Not all fields are filled. Make sure to continue after "Check Availability"`) + alert(`Field "${fieldName}" not found`) + return false + } + const label = input.previousElementSibling + const required = label ? label.innerText.startsWith("*") : false // inputs not marked required + data[fieldName] = isCheckable(input) ? input.checked : input.value + if (required && !data[fieldName]) { + input.focus() + alert(`Failed to save. Missing required data for "${label.innerText.substring(1)}"`) + return false + } + } + GM_setValue(key, data) + alert(`Saved successfully. Reload to check`) + return true } -/* Misc config */ -const packageLocationFill = "Porch" +GM_registerMenuCommand("Save Step 1 Fields", () => saveFilledData("initialFields", initialFields)) +GM_registerMenuCommand("Save Step 2 Fields", () => saveFilledData("otherFields", otherFields)) /* Fill funcs */ -function fillInitialFields() { - for (let fieldName in fill) - document.getElementById(fieldName).value = fill[fieldName] +const magicChange = new Event("change") +function fillFields(data) { + for (let fieldName in data) { + const input = document.getElementById(fieldName) + if (isCheckable(input)) + input.checked = data[fieldName] + else + input.value = data[fieldName] + input.dispatchEvent(magicChange) + } } - -function fillDogField() { - const f = document.querySelector("#second-radio-verification[name=isDogHere]") - f.checked = true - return f +function fillInitialFields() { + const data = GM_getValue("initialFields", {}) + fillFields(data) } -function fillPackageLocation() { - const f = document.getElementById("packageLocation") - f.value = packageLocationFill - return f +function fillOtherFields() { + const data = GM_getValue("otherFields", {}) + fillFields(data) } function fillPickupTime() { @@ -71,15 +111,15 @@ function scrollToDetails() { function showPickupDateInStepFour(pickupDateTD) { const month = parseInt(pickupDateTD.dataset.month) + 1 - const year = pickupDateTD.dataset.year - const day = pickupDateTD.firstElementChild.innerText + const year = pickupDateTD.dataset.year + const day = pickupDateTD.firstElementChild.innerText const date = `${month}-${day}-${year}` const dateElement = document.createElement("div") dateElement.class = "step-four-top-header" - dateElement.innerHTML = `<p class="step-four-row-header"></p>` - dateElement.innerHTML += `<p class="step-four-row-header" style="font-weight:bold;">Date of Pickup: ${date}</p>` + dateElement.innerHTML = `<p class="step-four-row-header"></p>` + dateElement.innerHTML += `<mark class="step-four-row-header" style="font-weight:bold;">Date of Pickup: ${date}</mark>` const container = document.querySelector("div.pickup-summary-gray-box-wrapper div") const sibiling = container.querySelector("div.step-four-top-header") @@ -91,10 +131,7 @@ function showPickupDateInStepFour(pickupDateTD) { fillInitialFields() document.querySelector("#webToolsAddressCheck").addEventListener("click", () => { - const magicChange = new Event("change") - - fillDogField() .dispatchEvent(magicChange) - fillPackageLocation().dispatchEvent(magicChange) + fillOtherFields() fillPickupTime() // Works through click |
