Last active
December 31, 2015 14:39
-
-
Save liddiard/8001125 to your computer and use it in GitHub Desktop.
F.lux for the web
This file contains hidden or 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
// requires jQuery | |
function Color(r,g,b,a) { | |
this.r = parseInt(r); | |
this.g = parseInt(g); | |
this.b = parseInt(b); | |
this.a = parseFloat(a); | |
} | |
Color.prototype.rgb = function() { | |
var a = isNaN(this.a) ? "" : ","+this.a; | |
return "rgb(" + this.r + "," + this.g + "," + this.b + a + ")"; | |
} | |
Color.prototype.normalize = function() { | |
this.r = Math.round(this.r); | |
this.g = Math.round(this.g); | |
this.b = Math.round(this.b); | |
} | |
function duskify(elems) { | |
for (var i = elems.length; i--;) { | |
var elem = $(elems[i]); | |
var channels = elem.css('background-color').match(/\d+/g); | |
if (channels.length === 3) | |
var rgb = new Color(channels[0], channels[1], channels[2]); | |
else | |
var rgb = new Color(channels[0], channels[1], channels[2], channels[3]); | |
rgb.g /= 1.15; | |
rgb.b /= 1.15; | |
rgb.normalize(); | |
elem.css('background-color', rgb.rgb()); | |
} | |
} | |
$(document).ready(function(){ | |
var body = document.getElementsByTagName('body'); // get the body element itself | |
duskify(body); | |
var body_elems = document.body.getElementsByTagName('*'); // get every item under body | |
duskify(body_elems); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment