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