Created
June 3, 2010 16:34
-
-
Save edvakf/424103 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
// ==UserScript== | |
// @name iframe-addressbar | |
// @namespace http://d.hatena.ne.jp/edvakf/ | |
// @description Show pseudo address-bars for iframes on load and mouseover | |
// @include * | |
// ==/UserScript== | |
(function(win) { | |
if (win.top === win.self) return; | |
var initial_opacity = 0.8; | |
var isShown = false; | |
function showPseudoAddressBar() { | |
if (isShown) return; | |
isShown = true; | |
with (location) { | |
var origin = protocol + '//' + host + (port ? ':' + port : ''); | |
} | |
var bar = document.createElement('p'); | |
bar.textContent = origin; | |
bar.setAttribute('style', | |
['background-color : black' | |
,'color : white' | |
,'border : solid white 1px' | |
,'margin : 0' | |
,'padding : 0' | |
,'opacity : ' + initial_opacity | |
,'position : fixed' | |
,'z-index : 65535' | |
,'top : 0' | |
,'left : 0' | |
].join(';') | |
); | |
document.body.appendChild(bar); | |
setTimeout(function() { | |
var duration = 500; // millisecond | |
var t = new Date; | |
var timer = setInterval(function() { | |
var fraction = (new Date - t) / duration; | |
bar.style.opacity = initial_opacity * (1 - fraction); | |
if (fraction >= 1) { | |
bar.parentNode.removeChild(bar); | |
clearTimeout(timer); | |
isShown = false; | |
} | |
}, 50); | |
}, 2500); | |
} | |
win.addEventListener('load', showPseudoAddressBar, false); | |
win.addEventListener('focus', showPseudoAddressBar, false); | |
}(this.unsafeWindow || this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment