git ssb

3+

dust / capsule



Commit 6aea1b7fdb60e1780423d59193a6c90bb5e517f0

added auto-clearing channel and comment fields

dust committed on 4/5/2016, 6:23:32 AM
Parent: a7de32004c62ccfee0c58ceabf82fa58c35d2158

Files changed

chromium/capsule.htmlchanged
chromium/capsule.jschanged
os/parserchanged
package.jsonchanged
chromium/capsule.htmlView
@@ -65,11 +65,20 @@
6565 border-width: thick;
6666 border-color: white;
6767 border-radius: 2px;
6868 min-height: 4em;
69- overflow-y: visible;
69+ overflow-y: scroll;
7070 }
7171
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+
7281 #capsule-controls {
7382 display: block;
7483 text-align: center;
7584 padding: 0.5rem;
@@ -99,11 +108,14 @@
99108 <div id="capsule-selected-content">
100109 no selected HTML could be parsed :(
101110 </div>
102111 <hr id="capsule-hrule" />
103- <div id="capsule-comment-field">
112+ <div id="capsule-comment-field" contenteditable>
104113 Comments go here
105114 </div>
115+ <div id="capsule-channel-field" contenteditable>
116+ Channel
117+ </div>
106118 <div id="capsule-controls">
107119 <button id="capsule-send">Send</button>
108120 </div>
109121 </div>
chromium/capsule.jsView
@@ -32,17 +32,29 @@
3232 // anyway we're just going to base64 it
3333 return btoa(encodeURIComponent(htmlString))
3434 }
3535
36-var sendHTML = function(htmlString) {
36+var sendHTML = function(htmlString, comment, channel) {
3737 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+
4254
4355 const serialiserTabProps = {
44- url: serialisedURI,
56+ url: encodeURI(serialisedURI),
4557 active: true
4658 }
4759
4860 console.log('launching a capsule...')
@@ -52,14 +64,36 @@
5264 })
5365 })
5466 }
5567
68+var clearField = function() {
69+ return function listener(event) {
70+ event.target.innerText = ''
71+ event.target.removeEventListener(event.type, listener)
72+ }
73+}
74+
5675 var hookToElements = function() {
5776 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+
5883 sendButton.addEventListener('click', function() {
5984 const selectedBox = document.getElementById('capsule-selected-content')
85+ const commentBox = document.getElementById('capsule-comment-field')
86+ const channelField = document.getElementById('capsule-channel-field')
6087
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)
6296 })
6397 }
6498
6599 document.addEventListener('DOMContentLoaded', getSelectedHTML)
os/parserView
@@ -1,8 +1,8 @@
11 #!/usr/bin/env node
22
33 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')
55
66 var url = require('url')
77
88 // parse URL, split up query params
@@ -15,29 +15,38 @@
1515 for (var i = 0, len = payloadArray.length ; i<len ; i+=2) {
1616 payload[payloadArray[i]] = (payloadArray[i+1])
1717 }
1818
19-// decode body from base64
19+// decode payload from base64
2020 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+}
2124 payload.title = unescape(payload.title)
25+payload.channel = unescape(payload.channel)
2226
2327 // ssbify the dang thing, finally
2428 var ssbifyString = require('ssbify-string')
2529 var ssbClient = require('ssb-client')
2630
2731 ssbClient(function (err, sbot) {
2832 if (err) fs.writeFileSync('capsule.log', err, 'utf8')
29-
33+
34+
3035 ssbifyString(
3136 sbot, payload.body,
3237 { ignoreBrokenLinks: true, url: payload.src, title: payload.title },
3338 function(err, res) {
3439 if (err) fs.writeFileSync('capsule.log', err, 'utf8')
40+ else fs.writeFileSync('capsule.log', res, 'utf8')
3541
42+
43+ // TODO preflight check to ensure a gross post is not pushed instead
44+
3645 // publish a message
37- sbot.publish({ type: 'post', text: res, channel: 'test' },
46+ sbot.publish({ type: 'post', text: res, channel: payload.channel || '' },
3847 function (err, msg) {
3948 if (err) fs.writeFileSync('capsule.log', err, 'utf8')
4049 })
41-
50+
4251 })
4352 })
package.jsonView
@@ -1,7 +1,7 @@
11 {
22 "name": "capsule",
3- "version": "0.1.0",
3+ "version": "0.2.0",
44 "description": "HTML snippet extractor/cypherspace re-transmitter",
55 "main": "capsule.js",
66 "scripts": {
77 "test": "echo \"Error: no test specified\" && exit 1"

Built with git-ssb-web