From 614e7f0d09c744e8379a2dc7b8e0d87a697175b6 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 9 Apr 2014 15:44:28 +0000 Subject: [PATCH] store on-load script on server (ui.onload), fixes #1850 --- pandora/config.0xdb.jsonc | 1 + pandora/config.indiancinema.jsonc | 1 + pandora/config.padma.jsonc | 1 + pandora/config.pandora.jsonc | 1 + static/js/onloadDialog.js | 12 ++++-------- static/js/pandora.js | 6 +----- static/js/utils.js | 11 +++++++++++ 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/pandora/config.0xdb.jsonc b/pandora/config.0xdb.jsonc index 859061026..072ce8aca 100644 --- a/pandora/config.0xdb.jsonc +++ b/pandora/config.0xdb.jsonc @@ -822,6 +822,7 @@ "locale": "en", "mapFind": "", "mapSelection": "", + "onload": "", "page": "", "part": { "api": "", diff --git a/pandora/config.indiancinema.jsonc b/pandora/config.indiancinema.jsonc index 0a1624d92..a2b64e061 100644 --- a/pandora/config.indiancinema.jsonc +++ b/pandora/config.indiancinema.jsonc @@ -835,6 +835,7 @@ "locale": "en", "mapFind": "", "mapSelection": "", + "onload": "", "page": "", "part": { "api": "", diff --git a/pandora/config.padma.jsonc b/pandora/config.padma.jsonc index 4d0076ec9..28a2dc802 100644 --- a/pandora/config.padma.jsonc +++ b/pandora/config.padma.jsonc @@ -708,6 +708,7 @@ "locale": "en", "mapFind": "", "mapSelection": "", + "onload": "", "page": "", "part": { "api": "", diff --git a/pandora/config.pandora.jsonc b/pandora/config.pandora.jsonc index 6f5aba767..1b54aa335 100644 --- a/pandora/config.pandora.jsonc +++ b/pandora/config.pandora.jsonc @@ -627,6 +627,7 @@ "locale": "en", "mapFind": "", "mapSelection": "", + "onload": "", "page": "", "part": { "api": "", diff --git a/static/js/onloadDialog.js b/static/js/onloadDialog.js index 42014eb85..b94840b97 100644 --- a/static/js/onloadDialog.js +++ b/static/js/onloadDialog.js @@ -11,9 +11,9 @@ pandora.ui.onloadDialog = function() { id: 'onload', placeholder: Ox._('/*\nAny JavaScript you paste here will run on load.\n' + 'If you ever need to manually change or remove it, ' - + 'you can do so by setting localStorage["pandora.onload"] in the console.\n*/'), + + 'you can do so by pandora.UI.set({onload: ""}) in the console.\n*/'), type: 'textarea', - value: localStorage['pandora.onload'] || '', + value: pandora.user.ui.onload || '', width: dialogWidth - 32 }) .css({margin: '16px'}), @@ -62,18 +62,14 @@ pandora.ui.onloadDialog = function() { } function clear() { - delete localStorage['pandora.onload']; + pandora.UI.set({onload: ''}); $input.options({value: ''}); } that.superClose = that.close; that.close = function() { var value = $input.value(); - if (value) { - localStorage['pandora.onload'] = value; - } else { - delete localStorage['pandora.onload']; - } + pandora.UI.set({onload: value || ''}); that.superClose(); }; diff --git a/static/js/pandora.js b/static/js/pandora.js index 79d490721..b26139143 100644 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -426,11 +426,7 @@ appPanel }); Ox.Fullscreen.bind('exit', pandora.UI.set); pandora.site.sectionButtonsWidth = pandora.$ui.sectionButtons.width() + 8; - if (getLocalStorage('pandora.onload')) { - try { - eval(localStorage['pandora.onload']) - } catch(e) {} - } + pandora.loadUserScript(); } function loadBrowserMessage() { diff --git a/static/js/utils.js b/static/js/utils.js index 345d2746f..218c8aeb0 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1906,6 +1906,16 @@ pandora.isVideoView = function(view, item) { ).indexOf(view) > -1; }; +pandora.loadUserScript = function() { + if (pandora.user.ui.onload) { + try { + eval(pandora.user.ui.onload); + } catch(e) { + Ox.print('user onload script error', e); + } + } +}; + pandora.logEvent = function(data, event, element) { var element = this, handlers = self.eventHandlers ? self.eventHandlers[event] : []; @@ -1959,6 +1969,7 @@ pandora.signin = function(data) { pandora.URL.update(); Ox.Theme(pandora.user.ui.theme); pandora.$ui.appPanel.reload(); + pandora.loadUserScript(); }; pandora.signout = function(data) {