Browse Source

Added updating of badge for current process item

master
Teknikode 3 years ago
parent
commit
ac9b1a29dc

+ 0
- 20
content/popup.css View File

@@ -1,20 +0,0 @@
html, body {
width: 100px;
}

button {
margin: 3% auto;
padding: 4px;
text-align: center;
font-size: 1.5em;
cursor: pointer;
width: 100%;
}

.clear {
background-color: #FBFBC9;
}

.clear:hover {
background-color: #EAEAC9;
}

content/options.css → css/common.css View File


+ 0
- 0
css/options.css View File


+ 0
- 0
css/popup.css View File


+ 1
- 0
manifest.json View File

@@ -21,6 +21,7 @@
],
"browser_action": {
"browser_style": true,
"default_icon": {
"16": "images/favicon-16.png",
"48": "images/favicon-48.png"

+ 32
- 1
scripts/Crypto-js/crypto-js.min.js
File diff suppressed because it is too large
View File


+ 2
- 2
scripts/EncryptionWorker.js View File

@@ -1,4 +1,4 @@
self.addEventListener('message', function (e) {
self.onmessage = function (e) {
importScripts(e.data.script);
var bytes = new Uint8Array(e.data.file);

@@ -81,7 +81,7 @@
};

self.postMessage(objData, [objData.buffer]);
}, false);
}

function _arrayToArrayBuffer(array) {
var len = array.length;

+ 21
- 1
scripts/background.js View File

@@ -1,3 +1,8 @@
/*
-------- Global State Variable ---------
*/
var processCount = 0;

/*
Create all the context menu items.
*/
@@ -46,4 +51,19 @@ browser.contextMenus.onClicked.addListener(function(info, tab) {
shortenUrl(fullUrl);
break;
}
});
});

// Updates the process item list
function addProcessItem(type, url) {
console.log('Added ' + type + ': ' + url);
// Update the process count
processCount++;
// Update Badge
browser.browserAction.setBadgeText({text: processCount.toString()});
// add the item to the browser action
var sending = browser.runtime.sendMessage({cmd: 'add-item', type: type, value: url});
sending.then(onResponse, onError);
}

+ 20
- 1
scripts/common.js View File

@@ -22,6 +22,14 @@ function onOpened() {
console.log('Options page opened');
}

/*
Called when there was a response.
We'll just log the response here.
*/
function onResponse(msg) {
console.log('Response: ${msg}');
}

/*
Called when there was an error.
We'll just log the error here.
@@ -30,8 +38,8 @@ function onError(error) {
console.log('Error: ${error}');
}


function notify(title, message) {
console.log(title + ": " + message);
browser.notifications.create({
"type": "basic",
"iconUrl": browser.extension.getURL("images/favicon-48.png"),
@@ -40,6 +48,17 @@ function notify(title, message) {
});
}

function randomString(length, chars) {
var mask = '';
if (chars.indexOf('a') > -1) mask += 'abcdefghijklmnopqrstuvwxyz';
if (chars.indexOf('A') > -1) mask += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (chars.indexOf('#') > -1) mask += '0123456789';
if (chars.indexOf('!') > -1) mask += '~`!@#$%^&*()_+-={}[]:";\'<>?,./|\\';
var result = '';
for (var i = length; i > 0; --i) result += mask[Math.floor(Math.random() * mask.length)];
return result;
}

function getFileExtension(fileName) {
var index = fileName.lastIndexOf('.');
return '.' + fileName.substr(index + 1);

+ 2
- 2
scripts/options.js View File

@@ -9,8 +9,8 @@ function saveOptions(e) {
function restoreOptions() {

function setCurrentChoice(result) {
document.querySelector("#username").value = result.username;
document.querySelector("#authToken").value = result.authToken;
document.querySelector("#username").value = result.username || "";
document.querySelector("#authToken").value = result.authToken || "";
}

function onError(error) {

+ 3
- 0
scripts/paste.js View File

@@ -10,6 +10,9 @@ function createPaste(text) {
if (response.result) {
var pasteUrl = response.result.url;
browser.tabs.create({ url: pasteUrl });
// Update the browser action
addProcessItem('Paste', pasteUrl);
}
else {
notify("Paste Error", response.error.message);

+ 15
- 6
scripts/popup.js View File

@@ -1,10 +1,19 @@
$(document).ready(function () {
$('#clearList').click(function () {
$('#itemList').html('<li>No Items</li>');
});
$(document).ready(function () {
$('#settings').click(function () {
var opening = browser.runtime.openOptionsPage();
opening.then(onOpened, onError);
});
});
});

browser.runtime.onMessage.addListener(processMessage);

function processMessage(msg) {
switch (msg.cmd) {
case 'progress':
console.log('Current ' + msg.type + ' Progress: ' + msg.value + '%');
break;
case 'add-item':
console.log('Added ' + msg.type + ' Item: ' + msg.value);
break;
}
}

+ 3
- 0
scripts/shorten.js View File

@@ -9,6 +9,9 @@ function shortenUrl(url) {
success: function (response) {
if (response.result) {
var shortUrl = response.result.shortUrl;
// Update the browser action
addProcessItem('Shortened Url', shortUrl);
notify("Url Shortened", "The Url has been shortened to: " + shortUrl);
}
else {

+ 34
- 28
scripts/upload.js View File

@@ -1,6 +1,3 @@
var encScriptSrc = 'EncryptionWorker.js';
var aesScriptSrc = 'Crypto-js/crypto-js.min.js';

function uploadFromUrl(contentUrl) {
// Download the file
var xhr = new XMLHttpRequest();
@@ -8,13 +5,26 @@ function uploadFromUrl(contentUrl) {
xhr.responseType = 'blob';
xhr.onload = function() {
// Encrypt the downloaded file
//encryptFile(xhr.response, 'application/octet-stream', false, false, false, 256, 128, uploadFile);
encryptFile(xhr.response, xhr.response.type, false, false, false, 256, 128, 1000, uploadFile);
};
xhr.onerror = function(err) {
notify("Upload Error", err);
};
xhr.onprogress = function (data) {
if (data.lengthComputable) {
var percentComplete = parseInt(((data.loaded / data.total) * 100), 10);
// display loaded progress
console.log("Download Progress" + percentComplete + '% Downloaded');
}
}
xhr.send();
}

// Function to encrypt a file, overide the file's data attribute with the encrypted value, and then call a callback function if supplied
function encryptFile(fileBlob, contentType, saveKey, serverSideEncrypt, genDelKey, keySize, blockSize, callback) {
function encryptFile(fileBlob, contentType, saveKey, serverSideEncrypt, genDelKey, keySize, blockSize, chunkSize, callback) {
var encScriptSrc = browser.extension.getURL('scripts/EncryptionWorker.js');
var aesScriptSrc = browser.extension.getURL('scripts/Crypto-js/crypto-js.min.js');
// Start the file reader
var reader = new FileReader();

@@ -22,51 +32,43 @@ function encryptFile(fileBlob, contentType, saveKey, serverSideEncrypt, genDelKe
reader.onload = (function (callback) {
return function (e) {
// Create random key and iv (divide size by 8 for character length)
var keyBytes = secureRandom(keySize / 8);
var keyWords = CryptoJS.lib.WordArray.create(keyBytes);
var keyStr = keyWords.toString(CryptoJS.enc.Base64);
var ivBytes = secureRandom(blockSize / 8);
var ivWords = CryptoJS.lib.WordArray.create(ivBytes);
var ivStr = ivWords.toString(CryptoJS.enc.Base64);
var keyStr = randomString((keySize / 8), '#aA');
var ivStr = randomString((blockSize / 8), '#aA');

// Encrypt on the server side if they ask for it
if (serverSideEncrypt) {
callback(e.target.result, keyStr, ivStr, contentType, saveKey, serverSideEncrypt, genDelKey);
callback(e.target.result, keyStr, ivStr, keySize, blockSize, contentType, saveKey, serverSideEncrypt, genDelKey);
}
else {
var worker = new Worker(GenerateBlobURL(encScriptSrc));
var worker = new Worker(encScriptSrc);

worker.addEventListener('message', function (e) {
worker.onmessage = function (e) {
switch (e.data.cmd) {
case 'progress':
var percentComplete = Math.round(e.data.processed * 100 / e.data.total);
// Display encryption progress
notify("Upload Progress", percentComplete + '% Encrypted');
console.log("Upload Progress: " + percentComplete + '% Encrypted');
break;
case 'finish':
if (callback != null) {
// Finish
callback(e.data.buffer, keyStr, ivStr, contentType, saveKey, serverSideEncrypt, genDelKey);
callback(e.data.buffer, keyStr, ivStr, keySize, blockSize, contentType, saveKey, serverSideEncrypt, genDelKey);
}
break;
}
});
};

worker.onerror = function (err) {
// An error occured
/* NOTIFY SOMEONE */
notify("Upload Error", err);
notify("Upload Error", err.message);
}

// Generate the script to include as a blob
var scriptBlob = GenerateBlobURL(aesScriptSrc);

// Execute worker with data
var objData =
{
cmd: 'encrypt',
script: scriptBlob,
script: aesScriptSrc,
key: keyStr,
iv: ivStr,
chunkSize: chunkSize,
@@ -79,9 +81,9 @@ function encryptFile(fileBlob, contentType, saveKey, serverSideEncrypt, genDelKe

reader.onprogress = function (data) {
if (data.lengthComputable) {
var progress = parseInt(((data.loaded / data.total) * 100), 10);
var percentComplete = parseInt(((data.loaded / data.total) * 100), 10);
// display loaded progress
notify("Upload Progress", percentComplete + '% Loaded');
console.log("Upload Progress" + percentComplete + '% Loaded');
}
}

@@ -89,7 +91,7 @@ function encryptFile(fileBlob, contentType, saveKey, serverSideEncrypt, genDelKe
reader.readAsArrayBuffer(fileBlob);
}

function uploadFile(data, key, iv, contentType, saveKey, serverSideEncrypt, genDelKey)
function uploadFile(data, key, iv, keySize, blockSize, contentType, saveKey, serverSideEncrypt, genDelKey)
{
// Get the upload url
var uploadAPI = "https://api.teknik.io/v1/Upload";
@@ -100,7 +102,7 @@ function uploadFile(data, key, iv, contentType, saveKey, serverSideEncrypt, genD
// Create the form data to send
var fd = new FormData();
fd.append('file', blob);
fd.append('contentType', filetype);
fd.append('contentType', contentType);
fd.append('saveKey', saveKey);
if (saveKey)
{
@@ -125,7 +127,7 @@ function uploadFile(data, key, iv, contentType, saveKey, serverSideEncrypt, genD
function uploadProgress(evt) {
if (evt.lengthComputable) {
var percentComplete = Math.round(evt.loaded * 100 / evt.total);
notify("Upload Progress", percentComplete + '% Uploaded');
console.log("Upload Progress" + percentComplete + '% Uploaded');
}
}

@@ -138,8 +140,12 @@ function uploadComplete(key, saveKey, evt) {
if (!saveKey) {
fullUrl = fullUrl + '#' + key;
}
// Open a new tab to the upload
browser.tabs.create({ url: fullUrl });
// Update the browser action
addProcessItem('Upload', fullUrl);
}
else
{

+ 2
- 0
views/options.html View File

@@ -3,6 +3,8 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/common.css"/>
<link rel="stylesheet" href="../css/options.css"/>
</head>

<body>

+ 26
- 7
views/popup.html View File

@@ -3,17 +3,36 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../content/popup.css"/>
<link rel="stylesheet" href="../css/common.css"/>
<link rel="stylesheet" href="../css/popup.css"/>
<title>Teknik</title>
</head>

<body>
<ul id="itemList">
<li>No Items</li>
</ul>
<button class="button clear" id="clearList">Clear</button>
<hr>
<button class="button settings" id="settings">Settings</button>
<div class="panel">
<div id="process-list">No Items</div>
<div id="extraTools">
<button id="settings">Settings</button>
</div>
</div>
<div id="templates" style="display: none">
<div id="process-item-template">
<div id="process-item" class="panel-section panel-section-header">
<div class="text-section-header" id="process-type"/>
<div class="text-section-header" id="url"></div>
</div>
<div class="panel-section panel-section-footer">
<div id="open" class="panel-section-footer-button">Open</div>
<div class="panel-section-footer-separator"></div>
<div id="remove" class="panel-section-footer-button default">Remove</div>
</div>
</div>
</div>
<script type="application/javascript" src="../scripts/JQuery/jquery-3.1.1.min.js"></script>
<script type="application/javascript" src="../scripts/Mozilla/browser-polyfill.js"></script>
<script type="application/javascript" src="../scripts/popup.js"></script>
</body>

Loading…
Cancel
Save