User:Guy Bukzi Montag/common.js

// ************************************************** // Experimental javascript countdown timer (Splarka) // Version 0.0.3 // ************************************************** // // Usage example: // //  Only January 01 2007 00:00:00 PST until New years. // //  Javascript disabled.

function zeroPadding(number) { number = (number < 10 ? '0' : '' ) + number; return number; }

function multiplayerGlobalBonus (date) { var start = new Date("2018-10-01"); var diff = count=Math.floor((date.getTime-start.getTime)/1000/60/60/24); // calcuate bonus switch (diff%7) { case 0: case 1: return 50; case 2: case 3: case 6: return 25; default: return 0; } }

function updatetimer(i) { var now = new Date; switch (timers[i].type) { case "month": var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; timers[i].innerHTML = months[now.getUTCMonth]; break; case "day": timers[i].innerHTML = now.getUTCDate; break; case "time": var h = now.getUTCHours; var m = now.getUTCMinutes; h = zeroPadding(h); m = zeroPadding(m); timers[i].innerHTML = h + ":" + m;           break; case "seconds": var type = timers[i].type; var seconds = now.getUTCSeconds;

// calcuate current var current = seconds; timers[i].innerHTML = current + " " + type; break; case "multiplayer global bonus":

// calcuate bonus var bonus = multiplayerGlobalBonus(now); timers[i].innerHTML = bonus; break; default: // display countdown var then = timers[i].type; var diff = count=Math.floor((then.getTime-now.getTime)/1000); // catch bad date strings if(isNaN(diff)) { timers[i].innerHTML = '** ' + timers[i].type + ' **' ; return; }           // determine plus/minus if(diff<0) { diff = -diff; var tpm = ' '; } else { var tpm = ' '; }           // calcuate the diff var left = (diff%60) + ' seconds'; diff=Math.floor(diff/60); if(diff > 0) left = (diff%60) + ' minutes ' + left; diff=Math.floor(diff/60); if(diff > 0) left = (diff%24) + ' hours ' + left; diff=Math.floor(diff/24); if(diff > 0) left = diff + ' days ' + left; timers[i].innerHTML = tpm + left; }   timeouts[i] = setTimeout('updatetimer(' + i + ')',1000); }

function checktimers { //hide 'nocountdown' and show 'countdown' var classnotimers = document.getElementsByClassName("awnotimer"); console.log("classnotimers loaded. Probably."); for(var i in classnotimers) classnotimers[i].style.display = 'none'; console.log("classnotimers hidden."); var classtimers = document.getElementsByClassName("awtimer"); console.log("classtimers loaded. Probably."); for(var i in classtimers) { classtimers[i].style.display = 'inline'; console.log(i + ": " + classtimers[i].innerHTML); } console.log("For loop finished.");

//set up global objects timers and timeouts. timers = document.getElementsByClassName("awtimertype"); //global timeouts = new Array; // generic holder for the timeouts, global if (timers.length == 0) return; for(var i in timers) { switch (timers[i].innerHTML) { case "seconds": case "month": case "day": case "time": case "multiplayer global bonus": timers[i].type = timers[i].innerHTML; break; default: timers[i].type = new Date(timers[i].innerHTML); }       updatetimer(i);  //start it up    } } addOnloadHook(checktimers);

// ************************************************** // - end -  Experimental javascript countdown timer // **************************************************

// // Attempts to get a CSS variable into page code // Sanitizer doesn't allow simple // Example text

$("div").click(function {   var color = $(this).css("background-color");    $( "#result" ).html("That div is " + color + " ."); });

$(".testclass").css("color", returnVar("--test"));

$(function {   $("#bingo").html("The value of --test is: " + returnVar("--test") + "."); });

function returnVar(varName) { return window.getComputedStyle(document.documentElement).getPropertyValue(varName); // jQuery doesn't work: // return $(":root").css("--test") + " (jQuery)"; }