Commit 6aea1b7fdb60e1780423d59193a6c90bb5e517f0
added auto-clearing channel and comment fields
dust committed on 4/5/2016, 6:23:32 AMParent: a7de32004c62ccfee0c58ceabf82fa58c35d2158
Files changed
chromium/capsule.html | changed |
chromium/capsule.js | changed |
os/parser | changed |
package.json | changed |
chromium/capsule.html | ||
---|---|---|
@@ -65,11 +65,20 @@ | ||
65 | 65 | border-width: thick; |
66 | 66 | border-color: white; |
67 | 67 | border-radius: 2px; |
68 | 68 | min-height: 4em; |
69 | - overflow-y: visible; | |
69 | + overflow-y: scroll; | |
70 | 70 | } |
71 | 71 | |
72 | + #capsule-channel-field { | |
73 | + background-color: darkslategrey; | |
74 | + border-width: thick; | |
75 | + border-color: white; | |
76 | + border-radius: 2px; | |
77 | + height: 1.5em; | |
78 | + max-width: 100%; | |
79 | + } | |
80 | + | |
72 | 81 | #capsule-controls { |
73 | 82 | display: block; |
74 | 83 | text-align: center; |
75 | 84 | padding: 0.5rem; |
@@ -99,11 +108,14 @@ | ||
99 | 108 | <div id="capsule-selected-content"> |
100 | 109 | no selected HTML could be parsed :( |
101 | 110 | </div> |
102 | 111 | <hr id="capsule-hrule" /> |
103 | - <div id="capsule-comment-field"> | |
112 | + <div id="capsule-comment-field" contenteditable> | |
104 | 113 | Comments go here |
105 | 114 | </div> |
115 | + <div id="capsule-channel-field" contenteditable> | |
116 | + Channel | |
117 | + </div> | |
106 | 118 | <div id="capsule-controls"> |
107 | 119 | <button id="capsule-send">Send</button> |
108 | 120 | </div> |
109 | 121 | </div> |
chromium/capsule.js | ||
---|---|---|
@@ -32,17 +32,29 @@ | ||
32 | 32 | // anyway we're just going to base64 it |
33 | 33 | return btoa(encodeURIComponent(htmlString)) |
34 | 34 | } |
35 | 35 | |
36 | -var sendHTML = function(htmlString) { | |
36 | +var sendHTML = function(htmlString, comment, channel) { | |
37 | 37 | chrome.tabs.getSelected(function(selectedTab) { |
38 | - let serialisedURI = encodeURI('ssb-capsule://?body=' | |
39 | - .concat(encodeHTMLString(htmlString)) | |
40 | - .concat('&src=').concat(selectedTab.url) | |
41 | - .concat('&title=').concat(selectedTab.title)) | |
38 | + let serialisedURI = 'ssb-capsule://?body=' | |
39 | + .concat(encodeHTMLString(htmlString)) | |
40 | + .concat('&title=').concat(selectedTab.title) | |
41 | + | |
42 | + if (typeof selectedTab.url === 'string') { | |
43 | + serialisedURI = serialisedURI.concat('&src=').concat(selectedTab.url) | |
44 | + } | |
45 | + | |
46 | + if (typeof comment === 'string') { | |
47 | + serialisedURI = serialisedURI.concat('&comment=').concat(comment) | |
48 | + } | |
49 | + | |
50 | + if (typeof channel === 'string') { | |
51 | + serialisedURI = serialisedURI.concat('&channel=').concat(channel) | |
52 | + } | |
53 | + | |
42 | 54 | |
43 | 55 | const serialiserTabProps = { |
44 | - url: serialisedURI, | |
56 | + url: encodeURI(serialisedURI), | |
45 | 57 | active: true |
46 | 58 | } |
47 | 59 | |
48 | 60 | console.log('launching a capsule...') |
@@ -52,14 +64,36 @@ | ||
52 | 64 | }) |
53 | 65 | }) |
54 | 66 | } |
55 | 67 | |
68 | +var clearField = function() { | |
69 | + return function listener(event) { | |
70 | + event.target.innerText = '' | |
71 | + event.target.removeEventListener(event.type, listener) | |
72 | + } | |
73 | +} | |
74 | + | |
56 | 75 | var hookToElements = function() { |
57 | 76 | const sendButton = document.getElementById('capsule-send') |
77 | + const commentBox = document.getElementById('capsule-comment-field') | |
78 | + const channelField = document.getElementById('capsule-channel-field') | |
79 | + | |
80 | + channelField.addEventListener('click', clearField()) | |
81 | + commentBox.addEventListener('click', clearField()) | |
82 | + | |
58 | 83 | sendButton.addEventListener('click', function() { |
59 | 84 | const selectedBox = document.getElementById('capsule-selected-content') |
85 | + const commentBox = document.getElementById('capsule-comment-field') | |
86 | + const channelField = document.getElementById('capsule-channel-field') | |
60 | 87 | |
61 | - sendHTML(selectedBox.innerHTML) | |
88 | + // optional args: comment, channel choice | |
89 | + const comment = (commentBox.innerText.length > 0 && | |
90 | + commentBox.innerText !== 'Comment here') ? | |
91 | + commentBox.innerText : null | |
92 | + const channel = channelField.innerText.length > 0 ? | |
93 | + channelField.innerText : null | |
94 | + | |
95 | + sendHTML(selectedBox.innerHTML, comment, channel) | |
62 | 96 | }) |
63 | 97 | } |
64 | 98 | |
65 | 99 | document.addEventListener('DOMContentLoaded', getSelectedHTML) |
os/parser | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 | #!/usr/bin/env node |
2 | 2 | |
3 | 3 | var fs = require('fs') |
4 | -fs.writeFileSync('capsule.log', 'node parser was called but did not catch', 'utf8') | |
4 | +fs.writeFileSync('capsule.log', 'node parser was called but nothing happened', 'utf8') | |
5 | 5 | |
6 | 6 | var url = require('url') |
7 | 7 | |
8 | 8 | // parse URL, split up query params |
@@ -15,29 +15,38 @@ | ||
15 | 15 | for (var i = 0, len = payloadArray.length ; i<len ; i+=2) { |
16 | 16 | payload[payloadArray[i]] = (payloadArray[i+1]) |
17 | 17 | } |
18 | 18 | |
19 | -// decode body from base64 | |
19 | +// decode payload from base64 | |
20 | 20 | payload.body = unescape(new Buffer(payload.body, 'base64').toString()) |
21 | +if (typeof payload.comment === 'string') { | |
22 | + payload.body = payload.body.concat('\n<hr /><br />').concat(unescape(payload.comment)) | |
23 | +} | |
21 | 24 | payload.title = unescape(payload.title) |
25 | +payload.channel = unescape(payload.channel) | |
22 | 26 | |
23 | 27 | // ssbify the dang thing, finally |
24 | 28 | var ssbifyString = require('ssbify-string') |
25 | 29 | var ssbClient = require('ssb-client') |
26 | 30 | |
27 | 31 | ssbClient(function (err, sbot) { |
28 | 32 | if (err) fs.writeFileSync('capsule.log', err, 'utf8') |
29 | - | |
33 | + | |
34 | + | |
30 | 35 | ssbifyString( |
31 | 36 | sbot, payload.body, |
32 | 37 | { ignoreBrokenLinks: true, url: payload.src, title: payload.title }, |
33 | 38 | function(err, res) { |
34 | 39 | if (err) fs.writeFileSync('capsule.log', err, 'utf8') |
40 | + else fs.writeFileSync('capsule.log', res, 'utf8') | |
35 | 41 | |
42 | + | |
43 | + // TODO preflight check to ensure a gross post is not pushed instead | |
44 | + | |
36 | 45 | // publish a message |
37 | - sbot.publish({ type: 'post', text: res, channel: 'test' }, | |
46 | + sbot.publish({ type: 'post', text: res, channel: payload.channel || '' }, | |
38 | 47 | function (err, msg) { |
39 | 48 | if (err) fs.writeFileSync('capsule.log', err, 'utf8') |
40 | 49 | }) |
41 | - | |
50 | + | |
42 | 51 | }) |
43 | 52 | }) |
Built with git-ssb-web