From 66b3fc1c642e2021bee76c481cb04d882990aefd Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 21 Feb 2013 21:41:50 +0100 Subject: [PATCH] Convert imported settings from v2 to v3. Close #702. --- 4chan_x.user.js | 91 +++++++++++++++++++++++++++++++++++++++------ src/config.coffee | 8 ++-- src/features.coffee | 82 +++++++++++++++++++++++++++++++++++----- 3 files changed, 155 insertions(+), 26 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index e6a103130..545e672fe 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -135,7 +135,7 @@ filesize: [''].join('\n'), MD5: [''].join('\n') }, - sauces: ['http://iqdb.org/?url=%turl', 'http://www.google.com/searchbyimage?image_url=%turl', '#http://tineye.com/search?url=%turl', '#http://saucenao.com/search.php?db=999&url=%turl', '#http://3d.iqdb.org/?url=%turl', '#http://regex.info/exif.cgi?imgurl=%url', '# uploaders:', '#http://imgur.com/upload?url=%url;text:Upload to imgur', '#http://omploader.org/upload?url1=%url;text:Upload to omploader', '# "View Same" in archives:', '#//archive.foolz.us/_/search/image/%md5/;text:View same on foolz', '#//archive.foolz.us/%board/search/image/%md5/;text:View same on foolz /%board/', '#//archive.installgentoo.net/%board/image/%md5;text:View same on installgentoo /%board/'].join('\n'), + sauces: ['http://iqdb.org/?url=%turl', 'http://www.google.com/searchbyimage?image_url=%turl', '#http://tineye.com/search?url=%turl', '#http://saucenao.com/search.php?db=999&url=%turl', '#http://3d.iqdb.org/?url=%turl', '#http://regex.info/exif.cgi?imgurl=%url', '# uploaders:', '#http://imgur.com/upload?url=%url;text:Upload to imgur', '#http://omploader.org/upload?url1=%url;text:Upload to omploader', '# "View Same" in archives:', '#//archive.foolz.us/_/search/image/%MD5/;text:View same on foolz', '#//archive.foolz.us/%board/search/image/%MD5/;text:View same on foolz /%board/', '#//archive.installgentoo.net/%board/image/%MD5;text:View same on installgentoo /%board/'].join('\n'), time: '%m/%d/%y(%a)%H:%M:%S', backlink: '>>%id', fileInfo: '%l (%p%s, %r)', @@ -143,7 +143,7 @@ hotkeys: { 'Open empty QR': ['q', 'Open QR without post number inserted.'], 'Open QR': ['Shift+q', 'Open QR with post number inserted.'], - 'Open options': ['Alt+o', 'Open Options.'], + 'Open settings': ['Alt+o', 'Open Settings.'], 'Close': ['Esc', 'Close Settings, Notifications or QR.'], 'Spoiler tags': ['Ctrl+s', 'Insert spoiler tags.'], 'Code tags': ['Alt+c', 'Insert code tags.'], @@ -1128,7 +1128,7 @@ $.event('AddMenuEntry', { type: 'header', el: link, - order: 110 + order: 111 }); link = $.el('a', { className: 'fourchan-settings-link', @@ -1141,7 +1141,7 @@ $.event('AddMenuEntry', { type: 'header', el: link, - order: 111, + order: 110, open: function() { return Conf['Enable 4chan\'s extension']; } @@ -1299,7 +1299,7 @@ a = $.el('a', { className: 'warning', textContent: 'Save me!', - download: "4chan X Beta-" + now + ".json", + download: "4chan X Beta v" + g.VERSION + "-" + now + ".json", href: "data:application/json;base64," + (btoa(unescape(encodeURIComponent(JSON.stringify(data))))), target: '_blank' }); @@ -1341,9 +1341,68 @@ return reader.readAsText(file); }, loadSettings: function(data) { - var key, val, _ref; - if (data.version.split('.')[0] === '2') { - data = Settings.convertSettingsFromV2(data); + var key, val, version, _ref; + version = data.version.split('.'); + if (version[0] === '2') { + data = Settings.convertSettings(data, { + 'Disable 4chan\'s extension': '', + 'Catalog Links': '', + 'Reply Navigation': '', + 'Show Stubs': 'Stubs', + 'Image Auto-Gif': 'Auto-GIF', + 'Expand From Current': '', + 'Unread Favicon': 'Unread Tab Icon', + 'Post in Title': 'Thread Excerpt', + 'Auto Hide QR': '', + 'Open Reply in New Tab': '', + 'Remember QR size': '', + 'Indicate OP quote': 'Mark OP Quotes', + 'Indicate Cross-thread Quotes': 'Mark Cross-thread Quotes', + 'uniqueid': 'uniqueID', + 'mod': 'capcode', + 'country': 'flag', + 'md5': 'MD5', + 'openEmptyQR': 'Open empty QR', + 'openQR': 'Open QR', + 'openOptions': 'Open settings', + 'close': 'Close', + 'spoiler': 'Spoiler tags', + 'code': 'Code tags', + 'submit': 'Submit QR', + 'watch': 'Watch', + 'update': 'Update', + 'unreadCountTo0': '', + 'expandAllImages': 'Expand image', + 'expandImage': 'Expand images', + 'zero': 'Front page', + 'nextPage': 'Next page', + 'previousPage': 'Previous page', + 'nextThread': 'Next thread', + 'previousThread': 'Previous thread', + 'expandThread': 'Expand thread', + 'openThreadTab': 'Open thread', + 'openThread': 'Open thread tab', + 'nextReply': 'Next reply', + 'previousReply': 'Previous reply', + 'hide': 'Hide', + 'Scrolling': 'Auto Scroll', + 'Verbose': '' + }); + data.Conf.sauces = data.Conf.sauces.replace(/\$\d/g, function(c) { + $.log(c); + switch (c) { + case '$1': + return '%turl'; + case '$2': + return '%url'; + case '$3': + return '%MD5'; + case '$4': + return '%board'; + default: + return c; + } + }); } _ref = data.Conf; for (key in _ref) { @@ -1352,7 +1411,15 @@ } return $.set('WatchedThreads', data.WatchedThreads); }, - convertSettingsFromV2: function(data) { + convertSettings: function(data, map) { + var newKey, prevKey; + for (prevKey in map) { + newKey = map[prevKey]; + if (newKey) { + data.Conf[newKey] = data.Conf[prevKey]; + } + delete data.Conf[prevKey]; + } return data; }, filter: function(section) { @@ -1380,7 +1447,7 @@ }, sauce: function(section) { var sauce; - section.innerHTML = "
Sauce is disabled.
\n
Lines starting with a # will be ignored.
\n
You can specify a display text by appending ;text:[text] to the url.
\n\n"; + section.innerHTML = "
Sauce is disabled.
\n
Lines starting with a # will be ignored.
\n
You can specify a display text by appending ;text:[text] to the url.
\n\n"; sauce = $('textarea', section); sauce.value = $.get('sauces', Conf['sauces']); return $.on(sauce, 'change', $.cb.value); @@ -1392,7 +1459,7 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { name = _ref[_i]; input = $("[name=" + name + "]", section); - input.value = $.get('name', Conf[name]); + input.value = $.get(name, Conf[name]); event = input.nodeName === 'SELECT' ? 'change' : 'input'; $.on(input, event, $.cb.value); $.on(input, event, Settings[name]); @@ -4237,7 +4304,7 @@ return "' + post.file.thumbURL + '"; case '%url': return "' + post.file.URL + '"; - case '%md5': + case '%MD5': return "' + encodeURIComponent(post.file.MD5) + '"; case '%board': return "' + post.board + '"; diff --git a/src/config.coffee b/src/config.coffee index b124c0cbe..8b6ec1658 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -120,9 +120,9 @@ Config = '#http://imgur.com/upload?url=%url;text:Upload to imgur' '#http://omploader.org/upload?url1=%url;text:Upload to omploader' '# "View Same" in archives:' - '#//archive.foolz.us/_/search/image/%md5/;text:View same on foolz' - '#//archive.foolz.us/%board/search/image/%md5/;text:View same on foolz /%board/' - '#//archive.installgentoo.net/%board/image/%md5;text:View same on installgentoo /%board/' + '#//archive.foolz.us/_/search/image/%MD5/;text:View same on foolz' + '#//archive.foolz.us/%board/search/image/%MD5/;text:View same on foolz /%board/' + '#//archive.installgentoo.net/%board/image/%MD5;text:View same on installgentoo /%board/' ].join '\n' time: '%m/%d/%y(%a)%H:%M:%S' backlink: '>>%id' @@ -132,7 +132,7 @@ Config = # QR & Options 'Open empty QR': ['q', 'Open QR without post number inserted.'] 'Open QR': ['Shift+q', 'Open QR with post number inserted.'] - 'Open options': ['Alt+o', 'Open Options.'] + 'Open settings': ['Alt+o', 'Open Settings.'] 'Close': ['Esc', 'Close Settings, Notifications or QR.'] 'Spoiler tags': ['Ctrl+s', 'Insert spoiler tags.'] 'Code tags': ['Alt+c', 'Insert code tags.'] diff --git a/src/features.coffee b/src/features.coffee index 6fa5e8488..946cdbaaf 100644 --- a/src/features.coffee +++ b/src/features.coffee @@ -128,7 +128,7 @@ Settings = $.event 'AddMenuEntry', type: 'header' el: link - order: 110 + order: 111 # 4chan settings link link = $.el 'a', @@ -139,7 +139,7 @@ Settings = $.event 'AddMenuEntry', type: 'header' el: link - order: 111 + order: 110 open: -> Conf['Enable 4chan\'s extension'] unless $.get 'previousversion' @@ -274,7 +274,7 @@ Settings = a = $.el 'a', className: 'warning' textContent: 'Save me!' - download: "<%= meta.name %>-#{now}.json" + download: "<%= meta.name %> v#{g.VERSION}-#{now}.json" href: "data:application/json;base64,#{btoa unescape encodeURIComponent JSON.stringify data}" target: '_blank' if $.engine isnt 'gecko' @@ -304,13 +304,75 @@ Settings = $.log err.stack reader.readAsText file loadSettings: (data) -> - if data.version.split('.')[0] is '2' - data = Settings.convertSettingsFromV2 data + version = data.version.split '.' + if version[0] is '2' + data = Settings.convertSettings data, + # General confs + 'Disable 4chan\'s extension': '' + 'Catalog Links': '' + 'Reply Navigation': '' + 'Show Stubs': 'Stubs' + 'Image Auto-Gif': 'Auto-GIF' + 'Expand From Current': '' + 'Unread Favicon': 'Unread Tab Icon' + 'Post in Title': 'Thread Excerpt' + 'Auto Hide QR': '' + 'Open Reply in New Tab': '' + 'Remember QR size': '' + 'Indicate OP quote': 'Mark OP Quotes' + 'Indicate Cross-thread Quotes': 'Mark Cross-thread Quotes' + # filter + 'uniqueid': 'uniqueID' + 'mod': 'capcode' + 'country': 'flag' + 'md5': 'MD5' + # keybinds + 'openEmptyQR': 'Open empty QR' + 'openQR': 'Open QR' + 'openOptions': 'Open settings' + 'close': 'Close' + 'spoiler': 'Spoiler tags' + 'code': 'Code tags' + 'submit': 'Submit QR' + 'watch': 'Watch' + 'update': 'Update' + 'unreadCountTo0': '' + 'expandAllImages': 'Expand image' + 'expandImage': 'Expand images' + 'zero': 'Front page' + 'nextPage': 'Next page' + 'previousPage': 'Previous page' + 'nextThread': 'Next thread' + 'previousThread': 'Previous thread' + 'expandThread': 'Expand thread' + 'openThreadTab': 'Open thread' + 'openThread': 'Open thread tab' + 'nextReply': 'Next reply' + 'previousReply': 'Previous reply' + 'hide': 'Hide' + # updater + 'Scrolling': 'Auto Scroll' + 'Verbose': '' + data.Conf.sauces = data.Conf.sauces.replace /\$\d/g, (c) -> + $.log c + switch c + when '$1' + '%turl' + when '$2' + '%url' + when '$3' + '%MD5' + when '$4' + '%board' + else + c for key, val of data.Conf $.set key, val $.set 'WatchedThreads', data.WatchedThreads - convertSettingsFromV2: (data) -> - # XXX TODO + convertSettings: (data, map) -> + for prevKey, newKey of map + data.Conf[newKey] = data.Conf[prevKey] if newKey + delete data.Conf[prevKey] data filter: (section) -> @@ -386,7 +448,7 @@ Settings = @@ -433,7 +495,7 @@ Settings = """ for name in ['time', 'backlink', 'fileInfo', 'favicon'] input = $ "[name=#{name}]", section - input.value = $.get 'name', Conf[name] + input.value = $.get name, Conf[name] event = if input.nodeName is 'SELECT' 'change' else @@ -2808,7 +2870,7 @@ Sauce = "' + post.file.thumbURL + '" when '%url' "' + post.file.URL + '" - when '%md5' + when '%MD5' "' + encodeURIComponent(post.file.MD5) + '" when '%board' "' + post.board + '"