From 44f83a756a7e4218abbc997ae523cb1a974e3e8c Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sun, 25 Aug 2013 11:16:59 -0700 Subject: [PATCH] Fix #329 --- builds/appchan-x.user.js | 39 ++++++++++++++++++++++++------------- builds/crx/script.js | 39 ++++++++++++++++++++++++------------- src/General/Settings.coffee | 36 +++++++++++++++++++++------------- 3 files changed, 74 insertions(+), 40 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index aa9a0ef36..826e52b20 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -14394,7 +14394,7 @@ Settings = { init: function() { - var el, settings; + var addSection, check, el, key, settings, value, _ref; el = $.el('a', { className: 'settings-link', @@ -14431,24 +14431,37 @@ } return $.set('previousversion', g.VERSION); }); - Settings.addSection('Style', Settings.style); - Settings.addSection('Themes', Settings.themes); - Settings.addSection('Mascots', Settings.mascots); - Settings.addSection('Script', Settings.main); - Settings.addSection('Filter', Settings.filter); - Settings.addSection('Sauce', Settings.sauce); - Settings.addSection('Advanced', Settings.advanced); - Settings.addSection('Keybinds', Settings.keybinds); + addSection = Settings.addSection; + _ref = { + 'style': 'Style', + 'themes': 'Themes', + 'mascots': 'Mascots', + 'main': 'Script', + 'filter': 'Filter', + 'sauce': 'Sauce', + 'advanced': 'Advanced', + 'keybinds': 'Keybinds' + }; + for (key in _ref) { + value = _ref[key]; + addSection(value, Settings[key]); + } $.on(d, 'AddSettingsSection', Settings.addSection); $.on(d, 'OpenSettings', function(e) { return Settings.open(e.detail); }); settings = JSON.parse(localStorage.getItem('4chan-settings')) || {}; - if (settings.disableAll) { - return; + if (!settings.disableAll) { + settings.disableAll = true; + check = true; + } + if (settings.keyBinds) { + settings.keyBinds = false; + check = true; + } + if (check) { + return localStorage.setItem('4chan-settings', JSON.stringify(settings)); } - settings.disableAll = true; - return localStorage.setItem('4chan-settings', JSON.stringify(settings)); }, open: function(openSection) { var dialog, link, links, overlay, section, sectionToOpen, _i, _len, _ref; diff --git a/builds/crx/script.js b/builds/crx/script.js index 1a2dcbfd9..1703404d0 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -14388,7 +14388,7 @@ Settings = { init: function() { - var el, settings; + var addSection, check, el, key, settings, value, _ref; el = $.el('a', { className: 'settings-link', @@ -14425,24 +14425,37 @@ } return $.set('previousversion', g.VERSION); }); - Settings.addSection('Style', Settings.style); - Settings.addSection('Themes', Settings.themes); - Settings.addSection('Mascots', Settings.mascots); - Settings.addSection('Script', Settings.main); - Settings.addSection('Filter', Settings.filter); - Settings.addSection('Sauce', Settings.sauce); - Settings.addSection('Advanced', Settings.advanced); - Settings.addSection('Keybinds', Settings.keybinds); + addSection = Settings.addSection; + _ref = { + 'style': 'Style', + 'themes': 'Themes', + 'mascots': 'Mascots', + 'main': 'Script', + 'filter': 'Filter', + 'sauce': 'Sauce', + 'advanced': 'Advanced', + 'keybinds': 'Keybinds' + }; + for (key in _ref) { + value = _ref[key]; + addSection(value, Settings[key]); + } $.on(d, 'AddSettingsSection', Settings.addSection); $.on(d, 'OpenSettings', function(e) { return Settings.open(e.detail); }); settings = JSON.parse(localStorage.getItem('4chan-settings')) || {}; - if (settings.disableAll) { - return; + if (!settings.disableAll) { + settings.disableAll = true; + check = true; + } + if (settings.keyBinds) { + settings.keyBinds = false; + check = true; + } + if (check) { + return localStorage.setItem('4chan-settings', JSON.stringify(settings)); } - settings.disableAll = true; - return localStorage.setItem('4chan-settings', JSON.stringify(settings)); }, open: function(openSection) { var dialog, link, links, overlay, section, sectionToOpen, _i, _len, _ref; diff --git a/src/General/Settings.coffee b/src/General/Settings.coffee index 55baf695d..30d470032 100755 --- a/src/General/Settings.coffee +++ b/src/General/Settings.coffee @@ -6,7 +6,7 @@ Settings = href: 'javascript:;' textContent: 'Settings' $.on el, 'click', Settings.open - + $.event 'AddMenuEntry', type: 'header' el: el @@ -30,22 +30,30 @@ Settings = $.on d, '4chanXInitFinished', Settings.open $.set 'previousversion', g.VERSION - Settings.addSection 'Style', Settings.style - Settings.addSection 'Themes', Settings.themes - Settings.addSection 'Mascots', Settings.mascots - Settings.addSection 'Script', Settings.main - Settings.addSection 'Filter', Settings.filter - Settings.addSection 'Sauce', Settings.sauce - Settings.addSection 'Advanced', Settings.advanced - Settings.addSection 'Keybinds', Settings.keybinds + {addSection} = Settings + addSection value, Settings[key] for key, value of { + 'style': 'Style' + 'themes': 'Themes' + 'mascots': 'Mascots' + 'main': 'Script' + 'filter': 'Filter' + 'sauce': 'Sauce' + 'advanced': 'Advanced' + 'keybinds': 'Keybinds' + } - $.on d, 'AddSettingsSection', Settings.addSection - $.on d, 'OpenSettings', (e) -> Settings.open e.detail + $.on d, 'AddSettingsSection', Settings.addSection + $.on d, 'OpenSettings', (e) -> Settings.open e.detail settings = JSON.parse(localStorage.getItem '4chan-settings') or {} - return if settings.disableAll - settings.disableAll = true - localStorage.setItem '4chan-settings', JSON.stringify settings + unless settings.disableAll + settings.disableAll = true + check = true + if settings.keyBinds + # Keybinds persist even with disableAll. Thanks moot. + settings.keyBinds = false + check = true + localStorage.setItem '4chan-settings', JSON.stringify settings if check open: (openSection) -> if Conf['editMode'] is "theme"