// ==UserScript== // @name panel // @namespace http://efcl.info/ // @include http://* // ==/UserScript== makeFrame(gotFrame); makeFrame(gotFrame2); function gotFrame(iframe, win, doc) { iframe.height = "350"; iframe.width = "500"; iframe.style.position = "fixed"; iframe.style.bottom = iframe.style.left = "0"; doc.body.innerHTML += "Frame1ですね。" } function gotFrame2(iframe, win, doc) { iframe.height = "350"; iframe.width = "500"; iframe.style.position = "fixed"; iframe.style.bottom = iframe.style.right = "0"; iframe.style.backgroundColor = "#ddd"; doc.body.innerHTML += "Frame2ですよ。" } // Creates a new iframe and attaches it to the DOM, waits for it to load, tests // that we did not hit https://bugzilla.mozilla.org/show_bug.cgi?id=295813 nor // https://bugzilla.mozilla.org/show_bug.cgi?id=388714 (and retries otherwise), // to finally call the provided done callback, passing the iframe, its window // and document. (The optional name parameter, if provided, will be used to name // the iframe in window.frames, or be created as "pane-1" onwards, otherwise.) /* var cacllback = function(iframe, win, doc){ } makeFrame(cacllback); makeFrame(cacllback , "frameName"); makeFrame(cacllback , "frameName" , true);// debug mode */ function makeFrame(callback/*(iframeTag, window, document)*/, name, debug) { function testInvasion() { iframe.removeEventListener("load", done, true); var message = ((new Date) - load.start) + "ms passed, "; try { // probe for security violation error, in case mozilla struck a bug var url = unsafeWindow.frames[framename].location.href; message += url == "about:blank" ? "but we got the right document." : "and we incorrectly loaded " + url; if (debug) console.log(message); done(); } catch(e) { if (console && console.error && console.trace) { console.error(e); console.trace(); } if (debug) console.log(message + "and our iframe was invaded. Trying again!"); document.body.removeChild(iframe); makeFrame(callback, name); } } function done() { clearTimeout(load.timeout); if (debug) console.log("IFrame %x load event after %d ms", framename, (new Date) - load.start); var win = unsafeWindow.frames[framename]; var doc = iframe.contentWindow.document; // 苦し紛れのエスケープ var esframeName = "'"+framename+"'"; // 自分自身のiframeを閉じるボタン var xImg = doc.createElement("img"); xImg.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAATElEQVQoka2RSQ4AIAgD+f+jp96M0aq49AgdUiB0qZCkONQ/EBAwDOrrU7A1uZqN2hodtNwRqNdz0VOg62+jzuDUcVzkf+/I6h28UQHjW25Gob5AIAAAAABJRU5ErkJggg==" xImg.setAttribute("onclick", "parent.document.getElementsByName("+esframeName+")[0].style.display='none';"); xImg.setAttribute("style","background-color:red;border:3px;position:fixed;top:0px;right:0px"); doc.body.appendChild(xImg); callback(iframe, win, doc); } var iframe = document.createElement("iframe"); var framename = iframe.name = typeof name != "undefined" ? name : ("pane" + (makeFrame.id = (makeFrame.id || 0) - 1)); iframe.setAttribute("style", "overflow:auto;z-index:18999; border:0; margin:0; padding:0;top:auto; right:auto; bottom:auto; left:auto;background-color:#fff"); iframe.src = "about:blank"; iframe.addEventListener("load", done, true); var frames = makeFrame.data || {}; var load = frames[framename] || { start: new Date, sleepFor: 400 }; load.timeout = setTimeout(testInvasion, load.sleepFor); load.sleepFor *= 1.5; frames[framename] = load; makeFrame.data = frames; document.body.appendChild(iframe); }