// ==UserScript==
// @name HERO_details
// @author lorfeuvr | shocklp
// @namespace ORY1
// @version 20220301
// @updateURL \\https://drive.corp.amazon.com/view/lorfeuvr@/ORY1scripts/HeroDetails.user.js
// @downloadURL \\https://drive.corp.amazon.com/view/lorfeuvr@/ORY1scripts/HeroDetails.user.js
// @updateURL https://gitlab.aws.dev/shocklp/shocklp/-/raw/master/scripts/HERO_details.user.js
// @downloadURL https://gitlab.aws.dev/shocklp/shocklp/-/raw/master/scripts/HERO_details.user.js
// @include /https:\/\/hero.\w{2,}.picking.aft.a2z.com\/fc\/\w{3}\d\//
// @require https://drive.corp.amazon.com/view/lorfeuvr@/libs/jquery/3.2.1/jquery.min.js
// @require https://drive.corp.amazon.com/view/lorfeuvr@/libs/wfke/waitForKeyElements.js
// @icon https://hero.na.picking.aft.a2z.com/favicon.ico
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// ==/UserScript==
// ORY1 - lorfeuvr@amazon.com
// _______________________________________
/* globals jQuery, $, waitForKeyElements */
//-------------------------------------------------------------
// Don't make any changes after this line
//-------------------------------------------------------------
var _region; // ie. "NA" "EU"
var _fcname; // ie. "MTN1" "PHL7"
var _CustomerShipment;
var loadOK = false;
var i = 0;
this.$ = this.jQuery = jQuery.noConflict(true);
$(document).ready(function () {
// Retrieve url infos
var _urlmatch = document.URL.match(/https:\/\/hero.(.*).picking.aft.a2z.com\/fc\/(.*)\/\pick-events\/customer-shipment\/(.*)/);
if (_urlmatch){
_region = _urlmatch[1];
_fcname = _urlmatch[2];
_CustomerShipment = _urlmatch[3];
}
waitForKeyElements('.awsui-row', PageLoaded);
});
function PageLoaded(){
if (loadOK){return false;}
loadOK = true;
var aa = '';
$('head').append(aa);
aa = '
| REBIN | |
|---|
| Associate | |
| Wall | |
| Station | |
';
aa += '| PACK | |
|---|
| Associate | |
| Station | |
| BoxRec | |
| Spoo | |
';
aa += '';
aa += '';
$('.awsui-row:eq(5)').prepend('');
getDatas(_CustomerShipment);
}
function getDatas(_CustomerShipment){
GM_xmlhttpRequest({
method: 'GET',
url: 'https://hero.'+ _region +'.picking.aft.a2z.com/api/fcs/' + _fcname + '/entities/type/CUSTOMER_SHIPMENT/id/' + _CustomerShipment + '/events',
headers: {
'Accept':'application/json, text/javascript',
'Content-Type':'application/json; charset=UTF-8'
},
onload: function(response) {
var js = JSON.parse(response.responseText);
if (typeof js.EventList != 'undefined'){
for (i = js.EventList.length-1; i >= 0; i--){
if (js.EventList[i].eventType == 'Shipment Opener'){
var _rebinStation = js.EventList[i].description.match(/at station (.*?) /);
var _rebinWall = js.EventList[i].description.match(/to slot (.*?)\./);
var _rebinAA = js.EventList[i].metaData.userId;
if (_rebinAA){
$('.rebinAA').html('' + _rebinAA + '');
$('.rebinAAphoto').html('
');
}
if (_rebinWall){
$('.rebinWall').text(_rebinWall[1]);
}
if (_rebinStation){
$('.rebinStation').text(_rebinStation[1]);
}
}
if (js.EventList[i].eventType == 'CREATE_PACKAGE'){
getEventDetail('CREATE_PACKAGE', _CustomerShipment, js.EventList[i].requestId, js.EventList[i].eventDetailsKey);
}
if (js.EventList[i].eventType == 'COMPLETE_PACKAGE'){
getEventDetail('COMPLETE_PACKAGE', _CustomerShipment, js.EventList[i].requestId, js.EventList[i].eventDetailsKey);
}
if (js.EventList[i].eventType == 'PackageShipStarted'){
getEventDetail('PackageShipStarted', _CustomerShipment, js.EventList[i].requestId, js.EventList[i].eventDetailsKey);
}
}
}
}
});
}
function getEventDetail(_eventType, _CustomerShipment, _requestId, _eventDetailsKey){
GM_xmlhttpRequest({
method: 'GET',
url: 'https://hero.'+ _region +'.picking.aft.a2z.com/api/fcs/' + _fcname + '/entities/type/CUSTOMER_SHIPMENT/id/' + _CustomerShipment + '/events/id/' + _requestId + '/details/key/' + _eventDetailsKey,
headers: {
'Accept':'application/json, text/javascript',
'Content-Type': 'application/json; charset=UTF-8'
},
onload: function(response) {
var js = JSON.parse(response.responseText);
if (typeof js.eventDetails != 'undefined'){
if (typeof js.eventDetails.message != 'undefined'){
switch(_eventType){
case 'CREATE_PACKAGE':
var _boxRec = js.eventDetails.message.match(/boxRecommendation=(.*?),/);
var _packStation = js.eventDetails.message.match(/locationScannableId=(.*?),/);
var _packAA = js.eventDetails.message.match(/owner=(.*?),/);
if (_packAA){
$('.packAA').html(`${_packAA[1]}`);
$('.packAAphoto').html('
');
}
if (_packStation){
$('.packStation').text(_packStation[1]);
}
if (_boxRec){
$('.boxRec').text(_boxRec[1]);
}
break;
case 'COMPLETE_PACKAGE':
var _SPOO = js.eventDetails.message.match(/data=(.*?),/);
if (_SPOO){
$('.Spoo').html(`${_SPOO[1]}`);
}
break;
case 'PackageShipStarted':
console.log('https://hero.'+ _region +'.picking.aft.a2z.com/api/fcs/' + _fcname + '/entities/type/CUSTOMER_SHIPMENT/id/' + _CustomerShipment + '/events/id/' + _requestId + '/details/key/' + _eventDetailsKey);
var _Slam = js.eventDetails.message.match(/Station=(.*?),/);
var _Kickout = js.eventDetails.message.match(/Error Code=(.*?),/);
if (_Slam){
$('.slamStation').text(_Slam[1]);
}
if (_Kickout){
$('.Kickout').text(_Kickout[1]);
}
var _Kickout2;
var _Kickout3;
var _Kickout4;
var re = / errorCode=(.*?) /g;
_Kickout2 = re.exec(js.eventDetails.message);
if (_Kickout2){
_Kickout3 = re.exec(js.eventDetails.message);
_Kickout4 = js.eventDetails.message.match(/ description=(.*?)\./);
var aa = '';
if (_Kickout3){aa += _Kickout3[1] + '
';}
aa += _Kickout2[1] + '
';
if (_Kickout4){aa += _Kickout4[1];}
$('.moreError').html(aa).css('display','block');
}
break;
}
}
}
}
});
}
GM_addStyle ( `
.moreError{
background:#ffb8b8;
padding:2rem;
border:1px solid #d7c2b0;
display:none
}
.myDiv{
display:flex;
background:#fff0e3;
padding:1.9rem 2rem;
border-top:1px solid #eaeded;
box-shadow: 0 1px 1px 0 rgba(0,28,36,.3),1px 1px 1px 0 rgba(0,28,36,.15),-1px 1px 1px 0 rgba(0,28,36,.15);
}
.resultTbl{
background:#fff;
border-collapse:collapse;
/*border:1px solid #d7c2b0;*/
margin-right:2rem;
border-radius: 1em;
box-shadow: 0 1px 1px 0 rgba(0,28,36,.3),1px 1px 1px 0 rgba(0,28,36,.15),-1px 1px 1px 0 rgba(0,28,36,.15);
}
.resultTbl tr:last-child td{
border-bottom:none;
}
.resultTbl tr td{
border:1px solid #d7c2b0;
padding:0 5px;
min-width:80px;
}
.resultTbl tr td:first-child{
border-left:none;
}
.resultTbl tr td:last-child{
border-right:none;
}
.packAAphoto img{
border-top-right-radius: 1em;
border-bottom-right-radius: 1em;
box-shadow: 0 1px 1px 0 rgba(0,28,36,.3),1px 1px 1px 0 rgba(0,28,36,.15),-1px 1px 1px 0 rgba(0,28,36,.15);
}
`)