Skip to content

Instantly share code, notes, and snippets.

@Ninjex
Last active February 4, 2017 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ninjex/e242cf2a5dda8c4b413000f8ff29d4f1 to your computer and use it in GitHub Desktop.
Save Ninjex/e242cf2a5dda8c4b413000f8ff29d4f1 to your computer and use it in GitHub Desktop.
pwn the ko
// ==UserScript==
// @name FANS Poller
// @namespace https://fcswat-us.aka.amazon.com/workflow/init
// @description manages the display tabs
// @include https://fcswat-us.aka.amazon.com/workflow/init
// @version 1
// @grant none
// ==/UserScript==
// workflow message
// document.getElementById("action_section").childNodes[1].childNodes[1].innerHTML
// success or fail message
// document.getElementById("workflow_status_content").childNodes[1].childNodes[0].innerHTML
/* Messages For Workflow
"Scan the <strong>STATION ID</strong>"
"Scan the <strong>BOX BARCODE</strong>, or <br><strong>(1) OwnBox</strong>, <strong>(2) Overwrap</strong>,<br><strong>(3) CustomBox</strong>"
"Place the package on the scale, then scan the <strong>SPOO</strong>."
"Scan the <strong>LithiumIon</strong>"
"Scan the <strong>LithiumMetal</strong>"
"Scan the <strong>SHIPPING LABEL </strong>"
*/
/*******************************************************
Tools Logic (JavaScript Section)
*******************************************************/
window.onkeydown = function(e) {
e = e || event
if( e.ctrlKey) {
switch(e.keyCode) {
// ctrl + i
case 73:
scanLithiumIon();
break;
// ctrl + m
case 77:
scanLithiumMetal();
break;
// ctrl + <- (left arrow)
case 37:
v = document.getElementById('auto_override').checked
if(v === false) {
document.getElementById('auto_override').checked = true;
} else {
document.getElementById('auto_override').checked = false;
}
break;
}
}
switch (e.keyCode) {
// KeyPad: 0
// Override Weight of final item
case 96:
overrideLastUnit();
break;
// KeyPad: 1
// Inject arbitrary data
case 97:
inject(prompt("Data to Inject"));
break;
// KeyPad: 2
// Add ASIN from ASIN field to shipment and get weight
// Useful for shotgunned shipments with high quantity
case 98:
inject();
break;
// KeyPad: 3
// Override Weight of ASIN (Not final unit)
case 99:
overrideUnit();
break;
// KeyPad: 4
// Use a Preffered Box Code
case 100:
boxOverride();
break;
// KeyPad: 5
// Send Shipment to Problem Solve
case 101:
problemSolveShipment();
break;
// KeyPad: 6
// CREATE A RESTART SHIPMENT FUNCTION???
case 102:
restartShipment();
break;
// KeyPad: 7
// Bruteforce Shipment With Box Code List
case 103:
shotgun();
break;
// KeyPad: 9
// Toggle Custom Tools Visibility
case 105:
toggleVisibility();
document.getElementById("action_section").childNodes[1].childNodes[1].addEventListener('change', function() {
if(document.getElementById("action_section").childNodes[1].childNodes[1].innerHTML === 'Scan the <strong>BOX BARCODE</strong>, or <br><strong>(1) OwnBox</strong>, <strong>(2) Overwrap</strong>,<br><strong>(3) CustomBox</strong>') {
console.log('auto do stuff here?');
}
})
break;
}
}
var box_list = ["BFG", "BFE", "B5L", "B5M"];
window.setInterval(function(){
// "Scan the <strong>STATION ID</strong>"
if(document.getElementById("action_section")) {
if(document.getElementById("action_section").childNodes[1].childNodes[1].innerHTML === "Scan the <strong>STATION ID</strong>") {
handleScan('901');
handleScan('event_btn_1');
}
if(document.getElementById('auto_override').checked === true) {
switch(document.getElementById("action_section").childNodes[1].childNodes[1].innerHTML) {
case 'Scan the <strong>BOX BARCODE</strong>, or <br><strong>(1) OwnBox</strong>, <strong>(2) Overwrap</strong>,<br><strong>(3) CustomBox</strong>':
box_code = document.getElementById('box_codes').value.trim();
handleScan(box_code);
break;
case 'Scan the <strong>LithiumIon</strong>':
scanLithiumIon()
break;
case "Scan the <strong>LithiumMetal</strong>":
scanLithiumMetal();
break;
case "Scan the <strong>SHIPPING LABEL </strong>":
handleScan("event_btn_1");
break;
}
}
}
}, 1000);
/*
(function(){
var originallog = console.log;
console.log = function(txt) {
// Do really interesting stuff
if(document.getElementById("action_section")) {
if(document.getElementById("action_section").childNodes[1].childNodes[1].innerHTML === 'Scan the <strong>BOX BARCODE</strong>, or <br><strong>(1) OwnBox</strong>, <strong>(2) Overwrap</strong>,<br><strong>(3) CustomBox</strong>') {
box_code = document.getElementById('box_codes').value.trim();
handleScan(box_code);
document.getElementById("action_section").childNodes[1].childNodes[1].innerHTML = 'foo';
return;
} else {
return '';
}
}
originallog.apply(console, arguments);
}
})();
*/
function autoOverride(box_list) {
// Find a way to tell if a sp00 becomes scanned
// if autooverride is enabled and a sp00 becomes scanned
// call bruteForceShipment(box_list)
} window.autoOverride = autoOverride;
function bruteForceShipment(box_list) {
updateLog("Initiating Bruteforce");
for(var box = 0; box < box_list.length; box++) {
code = box_list[box];
updateLog("Bruteforce Box: " + code);
handleScan(code);
if(1 == 2) break; // SWAP WITH THE LINE BELOW BEFORE PLACING IN PRODUCTION!!!
//if(document.getElementById("workflow_status_content").childNodes[1].childNodes[0].innerHTML == 'SUCCESS') break;
else restartShipment();
}
} window.bruteForceShipment = bruteForceShipment;
function shotgun() {
var asin = prompt("ASIN");
var amount = Number(prompt("How many units?"));
updateLog("Shotgun: " + asin + ' * ' + amount);
for(var x = 0; x < amount; x++) {
handleScan(asin);
handleScan("continue");
handleScan("event_btn_3");
overrideUnit(asin);
}
} window.shotgun = shotgun;
function overrideLastUnit() {
updateLog("Final Unit Override + Shipping");
handleScan("continue");
handleScan("event_btn_3");
handleScan("event_btn_2");
handleScan("continue");
} window.overrideLastUnit = overrideLastUnit;
function scanLithiumMetal() {
updateLog("Injecting Lithium Metal Label Scans");
handleScan("LithiumMetal");
handleScan("LithiumMetal_TD");
} window.scanLithiumMetal = scanLithiumMetal;
function scanLithiumIon() {
updateLog("Injecting Lithium Ion Label Scans");
handleScan("LithiumIon");
handleScan("LithiumIon_TD");
} window.scanLithiumIon = scanLithiumIon;
function overrideUnit() {
updateLog("Overriding Weight of Current Unit");
handleScan("continue");
handleScan("event_btn_3");
} window.overrideUnit = overrideUnit;
function boxOverride() {
box_code = document.getElementById('box_codes').value.trim()
updateLog("Box Code Override: " + box_code);
handleScan(box_code);
} window.boxOverride = boxOverride;
function manualBoxOverride(box_code) {
updateLog("Box Code Override: " + box_code);
handleScan(box_code);
} window.manualBoxOverride = manualBoxOverride;
function inject(data=false) {
if(!data) {
data = document.getElementById('inject').value.trim();
}
updateLog('Injected: ' + data );
handleScan(data);
} window.inject = inject;
function getLastSpoo() {
for(var x = 0; x < document.getElementsByTagName('td').length; x++) {
if(document.getElementsByTagName('td')[x].textContent === 'SPOO') {
return (document.getElementsByTagName('td')[x + 1].textContent);
}
}
//return document.getElementsByTagName('td')[3].textContent;
} window.getLastSpoo = getLastSpoo;
// If custom sp00 field is null, adjust function to pull real sp00 field
function restartShipment() {
/* Get current spoo from console.log?
send spoo to problem solve and rescan spoo
*/
updateLog("Restarting Shipment...")
// Get last SP00 from logs
// var last_spoo = <logic here>
problemSolveShipment();
handleScan(getLastSpoo());
} window.restartShipment = restartShipment;
function problemSolveShipment() {
// logic to send to problem solve
updateLog("Sending to ProblemSolve");
handleScan("continue");
handleScan("event_btn_1");
handleScan("continue");
} window.problemSolveShipment = problemSolveShipment;
function updateLog(data) {
document.getElementById("log_data").innerHTML = "<p>" + data + document.getElementById("log_data").innerHTML + "</p>";
} window.updateLog = updateLog;
function clearLogs() {
document.getElementById('log_data').innerHTML = '';
} window.clearLogs = clearLogs;
function toggleVisibility() {
vis = document.getElementById("tools_container").style.visibility;
if(vis == 'hidden') document.getElementById("tools_container").style.visibility = 'visible';
else document.getElementById("tools_container").style.visibility = 'hidden';
} window.toggleVisibility = toggleVisibility;
/********************************************************
Automatic Override Event Handler
********************************************************/
window.onload = function() {
document.getElementById('auto_override').addEventListener('change', function() {
override_status = document.getElementById('auto_override').checked;
updateLog("Auto Override toggled: " + override_status);
})
}
function addStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
/*******************************************************
Styling (CSS Section)
*******************************************************/
var styleSheet = `
#tools_container {
width: 50%;
margin: auto;
background-color: white;
border: solid thin black;
min-width: 1000px;
overflow: hidden;
}
#tools_container .title {
text-align: center;
font-weight: bold;
font-size: 1.5em;
color: red;
}
#quick_links_container ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
#quick_links_container li {
float: left;
}
#quick_links_container li a, #quick_links_container .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
#quick_links_container li a:hover,
#quick_links_container .dropdown:hover .dropbtn {
background-color: red;
}
#quick_links_container li.dropdown {
display: inline-block;
}
#quick_links_container .dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
#quick_links_container .dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
#quick_links_container .dropdown-content a:hover {
background-color: #f1f1f1
}
#quick_links_container .dropdown:hover .dropdown-content {
display: block;
}
#quick_links .link_header {
color: red;
margin-bottom: 0;
padding-bottom: 0;
position: relative;
text-align: center;
}
#tools_container #logs {
float: right;
margin-right: 5px;
width: 50%;
height: 22em;
overflow: hidden;
border-left: solid thin black;
}
#tools_container #logs #log_data {
border-top: solid medium black;
padding-left: 5px;
width: 100%;
height: 100%;
overflow-y: scroll;
}
#tools_container #functions {
float: left;
margin-left: 5px;
}`
addStyle(styleSheet);
/*******************************************************
Markup (HTML Section)
*******************************************************/
var DOM = `
<div id="tools_container">
<h1 class="title">KO Tools Version 4.0 - Justin Bess</h1>
<div id="quick_links_container">
<ul id="quick_links">
<li>
<p class="link_header">1</p>
<a onclick="overrideLastUnit();">Final Override</a>
</li>
<li class="dropdown">
<p class="link_header">4</p>
<a href="javascript:void(0)" class="dropbtn">Supersede Box</a>
<div class="dropdown-content">
<a onclick="manualBoxOverride('BFG');">BFG</a>
<a onclick="manualBoxOverride('BFE');">BFE</a>
<a onclick="manualBoxOverride('B5M');">B5M</a>
<a onclick="manualBoxOverride('BFS');">BFS</a>
<a onclick="manualBoxOverride('B5L');">B5L</a>
</div>
</li>
<li>
<p class="link_header">5</p>
<a onclick="problemSolveShipment();">Problem Solve</a>
</li>
<li>
<p class="link_header">6</p>
<a onclick="restartShipment();">Restart</a>
</li>
<li>
<p class="link_header">7</p>
<a onclick="shotgun();">Shotgun</a>
</li>
<li>
<p class="link_header">9</p>
<a onclick="toggleVisibility();">Toggle Visibility</a>
</li>
<li class="dropdown">
<p class="link_header"><br></p>
<a href="javascript:void(0)" class="dropbtn">Battery Scan</a>
<div class="dropdown-content">
<a onclick="scanLithiumIon();">Ion</a>
<a onclick="scanLithiumMetal();">Metal</a>
</div>
</li>
<li class="dropdown">
<p class="link_header"><br></p>
<a href="javascript:void(0)" class="dropbtn">Links</a>
<div class="dropdown-content">
<a href="#RODEO" class="slidebtn">Rodeo</a>
<a href="#HitchReport">Hitch Report</a>
<a href="#FCResearch">FCResearch</a>
<a href="#MASTERMIND">Mastermind</a>
<a href="#OOPS">OOPS</a>
<a href="#PACK-APP">Pack App</a>
</div>
</li>
<li>
<p class="link_header"><br></p>
<a onclick="clearLogs();">Clear Logs</a>
</li>
</ul>
</div>
<div id="functions">
<p>
<input type="text" id="inject" placeholder="SPOO / ASIN">
<button name="inject" type="button" onclick="inject();">Inject</button>
<input type="checkbox" value="true" id="auto_override" name="auto_override" />
<label for="auto_override">Auto Override</label>
</p>
<p>
<label for="box_codes">Box</label>
<select id="box_codes">
<option value="BFE">BFE</option>
<option value="BFS">BFS</option>
<option value="BFG">BFG</option>
<option value="B5M">B5M</option>
<option value="B5L">B5L</option>
</select>
</p>
</div>
<section id="logs">
<a target="_blank" href="https://rodeo-iad.amazon.com/BNA3/ExSD" class="slidebtn">Rodeo</a>
<a target="_blank" href="https://fc-hitch.iad.proxy.amazon.com/gp/fc-application-services/hitch-report/index.html?warehouseId=BNA3">Hitch Report</a>
<a target="_blank" href="http://fcresearch-na.aka.amazon.com/BNA3/search">FCResearch</a>
<a target="_blank" href="https://mastermind.amazon.com/kickout">Mastermind</a>
<a target="_blank" href="http://oops-web-iad.amazon.com/selectProblemSolvingArea?problemSolvingArea=SlamKickout">OOPS</a>
<a target="_blank" href="https://packapp-web-na.aka.amazon.com/pslip/">Pack App</a>
<a target="_blank" href="https://commandcenter-iad.amazon.com/#/dashboard?warehouseId=BNA3">Command Center</a>
<h1 class="title">Log Information</h1>
<div id="log_data">
</div>
</section>
</div>
`
document.body.innerHTML += DOM;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment