Add a Reset Settings button.

This commit is contained in:
Mayhem 2014-01-22 16:33:08 +01:00
parent 0b39d6d3f5
commit c7c8ea9ec5
5 changed files with 27 additions and 7 deletions

View File

@ -1,3 +1,5 @@
- Added a `Reset Settings` button in the settings.
### 3.15.2 - *2014-01-22*
- More stability update.

View File

@ -1,6 +1,7 @@
<div class="imp-exp">
<button class="export">Export Settings</button>
<button class="import">Import Settings</button>
<input type="file" style="visibility: hidden;">
<button class="reset">Reset Settings</button>
<input type="file" hidden>
</div>
<p class="imp-exp-result"></p>

View File

@ -300,6 +300,15 @@ $.set = do ->
else
$.extend items.sync, key
setAll()
$.clear = (cb) ->
count = 2
done = ->
if chrome.runtime.lastError
c.error chrome.runtime.lastError.message
return
cb?() unless --count
chrome.storage.local.clear done
chrome.storage.sync.clear done
<% } else { %>
# http://wiki.greasespot.net/Main_Page
$.sync = do ->
@ -341,4 +350,7 @@ $.set = do ->
for key, val of keys
set key, val
return
$.clear = (cb) ->
$.delete GM_listValues().map (key) -> key.replace g.NAMESPACE, ''
cb?()
<% } %>

View File

@ -96,6 +96,7 @@ Settings =
section.innerHTML = <%= importHTML('General/Settings-section-Main') %>
$.on $('.export', section), 'click', Settings.export
$.on $('.import', section), 'click', Settings.import
$.on $('.reset', section), 'click', Settings.reset
$.on $('input', section), 'change', Settings.onImport
items = {}
@ -154,7 +155,7 @@ Settings =
<% } %>
a.click()
import: ->
@nextElementSibling.click()
$('input', @parentNode).click()
onImport: ->
return unless file = @files[0]
output = @parentNode.nextElementSibling
@ -174,6 +175,11 @@ Settings =
loadSettings: (data) ->
version = data.version.split '.'
if version[0] is '2'
convertSettings = (data, map) ->
for prevKey, newKey of map
data.Conf[newKey] = data.Conf[prevKey] if newKey
delete data.Conf[prevKey]
data
data = Settings.convertSettings data,
# General confs
'Disable 4chan\'s extension': ''
@ -243,11 +249,9 @@ Settings =
data.Conf['watchedThreads'] = boards: ThreadWatcher.convert data.Conf['WatchedThreads']
delete data.Conf['WatchedThreads']
$.set data.Conf
convertSettings: (data, map) ->
for prevKey, newKey of map
data.Conf[newKey] = data.Conf[prevKey] if newKey
delete data.Conf[prevKey]
data
reset: ->
if confirm 'Your current settings will be entirely wiped, are you sure?'
$.clear -> window.location.reload() if confirm 'Reset successful. Reload now?'
filter: (section) ->
section.innerHTML = <%= importHTML('General/Settings-section-Filter') %>

View File

@ -14,6 +14,7 @@
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant GM_openInTab
// @run-at document-start
// @updateURL <%= meta.page %><%= meta.buildsPath %><%= name %>.meta.js