I got a webpage which only support IE7 and older IE. After some digging I found out it just use some very old JS method and the most important function is just implemented with XML HTTP Request
. So I decided to make the request myself.
I write a bookmarklet (which can be compressed with https://mrcoles.com/bookmarklet/) to do the job.
iframe = document.getElementsByName('midFrame')[0].contentWindow.document.getElementsByName('main')[0];
if(!iframe.contentWindow.document.getElementById("session_sid")){
var alert_div = document.createElement("div");
alert_div.id = "session_sid";
alert_div.style = "
font-size: 1.6rem;
height: auto;
position: fixed;
text-align: center;
width: 100%;
color: #fff;
padding: 20px;
background-color:#67daff;
z-index:5555;
";
iframe.contentWindow.document.body.appendChild(alert_div)
};
token = 'method=login&arguments=can¬=be&told=because&of=privacy';
xhr = new XMLHttpRequest();
xhr.onreadystatechange = stateChange;
xhr.open("GET", '/aim/sso.do?'+token, true);
xhr.send();
const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected =
document.getSelection().rangeCount > 0
? document.getSelection().getRangeAt(0)
: false;
el.select();
document.execCommand('copy');
document.body.removeChild(el);
if (selected) {
document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
};
function stateChange() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
iframe = document.getElementsByName('midFrame')[0].contentWindow.document.getElementsByName('main')[0];
iframe.contentWindow.document.getElementById('session_sid').innerHTML = xhr.responseText;
copyToClipboard(xhr.responseText);
} else {
console.log(xhr.status)
}
}
}
Here are some notes:
-
A lot of
Frame
are used, we need to get into the correct level with methodcontentWindow
. -
You may use following code to send the result into clipboard:
iframe.contentWindow.document.getElementById('session_sid').innerHTML = '<input type="text" value="'+xhr.responseText+'" id="sid" readonly>';
iframe.contentWindow.document.getElementById('sid').select();
iframe.contentWindow.document.execCommand('copy')