git ssb

3+

dust / capsule



Commit 7ea29b794dfc29dd5e3fb8c818bdd1db5f33b450

URI now properly serialised

dust committed on 3/30/2016, 5:01:09 AM
Parent: 1d28755f6ce7e8336504a6f6143fe4f932bdface

Files changed

capsule.jschanged
capsule.jsView
@@ -1,11 +1,8 @@
1-// var ssbClient = require('ssb-client')
2-// var ssbify = require('./lib/ssbify-browser.js')
3-
41 var getSelectedHTML = function() {
52 chrome.tabs.query({active: true}, function(tabs) {
63 var tab = tabs[0]
7- debugger
4+
85 chrome.tabs.executeScript(
96 {
107 file: './serializeSelectedHTML.js',
118 runAt: 'document_end'
@@ -15,32 +12,46 @@
1512 })
1613 }
1714
1815 var renderSelectedHTML = function(selection) {
19- debugger
2016 const parsedSelection = JSON.parse(selection)
21-
22-// TODO parse CSS and include also
23-// const styleString = '<style>'
24-// .concat(parsedSelection.css.reduce((cssStr, cssObj) =>
25-// cssStr.concat(JSON.stringify(cssObj)), ''))
26-// .concat('</style>')
2717
2818 var modify = []
29- /* iframe.querySelectorAll('img').map(function (i, el) { modify.push(el) }) */
3019
31- const selectedBox = document.getElementById('journalet-selected-content')
20+ const selectedBox = document.getElementById('capsule-selected-content')
21+
3222 if (parsedSelection.html) {
3323 selectedBox.innerHTML = parsedSelection.html
3424 }
3525 }
3626
37-var sendHTML = function(htmlString, url) {
38- ssbify(htmlString, { url: url, ignoreBrokenImgLinks: true },
39- function (err, res) {
40- if (err) throw err
41- console.log(res)
42- alert(res)
43- })
27+var sendHTML = function(htmlString) {
28+ chrome.tabs.getSelected(function(selectedTab) {
29+ let serialisedURI = 'ssb-capsule://?body='
30+ .concat(htmlString)
31+ .concat('&src=')
32+ .concat(selectedTab.url)
33+
34+ const serialiserTabProps = {
35+ url: serialisedURI,
36+ active: true
37+ }
38+
39+ console.log('launching a capsule...')
40+ chrome.tabs.create(serialiserTabProps, function(URITab) {
41+ // TODO this doesn't close the new tab
42+ chrome.tabs.remove(URITab.id)
43+ })
44+ })
4445 }
4546
47+var hookToElements = function() {
48+ const sendButton = document.getElementById('capsule-send')
49+ sendButton.addEventListener('click', function() {
50+ const selectedBox = document.getElementById('capsule-selected-content')
51+
52+ sendHTML(selectedBox.innerHTML)
53+ })
54+}
55+
4656 document.addEventListener('DOMContentLoaded', getSelectedHTML)
57+document.addEventListener('DOMContentLoaded', hookToElements)

Built with git-ssb-web