-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
868f0ee
commit 33fd00b
Showing
9 changed files
with
284 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
async function encryptText(text){ | ||
if(typeof text === 'string' && text.length !== 0){ | ||
chrome.storage.local.get(['encryptFor'], async result => { | ||
if (result.encryptFor.length != 0){ | ||
var publicKeys = await Promise.all(result.encryptFor.map(async (key) => { | ||
return (await openpgp.key.readArmored(key)).keys[0]; | ||
})); | ||
|
||
openpgp.encrypt({ | ||
message: openpgp.message.fromText(text), | ||
publicKeys: publicKeys, | ||
}).then(encrypted => { | ||
var encryptedText = encrypted.data; | ||
encryptedText = encryptedText.replace(encryptedText.slice(27, 88), ''); | ||
navigator.clipboard.writeText(encryptedText); | ||
M.toast({html: `LivePGP: The selected text was encrypted, it's on your clipboard!`}); | ||
}); | ||
} else { | ||
M.toast({html: `LivePGP: No public keys were selected, so nothing was encrypted. ¯\\_(ツ)_/¯`}); | ||
} | ||
}); | ||
} else { | ||
M.toast({html: `LivePGP: Nothing was selected, so nothing was encrypted. ¯\\_(ツ)_/¯`}); | ||
} | ||
} | ||
|
||
document.addEventListener("keydown", function (e) { | ||
if (e.ctrlKey && e.shiftKey && (e.key === "e" || e.key === "E")) { | ||
encryptText(window.getSelection().toString()); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<style> | ||
body { | ||
min-width: 500px; | ||
} | ||
|
||
.materialize-textarea { | ||
white-space: pre-wrap; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<nav> | ||
<div class="nav-wrapper blue lighten-4"> | ||
<ul class="left"> | ||
<li class="active"><a href="menu.html">Public keys</a></li> | ||
<li><a href="options.html">Private key</a></li> | ||
</ul> | ||
</div> | ||
</nav> | ||
<div class=""> | ||
<ul class="collapsible" style="height: 90vh; width: 100vw; margin:0px; box-shadow: none;"> | ||
<li class="active"> | ||
<div class="collapsible-header"><i class="material-icons">vpn_key</i>Select public keys</div> | ||
<div class="collapsible-body"> | ||
<form id="use-public-key-form"> | ||
<div id="select-pub-keys"> | ||
|
||
</div> | ||
<span class="blue-text text-lighten-3"> | ||
Note: To encrypt a message, select the text you want to encrypt and press CTRL + SHIFT + E, | ||
then paste the encrypted text anywhere, it's in your clipboard! | ||
</span> | ||
<button class="btn waves-effect waves-light">Submit</button> | ||
</form> | ||
</div> | ||
</li> | ||
<li> | ||
<div class="collapsible-header"><i class="material-icons">save_alt</i>Import a public key</div> | ||
<div class="collapsible-body"> | ||
<form id="import-public-key-form"> | ||
<div class="input-field"> | ||
<input type="text" id="public-key-nickname-ifield"> | ||
<label for="public-key-nickname-ifield">Public key nickname</label> | ||
</div> | ||
|
||
<div class="input-field"> | ||
<textarea id="public-key-ifield" class="materialize-textarea"></textarea> | ||
<label for="public-key-ifield">Public key</label> | ||
</div> | ||
<p> | ||
<span class="blue-text text-lighten-3"> | ||
Note: At the moment you can only import one public key at a time, importing more than one key will | ||
result in only one key being imported, or none at all. This also applies to ASCII armored | ||
keys bundled up in one single key block, only one key from the block will be imported. | ||
</span> | ||
</p> | ||
<button class="btn waves-effect waves-light" type="submit">Submit</button> | ||
</form> | ||
</div> | ||
</li> | ||
</ul> | ||
</div> | ||
|
||
<script src="/vendor/materialize.min.js"></script> | ||
<script src="menu.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
M.AutoInit(); | ||
|
||
var elems = document.querySelectorAll('.collapsible'); | ||
var instances = M.Collapsible.init(elems); | ||
|
||
chrome.storage.local.get(['publicKeys', "encryptFor"], (result) => { | ||
if (typeof result.publicKeys === 'undefined' || result.publicKeys == null) { | ||
chrome.storage.local.set({ | ||
publicKeys: [], | ||
encryptFor: typeof encryptFor === 'undefined' ? [] : encryptFor | ||
}, (result) => { | ||
|
||
}); | ||
} else if(result.publicKeys.length == 0) { | ||
M.toast({html: 'Set public keys on the "Import a public key" section'}); | ||
} else { | ||
result.publicKeys.forEach(publicKey => { | ||
var label = document.createElement("label"); | ||
var checkboxWrapper = document.createElement("p"); | ||
var checkbox = document.createElement("input"); | ||
checkbox.classList.add("pubkeyCheckbox"); | ||
if(result.encryptFor.includes(publicKey.value)) checkbox.setAttribute("checked", ""); | ||
checkbox.setAttribute("type", "checkbox"); | ||
checkbox.setAttribute("key", publicKey.value); | ||
var span = document.createElement("span"); | ||
span.innerHTML = publicKey.nickname; | ||
label.appendChild(checkbox); | ||
label.appendChild(span); | ||
checkboxWrapper.appendChild(label); | ||
document.getElementById("select-pub-keys").appendChild(checkboxWrapper); | ||
}); | ||
} | ||
}); | ||
|
||
document.getElementById("import-public-key-form").addEventListener("submit" ,(e) => { | ||
e.preventDefault(); | ||
chrome.storage.local.get(['publicKeys'], (result) => { | ||
result.publicKeys.push({ | ||
value: document.getElementById('public-key-ifield').value, | ||
nickname: document.getElementById('public-key-nickname-ifield').value | ||
}); | ||
|
||
chrome.storage.local.set({ | ||
publicKeys: result.publicKeys | ||
}, (result) => { | ||
M.toast({html: 'Public key added! Reloading...'}); | ||
setTimeout(() => { | ||
location.reload(); | ||
}, 1000); | ||
}); | ||
}); | ||
}); | ||
|
||
document.getElementById("use-public-key-form").addEventListener("submit" ,(e) => { | ||
e.preventDefault(); | ||
var pubkeys = []; | ||
document.querySelectorAll(".pubkeyCheckbox").forEach(checkbox => { | ||
if (checkbox.checked){ | ||
pubkeys.push(checkbox.getAttribute("key")); | ||
} | ||
}); | ||
|
||
chrome.storage.local.set({ | ||
encryptFor: pubkeys | ||
}, () => { | ||
M.toast({html: 'Public keys set!'}) | ||
}); | ||
}); | ||
|
||
chrome.storage.local.get(['privateKey'], (result) => { | ||
if (typeof result.privateKey !== 'undefined' || result.privateKey == null || result.privateKey == ''){ | ||
document.querySelectorAll('a[href="options.html"]').forEach((element) => { | ||
element.classList.add("pulse"); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#toast-container { | ||
display: block; | ||
position: fixed; | ||
z-index: 10000; | ||
} | ||
|
||
@media only screen and (max-width: 600px) { | ||
#toast-container { | ||
min-width: 100%; | ||
bottom: 0%; | ||
} | ||
} | ||
|
||
@media only screen and (min-width: 601px) and (max-width: 992px) { | ||
#toast-container { | ||
left: 5%; | ||
bottom: 7%; | ||
max-width: 90%; | ||
} | ||
} | ||
|
||
@media only screen and (min-width: 993px) { | ||
#toast-container { | ||
top: 10%; | ||
right: 7%; | ||
max-width: 86%; | ||
} | ||
} | ||
|
||
.toast { | ||
font-family: monospace, monospace; | ||
-webkit-box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2); | ||
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.12), 0 1px 5px 0 rgba(0, 0, 0, 0.2); | ||
border-radius: 2px; | ||
top: 35px; | ||
width: auto; | ||
margin-top: 10px; | ||
position: relative; | ||
max-width: 100%; | ||
height: auto; | ||
min-height: 48px; | ||
line-height: 1.5em; | ||
background-color: #323232; | ||
padding: 10px 25px; | ||
font-size: 1.1rem; | ||
font-weight: 300; | ||
color: #fff; | ||
display: -webkit-box; | ||
display: -webkit-flex; | ||
display: -ms-flexbox; | ||
display: flex; | ||
-webkit-box-align: center; | ||
-webkit-align-items: center; | ||
-ms-flex-align: center; | ||
align-items: center; | ||
-webkit-box-pack: justify; | ||
-webkit-justify-content: space-between; | ||
-ms-flex-pack: justify; | ||
justify-content: space-between; | ||
cursor: default; | ||
} | ||
|
||
.toast .toast-action { | ||
color: #eeff41; | ||
font-weight: 500; | ||
margin-right: -25px; | ||
margin-left: 3rem; | ||
} | ||
|
||
.toast.rounded { | ||
border-radius: 24px; | ||
} | ||
|
||
@media only screen and (max-width: 600px) { | ||
.toast { | ||
width: 100%; | ||
border-radius: 0; | ||
} | ||
} |