Skip to content

Instantly share code, notes, and snippets.

@x43x61x69
Last active December 1, 2020 20:25
Show Gist options
  • Save x43x61x69/b46ea55819db229a6204d89b92d6a9b8 to your computer and use it in GitHub Desktop.
Save x43x61x69/b46ea55819db229a6204d89b92d6a9b8 to your computer and use it in GitHub Desktop.
Apple Shipment Enumerator via DHL Express (SHANGHAI, CHINA)
<!--
// Copyright (C) 2020 Zhi-Wei Cai.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-->
<html>
<head>
<title="Apple - DHL Express">
<style>
iframe
{
width: 100%;
height: 80%;
}
</style>
</head>
<body>
<input type="text" id="awb" name="awb" placeholder="Tracking#">
<button onclick="load()">Load</button>
<br />
<button onclick="prev()">Prev</button>
<input type="text" id="step" name="step" value="1" placeholder="Step(s)">
<button onclick="next()">Next</button>
<br />
<iframe id="dhlView" name="dhlView" onload="checkIframeLoaded();"></iframe>
<script>
const sample = 8477525571;
const url = "http://mrt2.ap.dhl.com/mrt?AWB=";
load();
document.onkeydown = keyDown;
function load()
{
var awb = parseInt(document.getElementById("awb").value);
if (Number.isNaN(awb) || awb < 0)
{
awb = sample;
document.getElementById("awb").value = awb;
}
document.getElementById('dhlView').src = url + awb.toString();
}
function checkIframeLoaded()
{
// Get a handle to the iframe element
var iframe = document.getElementById('dhlView');
var iframeDoc = iframe.contentDocument;
// Check if loading is complete
if ( iframeDoc.readyState == 'complete' ) {
// The loading is complete, call the function we want executed once the iframe is loaded
afterLoading();
return;
}
// If we are here, it is not loaded. Set things up so we check the status again in 100 milliseconds
window.setTimeout(checkIframeLoaded, 100);
}
function afterLoading()
{
console.log(document.getElementById('destinationURL4'));
}
function keyDown(e)
{
e = e || window.event;
if (e.keyCode == '37')
{
prev();
}
else if (e.keyCode == '39')
{
next();
}
}
function prev()
{
var step = parseInt(document.getElementById("step").value);
jump(step * -1);
}
function next()
{
var step = parseInt(document.getElementById("step").value);
jump(step);
}
function jump(step)
{
var steps = parseInt(step);
if (Number.isNaN(steps) || steps == 0)
{
steps = 1;
document.getElementById("step").value = steps;
}
var awb = checksum((parseInt(document.getElementById("awb").value.substr(0, 9)) + steps).toString());
document.getElementById("awb").value = awb;
load();
}
function checksum(awb)
{
var sum = parseInt(awb)%7;
return awb.substr(0, 9) + sum;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment