Last active
January 10, 2022 21:10
-
-
Save ousjaguraga/20bf24f624c30b4db88163fa01e3cdcd to your computer and use it in GitHub Desktop.
IDF Cleaning CM almost Automator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name IDFCleaningCmaster | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1.1 | |
// @description This script helps with idf cleaning CMs, please double check before submitting | |
// @author Ousman | |
// @match https://mcm.amazon.com/cms/new?from_template=8ab49e49-ed2b-4eda-9003-4fc76e2bb40f | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// customize | |
const WHID = 'bhx7' | |
// add a button to display the number of switches | |
const containerID = 'container-fluid' | |
const searchButtonContainer = document.createElement("div") | |
const searchButton = document.createElement("button") | |
const idfNumberInput = document.createElement("input") | |
const switchNumberInput = document.createElement("input") | |
// new: add technician and cm requester | |
const requesterInput = document.createElement("input") | |
const techInput = document.createElement("input") | |
searchButton.setAttribute('id', 'switchNumber') | |
searchButton.setAttribute('value', 'Go') | |
searchButton.innerHTML = "GO" | |
function processSwitchNames(){ | |
for (let i = 1; i < Number(switchNumberInput.value)+1; i++){ | |
if (i < 10){ | |
document.getElementById(`templateVariables[{{acc_sw_0${i}}}]`).value = `${WHID}-co-acc-sw${Number(idfNumberInput.value)}0${i}.amazon.com` | |
} else { | |
document.getElementById(`templateVariables[{{acc_sw_10}}]`).value = `${WHID}-co-acc-sw${Number(idfNumberInput.value)}10.amazon.com` | |
} | |
} | |
} | |
function processDistributionSwitches(){ | |
document.getElementById(`templateVariables[{{dis_sw_01}}]`).value = `${WHID}-co-dis-sw${Number(idfNumberInput.value)}01.amazon.com` | |
document.getElementById(`templateVariables[{{dis_sw_02}}]`).value = `${WHID}-co-dis-sw${Number(idfNumberInput.value)}02.amazon.com` | |
} | |
function processRest(){ | |
// if n is a single number add a leading 0 | |
let n = Number(idfNumberInput.value) | |
if (n < 10){ | |
document.getElementById(`templateVariables[{{IDF_Number}}]`).value =`0${n}` | |
} else { | |
document.getElementById(`templateVariables[{{IDF_Number}}]`).value = n | |
} | |
// set warehouse ID stuff | |
document.getElementById(`templateVariables[{{whid_lower}}]`).value =`${WHID.toLowerCase()}` | |
document.getElementById(`templateVariables[{{whid_upper}}]`).value =`${WHID.toUpperCase()}` | |
document.getElementById(`templateVariables[{{rsw_sw_1}}]`).value =`${WHID}-co-acc-rsw${Number(idfNumberInput.value)}-1.amazon.com` | |
document.getElementById(`templateVariables[{{rsw_sw_2}}]`).value =`${WHID}-co-acc-rsw${Number(idfNumberInput.value)}-2.amazon.com` | |
document.getElementById('cti_resolver_group').value = `OpsTechIT-${WHID.toUpperCase()}` | |
document.getElementById(`templateVariables[{{cm_requester}}]`).value =`${requesterInput.value}` | |
document.getElementById(`templateVariables[{{cm_technician}}]`).value =`${techInput.value}` | |
} | |
function processPduAndUps(){ | |
document.getElementById(`templateVariables[{{pdu_1}}]`).value =`${WHID}-idf${Number(idfNumberInput.value)}-pdu-1.${WHID}.amazon.com` | |
document.getElementById(`templateVariables[{{pdu_2}}]`).value =`${WHID}-idf${Number(idfNumberInput.value)}-pdu-2.${WHID}.amazon.com` | |
document.getElementById(`templateVariables[{{ups_1}}]`).value =`${WHID}-idf${Number(idfNumberInput.value)}-ups-1.${WHID}.amazon.com` | |
document.getElementById(`templateVariables[{{ups_2}}]`).value =`${WHID}-idf${Number(idfNumberInput.value)}-ups-2.${WHID}.amazon.com` | |
} | |
searchButton.addEventListener('click', event => { | |
// set all switch numbers | |
processSwitchNames() | |
processDistributionSwitches() | |
processPduAndUps() | |
processRest() | |
}); | |
// set attributes for the input elements | |
requesterInput.setAttribute('type', 'text') | |
techInput.setAttribute('type', 'text') | |
techInput.setAttribute('placeholder', 'Enter login of person running the MCM') | |
requesterInput.setAttribute('placeholder', 'Enter login of person writing the CM') | |
idfNumberInput.setAttribute('type', 'text') | |
idfNumberInput.setAttribute('placeholder', 'Enter IDF number') | |
switchNumberInput.setAttribute('type', 'text') | |
switchNumberInput.setAttribute('placeholder', 'How many switches?') | |
searchButtonContainer.appendChild(idfNumberInput) | |
searchButtonContainer.appendChild(switchNumberInput) | |
searchButtonContainer.appendChild(requesterInput) | |
searchButtonContainer.appendChild(techInput) | |
searchButtonContainer.appendChild(searchButton) | |
searchButtonContainer.style.background = 'black' | |
searchButtonContainer.setAttribute('class', 'container-fluid') | |
// searchButtonContainer contains all the elements and the button | |
for (var i = 0; i < searchButtonContainer.children.length - 1; i++) { | |
searchButtonContainer.children[i].setAttribute('class', 'search-query"') | |
searchButtonContainer.children[i].style.width = '250px' | |
searchButtonContainer.children[i].style.margin = '5px' | |
} | |
// now style the serach button | |
searchButton.setAttribute('class', 'btn btn-success') | |
var container = document.getElementsByClassName(containerID)[0] | |
container.after(searchButtonContainer) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment