Skip to content

Instantly share code, notes, and snippets.

@chadlavi
Last active January 27, 2019 20:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadlavi/d57509a35bc03305b28b3938dab0594f to your computer and use it in GitHub Desktop.
Save chadlavi/d57509a35bc03305b28b3938dab0594f to your computer and use it in GitHub Desktop.
Night Mode
// ==UserScript==
// @name Night Mode
// @namespace https://gist.github.com/chadlavi/d57509a35bc03305b28b3938dab0594f
// @downloadURL https://gist.github.com/chadlavi/d57509a35bc03305b28b3938dab0594f/raw/night-mode.user.js
// @updateURL https://gist.github.com/chadlavi/d57509a35bc03305b28b3938dab0594f/raw/night-mode.user.js
// @version 2.53
// @description turn on night mode between the night and morning times
// @author Chad Lavimoniere
// @include http*://6.f*.org/*
// @grant none
// @run-at document-body
// ==/UserScript==
(function() {
/*jshint multistr: true */
'use strict';
/* VARIABLES */
var night = '21' // this one's the start time at night
var morning = '6' // this one's the end time in the morning
var link = '#017bfe' // link color
var background = '#000000' // page background color
var text = '#d2b319' // text color
function setCookie(cname, cvalue, exhours) {
var d = new Date();
d.setTime(d.getTime() + (exhours * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function nightMode() {
$('*').css({'color':text,'background-color':background})
$('input, textarea').css({'border':'1px solid '+text})
$('a').css({'color':link})
$('#banner_image').css({'background-color':'none','filter':'invert(1)'})
$('#banner').css({'border-bottom': '1px dotted #d2b319'})
$('.image-hider').css({'background-color':background,'color':text})
$('*').css({'outline':'none'})
$('#nightmode').click(function(){ setCookie('nightmode','off',12); history.go(0); return false; });
}
function nightModeInsert() {
document.body.insertAdjacentHTML('afterbegin', '<div id="nightmode" style="\
position: fixed; \
top: 0; \
right: 0; \
border: none; \
background-color: '+background+'; \
color: '+text+'; \
border: 1px solid '+text+'; \
padding: 5px 10px; \
cursor: pointer; \
z-index: 2;" \
title="click to toggle for 12 hours">night mode 🌔</div>');
}
var currentdate = new Date()
var hour = currentdate.getHours();
if(hour >= night || hour < morning) {
nightModeInsert()
if(getCookie('nightmode') != 'off'){
nightMode();
} else {
$('#nightmode').click(function(){ setCookie('nightmode','on',12); history.go(0); return false; });
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment