Skip to content

Instantly share code, notes, and snippets.

Created August 4, 2010 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/508137 to your computer and use it in GitHub Desktop.
Save anonymous/508137 to your computer and use it in GitHub Desktop.
(function (){
if (window.top != window.self) return; //don't run on frames or iframes
var b, curtain, elem;
var specialsites = [
//[name, url, flash player parentNode XPath]
['Sohu', 'http://tv.sohu.com/', '//div[@id="sohuplayer"]']
,['Sina', 'http://video.sina.com.cn/', '//div[@id="myflashBox"]']
,['Sina', 'http://video.sina.com.cn/', '//div[@id="flashPlayer"]']
,['ku6', 'http://v.ku6.com/', '//div[@class="videoPlay"]']
,['tudou', 'http://www.tudou.com/playlist', '//object[@id="playerObject"]']
,['renren', 'http://share.renren.com/', '//div[@id="sharevideo"]']
]
var len = specialsites.length;
var url = document.location.href;
for (i=0;i<len;i++) {
if (url.indexOf(specialsites[i][1]) == 0) {
elem = document.evaluate(specialsites[i][2],document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0);
if (elem) break;
}
}
makeswitch();
lightsoff();
lightson();
function makeswitch() {
//create switcher button
b = document.createElement('div');
b.setAttribute('style', 'width: 80px; height: 25px; top: 10%; right: 0; z-index: 900000; position: fixed; color: white; background: black;opacity:0.6;text-align: center; vertical-align: middle; font-size: 9pt; cursor: pointer;-moz-border-radius:10px 0 0 10px;');
b.innerHTML = 'TurnOff';
b.addEventListener('click', lightsoff, false);
//insert button
document.body.appendChild(b);
}
function lightsoff() {
if (curtain) curtain.style.display = 'block';
else {
curtain = document.createElement('div');
curtain.innerHTML = 'Double Click to turn lights back on.';
curtain.title = 'Double Click to turn lights back on.';
curtain.setAttribute('style', 'width: 100%; height: 100%; top: 0; left: 0; z-index: 10000; position: fixed; color: #eee; background: black; text-align: right; opacity: 0.9;');
curtain.addEventListener('dblclick', lightson, false);
document.body.appendChild(curtain);
}
b.style.display = 'none'; //hide button
if (elem) {
fixZIndex(elem);
//setTimeout(fixZIndex,4000,elem);
}
}
function lightson() {
b.style.display = 'block';
curtain.style.display = 'none';
}
function fixZIndex(elem) {
elem.style.position = 'relative';
elem.style.zIndex = '10001';
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment