Commit 9bd1898b authored by taco@waag.org's avatar taco@waag.org
Browse files

share icon and original envelope

parent d30c2c70
<svg
viewBox="0 0 1000 1000"
height="30"
width="30"
xmlns="http://www.w3.org/2000/svg"
role="img"
>
<title>Copy to Clipboard</title>
<path
d="M704 896H64V320h640v192h64V192c0-35-29-64-64-64H512C512 57 455 0 384 0S256 57 256 128H64c-35 0-64 29-64 64v704c0 35 29 64 64 64h640c35 0 64-29 64-64V768h-64v128zM192 192h64s64-29 64-64 29-64 64-64 64 29 64 64 32 64 64 64h64s64 29 64 64H128c0-39 28-64 64-64zm-64 512h128v-64H128v64zm448-128V448L320 640l256 192V704h320V576H576zM128 832h192v-64H128v64zm320-448H128v64h320v-64zM256 512H128v64h128v-64z"
/>
</svg>
......@@ -8,6 +8,7 @@ browser.runtime.onMessage.addListener(function(msg, sender, sendResponse){
let keys = msg.signatures.map(entry=> entry[0]);
let values = msg.signatures.map(entry=>entry[1]);
let envelopes = msg.signatures.map(entry=>entry[2]);
Promise.all(values.map(signature =>
fetch('http://localhost:3000/verify', { method: 'POST', headers: {
......@@ -24,7 +25,7 @@ browser.runtime.onMessage.addListener(function(msg, sender, sendResponse){
//index resultset
const indexed_result = zip(keys,responses);
//save state for later use, indexed by tab
const state = {"signatures": msg.signatures, "results": indexed_result}
const state = {"signatures": msg.signatures, "results": indexed_result, "envelopes": envelopes}
//set the verfication state
let key1 = "pop_state_" + tab_id;
......
......@@ -25,5 +25,5 @@
"background": {
"scripts": ["local_backend.js"]
},
"web_accessible_resources": []
"web_accessible_resources": ["icons/clippy.svg"]
}
......@@ -14,6 +14,12 @@
.pop-button {
margin-top: 10px;
float: right;
cursor: pointer;
background-image: url(icons/clippy.svg);
padding: .25rem;
color: black;
height: 2rem;
width: 2rem;
}
.pop-proof {
......@@ -49,6 +55,7 @@
font-weight: bold;
}
pre {
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
......
......@@ -25,7 +25,7 @@ function signatures_v0(fragments){
}
const signature = JSON.stringify(obj);
return [fragment_type, signature];
return [fragment_type, signature, encoded_signature];//we also save the original envelope to the state for sharing to clipboard purposes
});
}
......
......@@ -7,8 +7,8 @@ if (window.hasRun) {
window.hasRun = true;
function render(state) {
//clear document
document.head.textContent = "";
document.head.textContent = "";
document.body.textContent = "";
for (let i = 0; i < state.signatures.length; i++) {
......@@ -16,49 +16,49 @@ if (window.hasRun) {
let signature = JSON.parse(state.signatures[i][1]);
let message = signature.message;
let result = JSON.parse(state.results[i][1]);
let envelope = state.envelopes[i];
switch(fragmentType) {
case 'data-pop-v0-title':
renderTitle(fragmentType,message,result,signature);
renderTitle(fragmentType,message,result,envelope);
break;
case 'data-pop-v0-abstract':
renderAbstract(fragmentType,message,result,signature);
renderAbstract(fragmentType,message,result,envelope);
break;
case 'data-pop-v0-body':
renderBody(fragmentType,message,result,signature);
renderBody(fragmentType,message,result,envelope);
break;
case 'data-pop-v0-author':
renderAuthor(fragmentType,message,result,signature);
renderAuthor(fragmentType,message,result,envelope);
break;
case 'data-pop-v0-img':
renderImage(fragmentType,message,result,signature);
renderImage(fragmentType,message,result,envelope);
break;
}
}
}
//renders a copybutton for the fragment
function appendCopyButton(fragment, type, message, signature){
function appendCopyButton(fragment, type, message, envelope){
let button = document.createElement('button');
button.classList.add('pop-button');
button.type = "button";
button.textContent = "Copy";
button.onclick = function() {toClipboard(message,signature,type)};
button.onclick = function() {toClipboard(message,envelope,type)};
fragment.appendChild(button);
}
//creates a blockquote (or img) for the message that contains the signature as attribute
function toClipboard(message,signature,type){
let serialized = btoa(JSON.stringify(signature));
//creates a blockquote (or img) for the message that contains the original envelope as attribute
function toClipboard(message, envelope, type){
if(type == 'data-pop-v0-img'){
let img = document.createElement('img');
img.src = message;
img.setAttribute(type,serialized);
img.setAttribute(type,envelope);
navigator.clipboard.writeText(img.outerHTML);
} else {
let blockquote = document.createElement('blockquote');
blockquote.textContent = message;
blockquote.setAttribute(type,serialized);
blockquote.setAttribute(type,envelope);
navigator.clipboard.writeText(blockquote.outerHTML);
}
alert('Copied to clipboard');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment