diff --git a/4chan_x.user.js b/4chan_x.user.js index 7f8b82aed..69ee1ea26 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1572,6 +1572,9 @@ text = ">>" + id + "\n"; sel = window.getSelection(); if ((s = sel.toString()) && id === ((_ref = $.x('ancestor-or-self::blockquote', sel.anchorNode)) != null ? _ref.id.match(/\d+$/)[0] : void 0)) { + if ($.engine === 'presto') { + s = d.getSelection(); + } s = s.replace(/\n/g, '\n>'); text += ">" + s + "\n"; } @@ -1580,6 +1583,9 @@ ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd); ta.focus(); range = caretPos + text.length; + if ($.engine === 'presto') { + range += text.match(/\n/g).length; + } ta.setSelectionRange(range, range); e = d.createEvent('Event'); e.initEvent('input', true, false); @@ -1640,7 +1646,27 @@ return QR.resetFileInput(); }, resetFileInput: function() { - return $('[type=file]', QR.el).value = null; + var clone, input; + input = $('[type=file]', QR.el); + input.value = null; + if ($.engine !== 'presto') { + return; + } + clone = $.el('input', { + type: 'file', + accept: input.accept, + max: input.max, + multiple: input.multiple, + size: input.size, + title: input.title + }); + $.on(clone, 'change', QR.fileInput); + $.on(clone, 'click', function(e) { + if (e.shiftKey) { + return QR.selected.rmFile() || e.preventDefault(); + } + }); + return $.replace(input, clone); }, replies: [], reply: (function() { @@ -4484,7 +4510,7 @@ } }, preParse: function(node) { - var el, fileInfo, img, parentClass, post; + var el, img, parentClass, post; parentClass = node.parentNode.className; el = $('.post', node); post = { @@ -4502,12 +4528,9 @@ fileInfo: false, img: false }; - if (fileInfo = $('.fileInfo', el)) { - img = fileInfo.nextElementSibling.firstElementChild; - if (img.alt !== 'File deleted.') { - post.fileInfo = fileInfo; - post.img = img; - } + if (img = $('img[data-md5]', el)) { + post.fileInfo = img.parentNode.previousElementSibling; + post.img = img; } Main.prettify(post.blockquote); return post; diff --git a/changelog b/changelog index ffd74a58e..80081b804 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,7 @@ master +- Mayhem + Opera fixes. + /f/ fixes. 2.32.1 - Mayhem diff --git a/script.coffee b/script.coffee index e6fa98a9f..0434c96fe 100644 --- a/script.coffee +++ b/script.coffee @@ -1159,6 +1159,8 @@ QR = sel = window.getSelection() if (s = sel.toString()) and id is $.x('ancestor-or-self::blockquote', sel.anchorNode)?.id.match(/\d+$/)[0] + # XXX Opera needs d.getSelection() to retain linebreaks from the selected text + s = d.getSelection() if $.engine is 'presto' s = s.replace /\n/g, '\n>' text += ">#{s}\n" @@ -1169,6 +1171,8 @@ QR = ta.focus() # Move the caret to the end of the new quote. range = caretPos + text.length + # XXX Opera counts newlines as double + range += text.match(/\n/g).length if $.engine is 'presto' ta.setSelectionRange range, range # Fire the 'input' event @@ -1221,7 +1225,20 @@ QR = $.addClass QR.el, 'dump' QR.resetFileInput() # reset input resetFileInput: -> - $('[type=file]', QR.el).value = null + input = $ '[type=file]', QR.el + input.value = null + return unless $.engine is 'presto' + # XXX Opera needs extra care to reset its file input's value + clone = $.el 'input', + type: 'file' + accept: input.accept + max: input.max + multiple: input.multiple + size: input.size + title: input.title + $.on clone, 'change', QR.fileInput + $.on clone, 'click', (e) -> if e.shiftKey then QR.selected.rmFile() or e.preventDefault() + $.replace input, clone replies: [] reply: class @@ -2148,7 +2165,7 @@ Sauce = @links = [] for link in Conf['sauces'].split '\n' continue if link[0] is '#' - # .trim() is there to fix Opera reading two different line breaks. + # XXX .trim() is there to fix Opera reading two different line breaks. @links.push @createSauceLink link.trim() return unless @links.length Main.callbacks.push @node @@ -3491,11 +3508,11 @@ Main = backlinks: el.getElementsByClassName 'backlink' fileInfo: false img: false - if fileInfo = $ '.fileInfo', el - img = fileInfo.nextElementSibling.firstElementChild - if img.alt isnt 'File deleted.' - post.fileInfo = fileInfo - post.img = img + if img = $ 'img[data-md5]', el + # Make sure to not add deleted images, + # those do not have a data-md5 attribute. + post.fileInfo = img.parentNode.previousElementSibling + post.img = img Main.prettify post.blockquote post node: (nodes, notify) ->