2016-11-06 01:07:28 +00:00
/* Thanks to StephenLynx, I modified his Theme Changer from the Penumbra Lynx Frontend for the Lynxchan Software https://gitgud.io/LynxChan/LynxChan and reused it to make f0ck a nicer place. */
2016-11-05 17:06:15 +00:00
var themes = [ {
2016-11-05 17:23:26 +00:00
file : 'cyber.css' ,
2016-11-05 17:06:15 +00:00
label : 'Cyber' ,
id : 'cyber'
} , {
2016-11-05 18:13:43 +00:00
file : 'pink.css' ,
label : 'pinkf0ck' ,
id : 'pink'
2016-11-05 23:56:41 +00:00
} , {
file : 'term.css' ,
label : 'TERM' ,
id : 'TERM'
2016-11-19 09:47:37 +00:00
} , {
2016-11-19 09:49:36 +00:00
file : 'coldblue.css' ,
2016-11-19 09:47:37 +00:00
label : 'COLD' ,
2017-02-01 05:32:13 +00:00
id : 'COLD' ,
} , {
file : 'krautchan.css' ,
label : 'Krautchan' ,
id : 'KC'
} ] ;
2016-11-05 17:06:15 +00:00
var customCss ;
var addedTheme ;
function updateCss ( ) {
if ( addedTheme ) {
addedTheme . parentNode . removeChild ( addedTheme ) ;
addedTheme = null ;
}
for ( var i = 0 ; i < themes . length ; i ++ ) {
var theme = themes [ i ] ;
if ( theme . id === localStorage . selectedTheme ) {
addedTheme = theme . element ;
2016-11-05 17:22:09 +00:00
document . head . insertBefore ( theme . element , customCss ) ;
2016-11-05 17:06:15 +00:00
}
}
}
2016-11-17 06:00:12 +00:00
for ( var i = 0 ; i < document . head . children . length ; i ++ ) {
var element = document . head . children [ i ] ;
if ( element . rel === 'stylesheet' && element . href . indexOf ( '/custom.css' ) > - 1 ) {
customCss = element ;
break ;
2016-11-05 17:06:15 +00:00
}
2016-11-17 06:00:12 +00:00
}
for ( var i = 0 ; i < themes . length ; i ++ ) {
themes [ i ] . element = document . createElement ( 'link' ) ;
themes [ i ] . element . type = 'text/css' ;
themes [ i ] . element . rel = 'stylesheet' ;
themes [ i ] . element . href = './s/' + themes [ i ] . file ;
}
updateCss ( ) ;
var postingLink = document . getElementById ( 'themes' ) ;
if ( postingLink ) {
var divider = document . createElement ( 'span' ) ;
divider . innerHTML = '' ;
var referenceNode = postingLink . nextSibling ;
postingLink . parentNode . insertBefore ( divider , referenceNode ) ;
var themeSelector = document . createElement ( 'select' ) ;
themeSelector . id = 'themeSelector' ;
var vanillaOption = document . createElement ( 'option' ) ;
vanillaOption . innerHTML = 'Default' ;
themeSelector . appendChild ( vanillaOption ) ;
for ( i = 0 ; i < themes . length ; i ++ ) {
var theme = themes [ i ] ;
var themeOption = document . createElement ( 'option' ) ;
themeOption . innerHTML = theme . label ;
if ( theme . id === localStorage . selectedTheme ) {
themeOption . selected = true ;
}
themeSelector . appendChild ( themeOption ) ;
2016-11-05 17:06:15 +00:00
}
2016-11-17 06:00:12 +00:00
themeSelector . onchange = function ( ) {
if ( ! themeSelector . selectedIndex ) {
if ( localStorage . selectedTheme ) {
delete localStorage . selectedTheme ;
updateCss ( ) ;
2016-11-05 17:06:15 +00:00
}
2016-11-17 06:00:12 +00:00
return ;
2016-11-05 17:06:15 +00:00
}
2016-11-17 06:00:12 +00:00
var selectedTheme = themes [ themeSelector . selectedIndex - 1 ] ;
if ( selectedTheme . id === localStorage . selectedTheme ) {
return ;
}
localStorage . selectedTheme = selectedTheme . id ;
updateCss ( ) ;
} ;
postingLink . parentNode . insertBefore ( themeSelector , referenceNode ) ;
}