From 4ec32cf1b115f49cf7c25fcc666fca321c7ebff6 Mon Sep 17 00:00:00 2001 From: anekos Date: Sat, 16 Jul 2011 07:59:15 +0900 Subject: 投稿入力時にヘルプを出すように --- google-plus-commando.js | 125 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 105 insertions(+), 20 deletions(-) diff --git a/google-plus-commando.js b/google-plus-commando.js index 1e288f4..4ed7885 100644 --- a/google-plus-commando.js +++ b/google-plus-commando.js @@ -35,7 +35,7 @@ THE POSSIBILITY OF SUCH DAMAGE. // INFO {{{ let INFO = <> - [role="button"][id$=".{name}"])); + const names = {submit: 'post', cancel: 'cancel'}; let editors = A(doc.querySelectorAll('div[id$=".editor"]')).filter(hasIFrame); @@ -121,24 +122,39 @@ let INFO = if (editors.length > 1) throw 'Two and more editors were found.'; - return editors[0].parentNode.querySelector(String(<>[role="button"][id$=".{names[type]}"]));; + return { + editor: #1=(editors[0]), + button: { + submit: button(#1#, 'post'), + cancel: button(#1#, 'cancel') + } + }; } function get2 () { + function button (editor, index) { + let result = editor.querySelectorAll('td > [role="button"]')[index]; + if (result) + return result; + if (index === 1) + return editor.querySelector('.om[id$=".c"]'); + } + const indexes = {submit: 0, cancel: 1}; - let editors = A(doc.querySelectorAll('.n')).filter(hasIFrame); + let editors = A(doc.querySelectorAll('.n')).filter(hasIFrame); 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"]'); + return { + editor: #1=(editors[0]), + button: { + submit: button(#1#, 0), + cancel: button(#1#, 1) + } + }; } let doc = content.document; @@ -211,6 +227,73 @@ let INFO = // }}} + // {{{ + + const PostHelp = { + PanelID: 'google-plus-commando-help-panel', + + get panel () Elements.doc.querySelector('#' + PostHelp.PanelID), + + show: function () { + function move (panel) { + let contentHeight = document.getElementById('content').boxObject.height; + let rect = Elements.focusedEditor.editor.getClientRects()[0]; + if (rect.top < contentHeight) { + panel.style.top = ''; + panel.style.bottom = '10px'; + } else { + panel.style.top = '10px'; + panel.style.bottom = ''; + } + } + + let doc = Elements.doc; + let parent = doc.body; + + let exists = PostHelp.panel; + if (exists) { + move(exists); + exists.style.display = 'block'; + return; + } + + let panel = doc.createElement('div'); + panel.setAttribute('id', PostHelp.PanelID); + let (ps = panel.style) { + ps.position = 'fixed'; + ps.left = '10px'; + ps.zIndex = 1000; + ps.backgroundColor = 'white'; + ps.border = 'solid 1px grey'; + } + panel.innerHTML = <> + + + + + + + + + +
入力 効果 解説
*TEXT* TEXT
_TEXT TEXT
-TEXT- TEXT
*-TEXT-* TEXT 打消は内側に
-ねこ- 日本語はダメ
-ね こ- ね こ 英数字や半角スペースを入れたらOK
-Aねこす- Aあねこす 英数字を前後に入れても良い
+ ; + + move(panel); + parent.appendChild(panel); + + return; + }, + + hide: function () { + let exists = PostHelp.panel; + if (exists) + exists.style.display = 'none'; + } + }; + + // }}} + // Commands {{{ const Commands = { @@ -237,12 +320,13 @@ let INFO = comment: function() { let entry = Elements.currentEntry; click(entry.comment); + PostHelp.show(); }, plusone: function() click(Elements.currentEntry.plusone), share: function() click(Elements.currentEntry.share), post: function() { buffer.scrollTop(); - click(Elements.post.editor); + click(Elements.post.open); }, yank: function () { let e = Elements.currentEntry.permlink; @@ -265,7 +349,7 @@ let INFO = submit: function () { if (liberator.focus) return; - click(Elements.getFocusedEditorButton('submit')); + click(Elements.focusedEditor.button.submit); }, unfold: function () { click(Elements.currentEntry.unfold); @@ -318,8 +402,9 @@ let INFO = let esc = mappings.getDefault(modes.NORMAL, ''); esc.action.apply(esc, arguments); } else { - click(Elements.getFocusedEditorButton('cancel')); + click(Elements.focusedEditor.button.cancel); modes.reset(); + PostHelp.hide(); } }, { -- cgit v1.2.3