//================================================
/*
Turn Off the Lights
The entire page will be fading to dark, so you can watch video as if you are in the cinema.
Copyright (C) 2010 Stefan vd
www.stefanvd.net
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
To view a copy of this license, visit
http://creativecommons.org/licenses/GPL/2.0/
*/
//================================================
function $(id) { return document.getElementById(id); }
// Variable for the fade in and out effect
var default_opacity = 80;
var opacity = 0;
var ReducingFinished = true;
var OpacityLevelIncrement = 10; // Percentage value: 1-100
var FadeDelayMS = 60; // Milliseconds
// Function determines whether we show or hide the item referenced by ElementID
function fader(ActionToTake)
{
DIVElementById = $('stefanvdlightareoff');
if (ActionToTake == "hide")
{ opacity = default_opacity; reduceOpacity(); }
else if (ActionToTake == "show")
{ increaseOpacity(); }
}
// Makes div increase
function increaseOpacity()
{
// If opacity level is less than default_opacity, we can still increase the opacity
if ((opacity < default_opacity) && (ReducingFinished == true))
{
ReducingFinished = true;
opacity += OpacityLevelIncrement;
DIVElementById.style.opacity = opacity/100;
setTimeout("increaseOpacity()", FadeDelayMS);
}
else
{
ReducingFinished = false;
}
}
// Makes div reduce
function reduceOpacity()
{
// If opacity level is greater than 0, we can still reduce the opacity
if ((opacity > 0) && (ReducingFinished == false))
{
ReducingFinished = false;
opacity -= OpacityLevelIncrement;
DIVElementById.style.opacity = (opacity/100);
setTimeout("reduceOpacity()", FadeDelayMS);
}
else
{
ReducingFinished = true;
// When finished, make sure the DIVElementById is set to remove element
if (DIVElementById.style.opacity = "0")
{document.body.removeChild(DIVElementById);}
}
}
chrome.extension.sendRequest({comando:'iopacity'}, function(response){
console.log(response.iopacity);
var autoplay = response.autoplay;
if(autoplay == 'true'){
var click = false;
// Start autoplay flash to show dark div
startautoplay = setInterval(
function () {
try {
// See
http://code.google.com/apis/youtube/...layback_status
// The number 1 show for => if playing video
if (document.getElementById("movie_player").getPlayer State() == 1) {autorun();}
}
catch(err) {} // i see nothing, that is good
},100); // 100 refreshing it
// autoplay html5
autoplayhtml5 = setInterval(function () {
try {
if ( document.getElementsByTagName('video')[0].currentTime > 0 ) {autorun();}
}
catch(err) {} // i see nothing, that is good
},100); // 100 refreshing it
function autorun(){
///////////////////// Begin dark from light.js
var blackon = $('stefanvdlightareoff');
// Black div on
if(blackon) {
// Do nothing
}
else
{
if(click == false)
{
// MAC & PC & LINUX
var movieplayer = $('movie_player');
if(movieplayer){$('movie_player').style.zIndex = 1000;$('movie_player').style.visibility = 'visible';$('movie_player').style.position = 'relative';}
// Youtube Channel, fixed show video
var player = $('playnav-player');
if(player)$('playnav-player').style.zIndex = 1000;
var userplaylist = $('user_playlist_navigator');
if(userplaylist)$('user_playlist_navigator').style .zIndex = 'auto';
var playnav = $('playnav-body');
if(playnav)$('playnav-body').style.zIndex = 'auto';
// HTML5
var html5player = $('html5-player');
if(html5player){$('html5-player').style.zIndex = 1001;$('html5-player').style.visibility = 'visible';$('html5-player').style.position = 'relative';}
var youtubehtml5 = $('video-player');
if(youtubehtml5){$('video-player').style.zIndex = 1001;$('video-player').style.visibility = 'visible';$('video-player').style.position = 'relative';}
// Show YouTube playlist
var playlist = response.playlist;
if(playlist == 'true'){
var watchsidebar = $('watch-sidebar');
if(watchsidebar){$('watch-sidebar').style.zIndex = 1001;$('watch-sidebar').style.position = 'relative';}
div = document.getElementsByTagName("div");
for(var i = 0; i < div.length; i++ )
{
if(div
.className == ("watch-module-body") ) {div.style.background = 'none';}
}
div = document.getElementsByTagName("div");
for(var i = 0; i < div.length; i++ )
{
if(div.className == ("yt-uix-expander-body watch-module-body") ) {div.style.background = 'none';}
}
}
// Show YouTube Channel name
var head = response.head ;
if(head == 'true'){
try {
var watchheadline = $('watch-headline-user-info');
if(watchheadline){$('watch-headline-user-info').style.zIndex = 1000;$('watch-headline-user-info').style.position = 'relative';}
var watchchannel = $('watch-channel-discoverbox');
if(watchchannel){$('watch-channel-discoverbox').style.zIndex = 1000;$('watch-channel-discoverbox').style.position = 'relative';$('watch-channel-discoverbox').style.background = 'white';}
var watchmore = $('watch-more-from-user');
if(watchmore){$('watch-more-from-user').style.zIndex = 1000;$('watch-more-from-user').style.position = 'relative';$('watch-more-from-user').style.background = 'none';}
var watchuser = $('watch-userbanner');
if(watchuser){$('watch-userbanner').style.zIndex = 1000;$('watch-userbanner').style.position = 'relative';$('watch-userbanner').style.background = 'white';}
span = document.getElementsByTagName("span");
for(var i = 0; i < span.length; i++ )
{
if(span.className == ("watch-expander-head yt-uix-expander-head yt-rounded") ) {span.style.background = 'white';}
}
}
catch(err) {} // i see nothing, that is good
}
// Dailymotion HTML5, fixed show video
if((document.URL.indexOf('http://openvideo.dailymotion.com') == 0))
{
var v1 = $('v1');
if(v1){$('v1').style.zIndex = 1001;$('v1').style.visibility = 'visible';$('v1').style.position = 'relative';}
div = document.getElementsByTagName("div");
for(var i = 0; i < div.length; i++ )
{
if(div.className == ("dmpi_playerhtml5 dm_widget_videoplayer") ) {div.style.zIndex = 1000;}
}
}
var interval = response.iopacity;
if(!interval)interval = 80;
var color = response.colors;
if(color)color = '#' + response.colors;
else color = '#000000';
default_opacity = interval; //(gammaVal/100);
var newdiv = document.createElement('div');
newdiv.setAttribute('id','stefanvdlightareoff');
newdiv.style.width = "100%";
newdiv.style.height = "100%";
newdiv.style.left = "0";
newdiv.style.top = "0";
newdiv.style.position = "fixed";
newdiv.style.background = color;
newdiv.style.opacity = 0;
newdiv.style.zIndex = "999";
// fade out effect
var fadeout = response.fadeout;
if(!fadeout)fadeout = 'false'; // default fadeout false
if(fadeout == 'true'){newdiv.onclick = function() {fader('hide')}; click = true;}
else{newdiv.onclick = function() {document.body.removeChild(newdiv); click = true;}}
document.body.appendChild(newdiv);
// fade in effect
var fadein = response.fadein;
if(!fadein)fadein = 'true'; // default fadein true
if(fadein == 'true'){fader('show');}
else{newdiv.style.opacity = default_opacity/100;} // no fade effect
} //click false
else{
var blackon = $('stefanvdlightareoff');
if(blackon) {
var fadeout = response.fadeout;
if(!fadeout)fadeout = 'false'; // default fadeout false
if(fadeout == 'true'){newdiv.onclick = function() {fader('hide')}; click = true;}
else{newdiv.onclick = function() {document.body.removeChild(newdiv); click = true;}}
}
}
///////////////////// End dark from light.js
}
} // option autoplay on end
}});
// here the easter eggs 1 => movie theater
window.onkeypress = function(key)
{
if (document.getElementById("stefanvdlightareoff"))
{
if(key.keyCode=='116') // T
{
if (document.getElementById("stefanvdtheater")){}
else {
alert('Do you like a real movie theater?');
var newimg = document.createElement('img');
newimg.setAttribute('id','stefanvdtheater');
newimg.src = chrome.extension.getURL("/images/theater.png");
newimg.style.left = "0";
newimg.style.top = "0";
newimg.style.position = "fixed";
newimg.style.width = "100%";
newimg.style.height = "100%";
newimg.style.zIndex = "998";
newimg.onclick = function() { document.body.removeChild(newimg); };
document.body.appendChild(newimg);
}
}
}
// end
}