From 95a74a55aa277e77e1c8090777e18e6f506ee6ce Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 21 Feb 2013 19:11:08 +0100 Subject: [PATCH 1/3] Add import/export settings buttons in the Settings. (v2 edition) #702 --- 4chan_x.user.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++- changelog | 2 ++ script.coffee | 56 ++++++++++++++++++++++++++++++++++++- 3 files changed, 129 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 30b04f018..7ca3b976c 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -2737,7 +2737,14 @@
\
\ \ -
\ +
\ +
\ + \ + \ + \ +
\ +

\ +
\ \
\
Sauce is disabled.
\ @@ -2819,6 +2826,9 @@
\
' }); + $.on($('#main_tab + div .export', dialog), 'click', Options["export"]); + $.on($('#main_tab + div .import', dialog), 'click', Options["import"]); + $.on($('#main_tab + div input', dialog), 'change', Options.onImport); _ref = Config.main; for (key in _ref) { obj = _ref[key]; @@ -2994,6 +3004,67 @@ Favicon["switch"](); Unread.update(true); return this.nextElementSibling.innerHTML = " "; + }, + "export": function() { + var a, data, now, output; + now = Date.now(); + data = { + version: Main.version, + date: now, + Conf: Conf, + WatchedThreads: $.get('watched', {}) + }; + a = $.el('a', { + className: 'warning', + textContent: 'Save me!', + download: "4chan X v" + Main.version + "-" + now + ".json", + href: "data:application/json;base64," + (btoa(unescape(encodeURIComponent(JSON.stringify(data))))), + target: '_blank' + }); + if ($.engine !== 'gecko') { + a.click(); + return; + } + output = this.parentNode.nextElementSibling; + output.innerHTML = null; + return $.add(output, a); + }, + "import": function() { + return this.nextElementSibling.click(); + }, + onImport: function() { + var file, output, reader; + if (!(file = this.files[0])) { + return; + } + output = this.parentNode.nextElementSibling; + if (!confirm('Your current settings will be entirely overwritten, are you sure?')) { + output.textContent = 'Import aborted.'; + return; + } + reader = new FileReader(); + reader.onload = function(e) { + var data; + try { + data = JSON.parse(decodeURIComponent(escape(e.target.result))); + Options.loadSettings(data); + if (confirm('Import successful. Refresh now?')) { + return window.location.reload(); + } + } catch (err) { + return output.textContent = 'Import failed due to an error.'; + } + }; + return reader.readAsText(file); + }, + loadSettings: function(data) { + var key, val, _ref; + _ref = data.Conf; + for (key in _ref) { + val = _ref[key]; + $.set(key, val); + } + return $.set('watched', data.WatchedThreads); } }; diff --git a/changelog b/changelog index 77bfc088d..1dc2b03a9 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ master +- Mayhem + Add Import/Export settings. 2.38.1 - Mayhem diff --git a/script.coffee b/script.coffee index 55a3debe7..2fc2f4381 100644 --- a/script.coffee +++ b/script.coffee @@ -2185,7 +2185,14 @@ Options =
-
+
+
+ + + +
+

