Greasy Fork is available in English.

Background giorno/notte

Change thema background color

// ==UserScript==
// @name        Background giorno/notte
// @description Change thema background color
// @author      figuccio
// @namespace https://greasyfork.org/users/237458
// @include     *
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       GM_registerMenuCommand
// @icon		https://images2.imgbox.com/b3/67/Aq5XazuW_o.png
// @version     0.2
// @noframes
// ==/UserScript==

//Set Cookie
var date = new Date();
date.setDate(date.getDate() + 10000*1000).toLocaleString();

var exp_date = new Date();
exp_date.setDate(exp_date.getDate() - 10000).toLocaleString();

var cookie = document.cookie.toString();
var color_str = /bgcolor=[a-z#0-9]*/i;
var check = color_str.exec(cookie);
if(check){
var current_bgcolor = check.toString().slice(8);
}
if(current_bgcolor){
document.body.style.background = current_bgcolor;
}

//Cancella cookie
function remove(){
var current_bgcolor_str = "bgcolor="+current_bgcolor;
document.cookie = current_bgcolor_str+';expires='+exp_date;
}

//CSS Here
var css1 = "a#color_button{text-align:center;padding-left:1px;width:67px;color:green;background:#d8d8d8;display:block;font-size:16px;border:2px red solid;}";
var css2 = "div#main_div{cursor:pointer;}div#colors{cursor:pointer;padding-left:2px;padding-top:4px;padding-bottom:4px;}span.colors{text-align:center;display:block;border:1px solid red};";
var css = css1 + css2;
var head = document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = "text/css";
style.innerHTML = css;
head.insertBefore(style,head.childNodes[1]);

// Scelte di colori
var inner_code1 = '<div id="main_div"><a id="color_button">MENU</a></div><br>';

//Aggiungi i colori qui  //'<span class="colors" id="color">COLOR</span><br>'+ //
var inner_code2 = ['<div id="colors">'+
'<span class="colors" id="black" style="background:black;color:green">NERO</span><br>'+
'<span class="colors" id="white" style="background:white;color:green">BIANCO</span><br>'+
'</div>'].join();

var inner_code = inner_code1 + inner_code2;
var div = function(){
var a = document.getElementsByTagName('body')[0];
var b = document.createElement('div');
b.style.position = 'absolute';
b.style.top = '160px';//50px
b.style.left = '0px';
b.innerHTML = inner_code;
a.appendChild(b);
}
div();


//Hide or Show
if(document.cookie.toString().match(/block/)){
$("#colors").show();
}
else if(document.cookie.toString().match(/none/)){
$("#colors").hide();
}
else{
$(function(){$("#colors").hide();})
}


var disp;
$("#main_div").click(function() {
    	$("#colors").slideToggle(function get_disp(){  //funzione di richiamata
    disp = document.getElementById('colors').style.display;
    document.cookie = disp +';expires='+date;
});

});
//black
var black = document.getElementById('black');
black.onclick = function(){
remove();
document.body.style.background = "black";
var color = "bgcolor=black";
document.cookie= color+';expires='+date;
}

//bianco
var white = document.getElementById('white');
white.onclick = function(){
remove();
document.body.style.background = "white";
var color = "bgcolor=white";
document.cookie= color+';expires='+date;
}

function myFunctiongn() {
  if (main_div.style.display === 'none') {
    main_div.style.display = 'block';
  } else {
    main_div.style.display = 'none';
  }
}
GM_registerMenuCommand("mostra/nascondi",myFunctiongn);


//////

function myFunctionnero() {
    document.body.style.background = 'black';}
    GM_registerMenuCommand("nero",myFunctionnero);

//
function myFunctionbianco() {
    document.body.style.background = 'white';}
    GM_registerMenuCommand("bianco",myFunctionbianco);