Commit 7ea29b794dfc29dd5e3fb8c818bdd1db5f33b450
URI now properly serialised
dust committed on 3/30/2016, 5:01:09 AMParent: 1d28755f6ce7e8336504a6f6143fe4f932bdface
Files changed
capsule.js | changed |
capsule.js | ||
---|---|---|
@@ -1,11 +1,8 @@ | ||
1 | -// var ssbClient = require('ssb-client') | |
2 | -// var ssbify = require('./lib/ssbify-browser.js') | |
3 | - | |
4 | 1 | var getSelectedHTML = function() { |
5 | 2 | chrome.tabs.query({active: true}, function(tabs) { |
6 | 3 | var tab = tabs[0] |
7 | - debugger | |
4 | + | |
8 | 5 | chrome.tabs.executeScript( |
9 | 6 | { |
10 | 7 | file: './serializeSelectedHTML.js', |
11 | 8 | runAt: 'document_end' |
@@ -15,32 +12,46 @@ | ||
15 | 12 | }) |
16 | 13 | } |
17 | 14 | |
18 | 15 | var renderSelectedHTML = function(selection) { |
19 | - debugger | |
20 | 16 | 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>') | |
27 | 17 | |
28 | 18 | var modify = [] |
29 | - /* iframe.querySelectorAll('img').map(function (i, el) { modify.push(el) }) */ | |
30 | 19 | |
31 | - const selectedBox = document.getElementById('journalet-selected-content') | |
20 | + const selectedBox = document.getElementById('capsule-selected-content') | |
21 | + | |
32 | 22 | if (parsedSelection.html) { |
33 | 23 | selectedBox.innerHTML = parsedSelection.html |
34 | 24 | } |
35 | 25 | } |
36 | 26 | |
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 | + }) | |
44 | 45 | } |
45 | 46 | |
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 | + | |
46 | 56 | document.addEventListener('DOMContentLoaded', getSelectedHTML) |
57 | +document.addEventListener('DOMContentLoaded', hookToElements) |
Built with git-ssb-web