+
Sauce is disabled.
@@ -2267,6 +2274,10 @@ Options =
' + $.on $('#main_tab + div .export', dialog), 'click', Options.export + $.on $('#main_tab + div .import', dialog), 'click', Options.import + $.on $('#main_tab + div input', dialog), 'change', Options.onImport + #main for key, obj of Config.main ul = $.el 'ul', @@ -2423,6 +2434,49 @@ Options = Unread.update true @nextElementSibling.innerHTML = " " + export: -> + now = Date.now() + data = + version: Main.version + date: now + Conf: Conf + WatchedThreads: $.get('watched', {}) + a = $.el 'a', + className: 'warning' + textContent: 'Save me!' + download: "4chan X v#{Main.version}-#{now}.json" + href: "data:application/json;base64,#{btoa unescape encodeURIComponent JSON.stringify data}" + target: '_blank' + if $.engine isnt 'gecko' + a.click() + return + # XXX Firefox won't let us download automatically. + output = @parentNode.nextElementSibling + output.innerHTML = null + $.add output, a + import: -> + @nextElementSibling.click() + onImport: -> + return unless file = @files[0] + output = @parentNode.nextElementSibling + unless confirm 'Your current settings will be entirely overwritten, are you sure?' + output.textContent = 'Import aborted.' + return + reader = new FileReader() + reader.onload = (e) -> + try + data = JSON.parse decodeURIComponent escape e.target.result + Options.loadSettings data + if confirm 'Import successful. Refresh now?' + window.location.reload() + catch err + output.textContent = 'Import failed due to an error.' + reader.readAsText file + loadSettings: (data) -> + for key, val of data.Conf + $.set key, val + $.set 'watched', data.WatchedThreads + Updater = init: -> html = '
' From 3900f97df6659e7ba5a698f7048825e38bfc7f38 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Mon, 25 Feb 2013 15:41:24 +0100 Subject: [PATCH 2/3] Upgrade CoffeeScript to 1.5.0. --- 4chan_x.user.js | 14 +++++++------- script.coffee | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 7ca3b976c..aae451399 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -3119,8 +3119,8 @@ return $.on(d, 'visibilitychange', this.cb.visibility); }, /* - http://freesound.org/people/pierrecartoons1979/sounds/90112/ - cc-by-nc-3.0 + http://freesound.org/people/pierrecartoons1979/sounds/90112/ + cc-by-nc-3.0 */ audio: $.el('audio', { @@ -3193,9 +3193,9 @@ case 0: case 304: /* - Status Code 304: Not modified - By sending the `If-Modified-Since` header we get a proper status code, and no response. - This saves bandwidth for both the user and the servers and avoid unnecessary computation. + Status Code 304: Not modified + By sending the `If-Modified-Since` header we get a proper status code, and no response. + This saves bandwidth for both the user and the servers and avoid unnecessary computation. */ Updater.unsuccessfulFetchCount++; @@ -4039,8 +4039,8 @@ }, post: function(o, isArchived) { /* - This function contains code from 4chan-JS (https://github.com/4chan/4chan-JS). - @license: https://github.com/4chan/4chan-JS/blob/master/LICENSE + This function contains code from 4chan-JS (https://github.com/4chan/4chan-JS). + @license: https://github.com/4chan/4chan-JS/blob/master/LICENSE */ var a, board, capcode, capcodeClass, capcodeStart, closed, comment, container, date, dateUTC, email, emailEnd, emailStart, ext, file, fileDims, fileHTML, fileInfo, fileSize, fileThumb, filename, flag, flagCode, flagName, href, imgSrc, isClosed, isOP, isSticky, name, postID, quote, shortFilename, spoilerRange, staticPath, sticky, subject, threadID, tripcode, uniqueID, userID, _i, _len, _ref; diff --git a/script.coffee b/script.coffee index 2fc2f4381..4505a12dd 100644 --- a/script.coffee +++ b/script.coffee @@ -1911,7 +1911,7 @@ QR = if g.BOARD is 'f' $('select[name=filetag]').cloneNode true else - $.el 'select' + $.el 'select', innerHTML: threads title: 'Create a new thread / Reply to a thread' $.prepend $('.move > span', QR.el), QR.threadSelector @@ -2165,7 +2165,7 @@ Options = Options.dialog() dialog: -> - dialog = $.el 'div' + dialog = $.el 'div', id: 'options' className: 'reply dialog' innerHTML: '
@@ -4181,7 +4181,7 @@ ImageHover = # Don't stop other elements from dragging return if UI.el - el = UI.el = $.el 'img' + el = UI.el = $.el 'img', id: 'ihover' src: @parentNode.href $.add d.body, el From f6206da98ad086d0eefc36bffa269ab544a9b5f1 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 1 Mar 2013 01:35:14 +0100 Subject: [PATCH 3/3] Remove /sp/ image archive redirection. --- 4chan_x.user.js | 1 - script.coffee | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index aae451399..2b8561615 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -4920,7 +4920,6 @@ case 'jp': case 'm': case 'q': - case 'sp': case 'tg': case 'vg': case 'wsg': diff --git a/script.coffee b/script.coffee index 4505a12dd..00fbb21c8 100644 --- a/script.coffee +++ b/script.coffee @@ -4080,7 +4080,7 @@ Redirect = image: (board, filename) -> # Do not use g.BOARD, the image url can originate from a cross-quote. switch board - when 'a', 'jp', 'm', 'q', 'sp', 'tg', 'vg', 'wsg' + when 'a', 'jp', 'm', 'q', 'tg', 'vg', 'wsg' "//archive.foolz.us/#{board}/full_image/#{filename}" when 'u' "//nsfw.foolz.us/#{board}/full_image/#{filename}"