From f58c3096ac93f6ce604c144e795ee95e23e7237b Mon Sep 17 00:00:00 2001 From: anekos Date: Fri, 15 Jul 2011 09:53:51 +0900 Subject: submit/cancel を修正。全般的に使えるようにしたかも。 --- google-plus-commando.js | 72 ++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/google-plus-commando.js b/google-plus-commando.js index 04e0276..4a438a1 100644 --- a/google-plus-commando.js +++ b/google-plus-commando.js @@ -35,7 +35,7 @@ THE POSSIBILITY OF SUCH DAMAGE. // INFO {{{ let INFO = <> - 1) + throw 'Two and more editors were found.'; + + return editors[0].parentNode.querySelector(String(<>[role="button"][id$=".{names[type]}"]));; + } + + function get2 () { + const indexes = {submit: 0, cancel: 1}; + + let editors = A(doc.querySelectorAll('.n')).filter(function(it) it.querySelector('iframe').contentWindow === win); + if (editors.length === 0) + return; + if (editors.length > 1) + throw 'Two and more editors were found.'; + + let result = editors[0].querySelectorAll('td > [role="button"]')[indexes[type]]; + if (result) + return result; + + if (type === 'cancel') + return editors[0].querySelector('.om[id$=".c"]'); + } + + let doc = content.document; + let win = document.commandDispatcher.focusedWindow; + + return get1() || get2(); + } }; function MakeElement (constructor, root) { @@ -204,20 +232,12 @@ let INFO = comment: function() { let entry = Elements.currentEntry; click(entry.comment); - State.form = { - cancel: function () click(entry.cancel), - submit: function () click(entry.submit) - }; }, plusone: function() click(Elements.currentEntry.plusone), share: function() click(Elements.currentEntry.share), post: function() { buffer.scrollTop(); click(Elements.post.editor); - State.form = { - cancel: function () click(Elements.post.cancel), - submit: function () click(Elements.post.submit) - }; }, yank: function () { let e = Elements.currentEntry.permlink; @@ -238,10 +258,9 @@ let INFO = click(Elements.doc.body); }, submit: function () { - if (liberator.focus || !State.form) + if (liberator.focus) return; - State.form.submit(); - State.form = null; + click(Elements.getFocusedEditorButton('submit')); }, unfold: function () { click(Elements.currentEntry.unfold); @@ -290,14 +309,13 @@ let INFO = [''], 'Escape from input area', function () { - if (!liberator.focus && State.form) { - State.form.cancel(); - State.form = null; + if (liberator.focus) { + let esc = mappings.getDefault(modes.NORMAL, ''); + esc.action.apply(esc, arguments); + } else { + click(Elements.getFocusedEditorButton('cancel')); modes.reset(); - return; } - let esc = mappings.getDefault(modes.NORMAL, ''); - esc.action.apply(esc, arguments); }, { matchingUrls: MatchingUrls -- cgit v1.2.3