autism die zweite

This commit is contained in:
Flummi 2016-11-17 07:00:12 +01:00
parent bb7eda3a1a
commit 2af6dfb63d
4 changed files with 67 additions and 108 deletions

View File

@ -1,5 +1,4 @@
/* 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. */ /* 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. */
var themes = [ { var themes = [ {
file : 'cyber.css', file : 'cyber.css',
label : 'Cyber', label : 'Cyber',
@ -13,109 +12,69 @@ var themes = [ {
label : 'TERM', label : 'TERM',
id : 'TERM' id : 'TERM'
}]; }];
var customCss; var customCss;
var addedTheme; var addedTheme;
function updateCss() { function updateCss() {
if (addedTheme) { if (addedTheme) {
addedTheme.parentNode.removeChild(addedTheme); addedTheme.parentNode.removeChild(addedTheme);
addedTheme = null; addedTheme = null;
} }
for (var i = 0; i < themes.length; i++) { for (var i = 0; i < themes.length; i++) {
var theme = themes[i]; var theme = themes[i];
if (theme.id === localStorage.selectedTheme) { if (theme.id === localStorage.selectedTheme) {
addedTheme = theme.element; addedTheme = theme.element;
document.head.insertBefore(theme.element, customCss); document.head.insertBefore(theme.element, customCss);
} }
} }
} }
for (var i = 0; i < document.head.children.length; i++) { for (var i = 0; i < document.head.children.length; i++) {
var element = document.head.children[i]; var element = document.head.children[i];
if (element.rel === 'stylesheet' && element.href.indexOf('/custom.css') > -1) {
if (element.rel === 'stylesheet'
&& element.href.indexOf('/custom.css') > -1) {
customCss = element; customCss = element;
break; break;
} }
} }
for (var i = 0; i < themes.length; i++) { for (var i = 0; i < themes.length; i++) {
themes[i].element = document.createElement('link'); themes[i].element = document.createElement('link');
themes[i].element.type = 'text/css'; themes[i].element.type = 'text/css';
themes[i].element.rel = 'stylesheet'; themes[i].element.rel = 'stylesheet';
themes[i].element.href = './s/' + themes[i].file; themes[i].element.href = './s/' + themes[i].file;
} }
updateCss(); updateCss();
var postingLink = document.getElementById('themes'); var postingLink = document.getElementById('themes');
if (postingLink) { if (postingLink) {
var divider = document.createElement('span'); var divider = document.createElement('span');
divider.innerHTML = ''; divider.innerHTML = '';
var referenceNode = postingLink.nextSibling; var referenceNode = postingLink.nextSibling;
postingLink.parentNode.insertBefore(divider, referenceNode); postingLink.parentNode.insertBefore(divider, referenceNode);
var themeSelector = document.createElement('select'); var themeSelector = document.createElement('select');
themeSelector.id = 'themeSelector'; themeSelector.id = 'themeSelector';
var vanillaOption = document.createElement('option'); var vanillaOption = document.createElement('option');
vanillaOption.innerHTML = 'Default'; vanillaOption.innerHTML = 'Default';
themeSelector.appendChild(vanillaOption); themeSelector.appendChild(vanillaOption);
for (i = 0; i < themes.length; i++) { for (i = 0; i < themes.length; i++) {
var theme = themes[i]; var theme = themes[i];
var themeOption = document.createElement('option'); var themeOption = document.createElement('option');
themeOption.innerHTML = theme.label; themeOption.innerHTML = theme.label;
if (theme.id === localStorage.selectedTheme) { if (theme.id === localStorage.selectedTheme) {
themeOption.selected = true; themeOption.selected = true;
} }
themeSelector.appendChild(themeOption); themeSelector.appendChild(themeOption);
} }
themeSelector.onchange = function() { themeSelector.onchange = function() {
if (!themeSelector.selectedIndex) { if (!themeSelector.selectedIndex) {
if (localStorage.selectedTheme) { if (localStorage.selectedTheme) {
delete localStorage.selectedTheme; delete localStorage.selectedTheme;
updateCss(); updateCss();
} }
return; return;
} }
var selectedTheme = themes[themeSelector.selectedIndex - 1]; var selectedTheme = themes[themeSelector.selectedIndex - 1];
if (selectedTheme.id === localStorage.selectedTheme) { if (selectedTheme.id === localStorage.selectedTheme) {
return; return;
} }
localStorage.selectedTheme = selectedTheme.id; localStorage.selectedTheme = selectedTheme.id;
updateCss(); updateCss();
}; };
postingLink.parentNode.insertBefore(themeSelector, referenceNode); postingLink.parentNode.insertBefore(themeSelector, referenceNode);
} }