0% found this document useful (0 votes)
26 views4 pages

WW OL Dropdown - Updated

This document is a user script designed for Tampermonkey that automates the selection of options on specific web pages related to Amazon's Geostudio templates. It includes functions to create buttons for various actions, such as saving or syncing data, and selecting radio buttons and dropdown options based on user-defined scenarios. The script also provides error handling and visual feedback for user interactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

WW OL Dropdown - Updated

This document is a user script designed for Tampermonkey that automates the selection of options on specific web pages related to Amazon's Geostudio templates. It includes functions to create buttons for various actions, such as saving or syncing data, and selecting radio buttons and dropdown options based on user-defined scenarios. The script also provides error handling and visual feedback for user interactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

// ==UserScript==

// @name WW Outliers FINAL - 2.2


// @author @ckarths
// @namespace http://tampermonkey.net/
// @version 2.3
// @description Auto select options for different scenarios
// @match https://eu.templates.geostudio.last-mile.amazon.dev/*
// @match https://na.templates.geostudio.last-mile.amazon.dev/*
// @match https://fe.templates.geostudio.last-mile.amazon.dev/*
// ==/UserScript==

(function() {
function createButton(label, left, action) {
var button = document.createElement("button");
button.innerHTML = label;
button.setAttribute('style', `position: absolute; z-index: 2500; padding:
2px; left:${left}%; top: 1%; background-color: #CCCCCC; color: #000000; border: 4px
solid #CCCCCC; border-radius: 8px; font-size: 14px; font-family: "Amazon Ember";
font-weight: bold; transition: background-color 0.3s, border-color 0.3s;`);

button.addEventListener('click', async () => {


try {
await delay(10);
await action();
} catch (error) {
showError(error);
}
});

button.addEventListener('mouseover', function() {
this.style.backgroundColor = '#777777';
this.style.borderColor = '#777777';
});

button.addEventListener('mouseout', function() {
this.style.backgroundColor = '#CCCCCC';
this.style.borderColor = '#CCCCCC';
});

button.addEventListener('mousedown', function() {
this.style.backgroundColor = '#444444';
this.style.borderColor = '#444444';
});

button.addEventListener('mouseup', function() {
this.style.backgroundColor = '#777777';
this.style.borderColor = '#777777';
});

document.body.appendChild(button);
}

function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

async function selectRadioByValue(containerClass, value) {


var container = document.querySelector(`.${containerClass}`);
if (!container) throw `Container with class ${containerClass} not found.`;
var radioButtons = container.querySelectorAll('input[type="radio"]');
var selectedRadio = Array.from(radioButtons).find(radio => radio.value ===
value);

if (selectedRadio) {
selectedRadio.click();
} else {
throw `Radio button with value "${value}" not found in $
{containerClass}.`;
}
}

async function selectOptionById(id, optionIndex) {


var element = document.getElementById(id);
if (!element) throw `Element with ID ${id} not found.`;
var event = new Event("mousedown", { bubbles: true });
element.dispatchEvent(event);

await delay(10);

var optionsListId = element.getAttribute("aria-controls");


var optionsList = document.getElementById(optionsListId);
if (!optionsList) throw `Options list for element with ID ${id} not
found.`;

var options = optionsList.querySelectorAll('[role="option"]');


if (options.length > optionIndex) {
options[optionIndex].click();
} else {
throw `Option at index ${optionIndex} not found for element with ID $
{id}.`;
}
}

async function selectSourceOption(optionIndex) {


try {
await selectOptionById("source", optionIndex);
} catch (error) {
// If the source selection fails, we can log the error or handle it
accordingly.
}
}

async function svBuAction() {


await selectRadioByValue("css-gx29mt", "Save"); // actionTaken
await selectOptionById("granularity", 1); // granularity - Building_Level
}

async function svRdAction() {


await selectRadioByValue("css-gx29mt", "Save"); // actionTaken
await selectOptionById("granularity", 2); // granularity - Road_Level
}

async function svNdAction() {


await selectRadioByValue("css-gx29mt", "Save"); // actionTaken
await selectOptionById("granularity", 4); // granularity - New_Development
}
async function svCAction() {
await selectRadioByValue("css-gx29mt", "Save"); // actionTaken
await selectOptionById("granularity", 3); // granularity -
University/Community
}

async function synBuAction() {


await selectRadioByValue("css-gx29mt", "Sync"); // actionTaken
await selectOptionById("granularity", 1); // granularity - Building_Level
}

async function synRdAction() {


await selectRadioByValue("css-gx29mt", "Sync"); // actionTaken
await selectOptionById("granularity", 2); // granularity - Road_Level
}

async function synNdAction() {


await selectRadioByValue("css-gx29mt", "Sync"); // actionTaken
await selectOptionById("granularity", 4); // granularity - New_Development
}

async function synCAction() {


await selectRadioByValue("css-gx29mt", "Sync"); // actionTaken
await selectOptionById("granularity", 3); // granularity -
University/Community
}

async function utlAction() {


await selectRadioByValue("css-gx29mt", "UTL"); // actionTaken
await selectOptionById("granularity", 5); // granularity - Unlocatable
await selectSourceOption(0); // Source - NA
}

async function nakAction() {


await selectRadioByValue("css-gx29mt", "NAK_ISSUE"); // actionTaken
await selectOptionById("granularity", 0); // granularity - NA
await selectSourceOption(0); // Source - NA
}

async function dfPoAction() {


await selectRadioByValue("css-gx29mt", "NA"); // actionTaken
await selectOptionById("granularity", 0); // granularity - NA
await selectSourceOption(0); // Source - NA

// Select the 'addressClassification' radio button with value "NA"


var addressClassificationContainer = document.querySelector('.css-
dfrd9x .css-gx29mt');
if (addressClassificationContainer) {
var naRadio =
addressClassificationContainer.querySelector('input[type="radio"][value="NA"]');
if (naRadio) {
naRadio.click(); // This should trigger the radio button selection

// Force the visual update


var naLabel = naRadio.closest('label');
if (naLabel) {
var customRadio = naLabel.querySelector('div[class^="css-"]');
if (customRadio) {
customRadio.className = 'css-1prjt9m';
}
}

// Ensure the radio button is checked


naRadio.checked = true;
naRadio.setAttribute('aria-checked', 'true');

// Dispatch events to ensure React picks up the change


naRadio.dispatchEvent(new Event('change', { bubbles: true }));
naRadio.dispatchEvent(new Event('click', { bubbles: true }));
} else {
throw new Error('Address Classification radio input for "NA" not
found.');
}
} else {
throw new Error('Address Classification container not found.');
}
}

function showError(errorMessage) {
var errorDiv = document.createElement("div");
errorDiv.innerHTML = errorMessage;
errorDiv.style.color = "red";
errorDiv.style.position = "absolute";
errorDiv.style.top = "50%";
errorDiv.style.left = "50%";
errorDiv.style.transform = "translate(-50%, -50%)";
errorDiv.style.zIndex = "9999";
errorDiv.style.backgroundColor = "#FFFFFF";
errorDiv.style.padding = "10px";
errorDiv.style.border = "1px solid #CCCCCC";
errorDiv.style.borderRadius = "4px";
errorDiv.style.fontSize = "16px";
errorDiv.style.fontFamily = "Amazon Ember";
document.body.appendChild(errorDiv);

setTimeout(() => {
errorDiv.style.opacity = 0;
setTimeout(() => {
document.body.removeChild(errorDiv);
}, 20);
}, 2000);
}

// Create buttons at the top of the screen, spaced evenly


createButton("Sv-BU", 5, svBuAction);
createButton("Sv-RD", 12, svRdAction);
createButton("Sv-ND", 20, svNdAction);
createButton("Sv-C", 28, svCAction);
createButton("Syn-BU", 35, synBuAction);
createButton("Syn-RD", 44, synRdAction);
createButton("Syn-ND", 52, synNdAction);
createButton("Syn-C", 60, synCAction);
createButton("UTL", 68, utlAction);
createButton("NAK", 75, nakAction);
createButton("DF|PO", 82, dfPoAction);
})();

You might also like