2017-05-07 18:19:37 +02:00
var night = localStorage . getItem ( "night" ) ;
function toggleNightMode ( ) {
2017-05-07 20:49:59 +02:00
var night = localStorage . getItem ( "night" ) ;
if ( night == "true" ) {
2017-05-13 23:07:49 +02:00
document . getElementsByTagName ( "head" ) [ 0 ] . removeChild ( darkStyleLink ) ;
2017-05-07 20:49:59 +02:00
} else {
2017-05-13 23:07:49 +02:00
document . getElementsByTagName ( "head" ) [ 0 ] . appendChild ( darkStyleLink ) ;
2017-05-07 18:19:37 +02:00
}
2017-05-07 20:49:59 +02:00
localStorage . setItem ( "night" , ( night == "true" ) ? "false" : "true" ) ;
2017-05-07 18:19:37 +02:00
}
2017-05-05 12:59:56 +02:00
// Used by spoiler tags
function toggleLayer ( elem ) {
if ( elem . classList . contains ( "hide" ) )
elem . classList . remove ( "hide" ) ;
else
elem . classList . add ( "hide" ) ;
}
2017-05-05 15:55:25 +02:00
2017-05-07 20:49:59 +02:00
// Date formatting
2017-05-05 15:55:25 +02:00
function formatDate ( date ) { // thanks stackoverflow
var monthNames = [
"January" , "February" , "March" ,
"April" , "May" , "June" , "July" ,
"August" , "September" , "October" ,
"November" , "December"
] ;
var day = date . getDate ( ) ;
var monthIndex = date . getMonth ( ) ;
var year = date . getFullYear ( ) ;
return day + ' ' + monthNames [ monthIndex ] + ' ' + year ;
}
var list = document . getElementsByClassName ( "date-short" ) ;
for ( var i in list ) {
var e = list [ i ] ;
e . title = e . innerText ;
e . innerText = formatDate ( new Date ( e . innerText ) ) ;
}
var list = document . getElementsByClassName ( "date-full" ) ;
for ( var i in list ) {
var e = list [ i ] ;
e . title = e . innerText ;
var date = new Date ( e . innerText ) ;
e . innerText = date . toDateString ( ) + " " + date . toLocaleTimeString ( ) ;
}
2017-05-13 00:37:37 +02:00
/*Fixed-Navbar offset fix*/
window . onload = function ( ) {
var shiftWindow = function ( ) { scrollBy ( 0 , - 70 ) } ;
if ( location . hash ) shiftWindow ( ) ;
window . addEventListener ( "hashchange" , shiftWindow ) ;
} ;
2017-05-13 02:01:17 +02:00
function loadLanguages ( ) {
var xhr = new XMLHttpRequest ( ) ;
xhr . onreadystatechange = function ( ) {
if ( xhr . readyState == 4 && xhr . status == 200 ) {
var selector = document . getElementById ( "bottom_language_selector" ) ;
selector . hidden = false
/ * R e s p o n s e f o r m a t i s
* { "current" : "(user current language)" ,
* "languages" : {
* "(language_code)" : "(language_name" ) ,
* } } * /
var response = JSON . parse ( xhr . responseText ) ;
for ( var language in response . languages ) {
if ( ! response . languages . hasOwnProperty ( language ) ) continue ;
var opt = document . createElement ( "option" )
opt . value = language
opt . innerHTML = response . languages [ language ]
if ( language == response . current ) {
opt . selected = true
}
selector . appendChild ( opt )
}
}
}
xhr . open ( "GET" , "/language?format=json" , true )
xhr . send ( )
}
2017-05-14 14:39:48 +02:00
loadLanguages ( ) ;