Don't show errors from local storage being disabled, and only show warnings when needed. #465
This commit is contained in:
parent
3723f7d06e
commit
7ad4645b81
@ -9,6 +9,7 @@ ThreadHiding =
|
||||
cb: @node
|
||||
|
||||
catalogSet: (board) ->
|
||||
return unless $.hasStorage
|
||||
hiddenThreads = ThreadHiding.db.get
|
||||
boardID: board.ID
|
||||
defaultValue: {}
|
||||
@ -16,6 +17,7 @@ ThreadHiding =
|
||||
localStorage.setItem "4chan-hide-t-#{board}", JSON.stringify hiddenThreads
|
||||
|
||||
catalogWatch: ->
|
||||
return unless $.hasStorage
|
||||
@hiddenThreads = JSON.parse(localStorage.getItem "4chan-hide-t-#{g.BOARD}") or {}
|
||||
Main.ready ->
|
||||
# 4chan's catalog sets the style to "display: none;" when hiding or unhiding a thread.
|
||||
|
||||
@ -43,8 +43,12 @@ Main =
|
||||
$.get items, (items) ->
|
||||
$.asap (-> doc = d.documentElement), ->
|
||||
|
||||
# Don't hide the local storage warning behind a settings panel.
|
||||
if $.cantSet
|
||||
# pass
|
||||
|
||||
# Fresh install
|
||||
if !items.previousversion?
|
||||
else if !items.previousversion?
|
||||
Main.ready ->
|
||||
$.set 'previousversion', g.VERSION
|
||||
Settings.open()
|
||||
@ -205,10 +209,16 @@ Main =
|
||||
$.event '4chanXInitFinished'
|
||||
|
||||
if Conf['Show Support Message']
|
||||
try
|
||||
localStorage.getItem '4chan-settings'
|
||||
catch err
|
||||
new Notice 'warning', 'Cookies need to be enabled on 4chan for <%= meta.name %> to operate properly.', 30
|
||||
if $.cantSync
|
||||
why = if $.cantSet
|
||||
'save your settings'
|
||||
else
|
||||
'synchronize data between tabs'
|
||||
new Notice 'warning', """
|
||||
<%= meta.name %> needs local storage to #{why}.
|
||||
Enable it on boards.4chan.org in your browser's privacy settings
|
||||
(may be listed as part of "local data" or "cookies").
|
||||
"""
|
||||
|
||||
initThread: ->
|
||||
if board = $ '.board'
|
||||
|
||||
@ -21,7 +21,7 @@ Settings =
|
||||
$.on d, 'AddSettingsSection', Settings.addSection
|
||||
$.on d, 'OpenSettings', (e) -> Settings.open e.detail
|
||||
|
||||
if Conf['Disable Native Extension']
|
||||
if Conf['Disable Native Extension'] and $.hasStorage
|
||||
settings = JSON.parse(localStorage.getItem '4chan-settings') or {}
|
||||
return if settings.disableAll
|
||||
settings.disableAll = true
|
||||
@ -140,8 +140,9 @@ Settings =
|
||||
$.on button, 'click', ->
|
||||
@textContent = 'Hidden: 0'
|
||||
$.get 'hiddenThreads', {}, ({hiddenThreads}) ->
|
||||
for boardID of hiddenThreads.boards
|
||||
localStorage.removeItem "4chan-hide-t-#{boardID}"
|
||||
if $.hasStorage
|
||||
for boardID of hiddenThreads.boards
|
||||
localStorage.removeItem "4chan-hide-t-#{boardID}"
|
||||
$.delete ['hiddenThreads', 'hiddenPosts']
|
||||
$.after $('input[name="Stubs"]', section).parentNode.parentNode, div
|
||||
|
||||
|
||||
@ -430,6 +430,7 @@ audio.controls-added {
|
||||
max-height: 200px;
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
/* Settings */
|
||||
|
||||
@ -338,6 +338,12 @@ $.engine = do ->
|
||||
return 'webkit' if /WebKit\//.test navigator.userAgent
|
||||
return 'gecko' if /Gecko\/|Goanna/.test navigator.userAgent # Goanna = Pale Moon 26+
|
||||
|
||||
try
|
||||
localStorage.getItem 'x'
|
||||
$.hasStorage = true
|
||||
catch err
|
||||
$.hasStorage = false
|
||||
|
||||
$.item = (key, val) ->
|
||||
item = {}
|
||||
item[key] = val
|
||||
@ -456,10 +462,13 @@ do ->
|
||||
if GM_deleteValue?
|
||||
$.getValue = GM_getValue
|
||||
$.listValues = -> GM_listValues() # error when called if missing
|
||||
else
|
||||
else if $.hasStorage
|
||||
$.getValue = (key) -> localStorage[key]
|
||||
$.listValues = ->
|
||||
key for key of localStorage when key[...g.NAMESPACE.length] is g.NAMESPACE
|
||||
else
|
||||
$.getValue = ->
|
||||
$.listValues = -> []
|
||||
|
||||
if GM_addValueChangeListener?
|
||||
$.setValue = GM_setValue
|
||||
@ -470,13 +479,14 @@ else if GM_deleteValue?
|
||||
GM_setValue key, val
|
||||
if key of $.syncing
|
||||
$.oldValue[key] = val
|
||||
localStorage[key] = val # for `storage` events
|
||||
localStorage[key] = val if $.hasStorage # for `storage` events
|
||||
$.deleteValue = (key) ->
|
||||
GM_deleteValue key
|
||||
if key of $.syncing
|
||||
delete $.oldValue[key]
|
||||
delete localStorage[key] # for `storage` events
|
||||
else
|
||||
delete localStorage[key] if $.hasStorage # for `storage` events
|
||||
$.cantSync = true if !$.hasStorage
|
||||
else if $.hasStorage
|
||||
$.oldValue = {}
|
||||
$.setValue = (key, val) ->
|
||||
$.oldValue[key] = val if key of $.syncing
|
||||
@ -484,6 +494,10 @@ else
|
||||
$.deleteValue = (key) ->
|
||||
delete $.oldValue[key] if key of $.syncing
|
||||
delete localStorage[key]
|
||||
else
|
||||
$.setValue = ->
|
||||
$.deleteValue = ->
|
||||
$.cantSync = $.cantSet = true
|
||||
|
||||
if GM_addValueChangeListener?
|
||||
$.sync = (key, cb) ->
|
||||
@ -492,7 +506,7 @@ if GM_addValueChangeListener?
|
||||
newValue = JSON.parse newValue unless newValue is undefined
|
||||
cb newValue, key
|
||||
$.forceSync = ->
|
||||
else
|
||||
else if $.hasStorage
|
||||
$.sync = (key, cb) ->
|
||||
key = g.NAMESPACE + key
|
||||
$.syncing[key] = cb
|
||||
@ -516,6 +530,9 @@ else
|
||||
# e.g. http://boards.4chan.org and https://boards.4chan.org
|
||||
# so force a check for changes to avoid lost data.
|
||||
onChange g.NAMESPACE + key
|
||||
else
|
||||
$.sync = ->
|
||||
$.forceSync = ->
|
||||
|
||||
$.delete = (keys) ->
|
||||
unless keys instanceof Array
|
||||
|
||||
@ -4,4 +4,7 @@ Flash =
|
||||
$.ready Flash.initReady
|
||||
|
||||
initReady: ->
|
||||
$.globalEval 'if (JSON.parse(localStorage["4chan-settings"] || "{}").disableAll) SWFEmbed.init();'
|
||||
if $.hasStorage
|
||||
$.global -> window.SWFEmbed.init() if JSON.parse(localStorage['4chan-settings'] or '{}').disableAll
|
||||
else
|
||||
$.global -> window.SWFEmbed.init()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user