chromium/capsule.jsView |
---|
12 | 12 | }) |
13 | 13 | } |
14 | 14 | |
15 | 15 | var renderSelectedHTML = function(selection) { |
16 | | - const parsedSelection = JSON.parse(selection) |
17 | | - |
18 | | - var modify = [] |
| 16 | + chrome.tabs.getSelected(function(selectedTab) { |
| 17 | + const titleField = document.getElementById('capsule-title-field') |
| 18 | + titleField.innerText = selectedTab.title |
19 | 19 | |
20 | | - const selectedBox = document.getElementById('capsule-selected-content') |
21 | | - |
22 | | - if (parsedSelection.html) { |
23 | | - selectedBox.innerHTML = parsedSelection.html |
24 | | - } |
| 20 | + const parsedSelection = JSON.parse(selection) |
| 21 | + const selectedBox = document.getElementById('capsule-selected-content') |
| 22 | + if (parsedSelection.html) { |
| 23 | + selectedBox.innerHTML = parsedSelection.html |
| 24 | + } |
| 25 | + }) |
25 | 26 | } |
26 | 27 | |
27 | 28 | var encodeHTMLString = function(htmlString) { |
28 | 29 | |
32 | 33 | |
33 | 34 | return btoa(encodeURIComponent(htmlString)) |
34 | 35 | } |
35 | 36 | |
36 | | -var sendHTML = function(htmlString, comment, channel) { |
| 37 | +var sendHTML = function(htmlString, title, comment, channel) { |
37 | 38 | chrome.tabs.getSelected(function(selectedTab) { |
38 | 39 | let serialisedURI = 'ssb-capsule://?body=' |
39 | 40 | .concat(encodeHTMLString(htmlString)) |
40 | | - .concat('&title=').concat(selectedTab.title) |
| 41 | + .concat('&title=').concat(title) |
41 | 42 | |
42 | 43 | if (typeof selectedTab.url === 'string') { |
43 | 44 | serialisedURI = serialisedURI.concat('&src=').concat(selectedTab.url) |
44 | 45 | } |
50 | 51 | if (typeof channel === 'string') { |
51 | 52 | serialisedURI = serialisedURI.concat('&channel=').concat(channel) |
52 | 53 | } |
53 | 54 | |
54 | | - |
| 55 | + |
55 | 56 | const serialiserTabProps = { |
56 | 57 | url: encodeURI(serialisedURI), |
57 | 58 | active: true |
58 | 59 | } |
73 | 74 | } |
74 | 75 | |
75 | 76 | var hookToElements = function() { |
76 | 77 | const sendButton = document.getElementById('capsule-send') |
| 78 | + const titleField = document.getElementById('capsule-title-field') |
77 | 79 | const commentBox = document.getElementById('capsule-comment-field') |
78 | 80 | const channelField = document.getElementById('capsule-channel-field') |
79 | 81 | |
80 | 82 | channelField.addEventListener('click', clearField()) |
| 83 | + channelField.addEventListener('focus', clearField()) |
81 | 84 | commentBox.addEventListener('click', clearField()) |
| 85 | + commentBox.addEventListener('focus', clearField()) |
82 | 86 | |
83 | 87 | sendButton.addEventListener('click', function() { |
84 | 88 | const selectedBox = document.getElementById('capsule-selected-content') |
| 89 | + const titleField = document.getElementById('capsule-title-field') |
85 | 90 | const commentBox = document.getElementById('capsule-comment-field') |
86 | 91 | const channelField = document.getElementById('capsule-channel-field') |
87 | 92 | |
88 | | - |
| 93 | + |
| 94 | + const title = (titleField.innerText.length > 0 && |
| 95 | + titleField.innerText !== 'title here') ? |
| 96 | + titleField.innerText : null |
89 | 97 | const comment = (commentBox.innerText.length > 0 && |
90 | | - commentBox.innerText !== 'Comment here') ? |
| 98 | + commentBox.innerText !== 'comment here') ? |
91 | 99 | commentBox.innerText : null |
92 | 100 | const channel = channelField.innerText.length > 0 ? |
93 | 101 | channelField.innerText : null |
94 | 102 | |
95 | | - sendHTML(selectedBox.innerHTML, comment, channel) |
| 103 | + sendHTML(selectedBox.innerHTML, title, comment, channel) |
96 | 104 | }) |
97 | 105 | } |
98 | 106 | |
99 | 107 | document.addEventListener('DOMContentLoaded', getSelectedHTML) |