Browse Source

Fixed uploads not using CORs. Fixed panel updates not occuring if an item was deleted/removed. Added tooltips to popup UI

master
Teknikode 3 years ago
parent
commit
6d6f290ebf
5 changed files with 39 additions and 31 deletions
  1. 3
    2
      manifest.json
  2. 8
    10
      scripts/background.js
  3. 1
    0
      scripts/popup.js
  4. 19
    11
      scripts/upload.js
  5. 8
    8
      views/popup.html

+ 3
- 2
manifest.json View File

@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Teknik Services Extender",
"version": "1.0.2",
"version": "1.0.3",
"author": "uncled1023",

"description": "Allows easy methods to utilize the Teknik Services.",
@@ -16,7 +16,8 @@
"contextMenus",
"storage",
"clipboardRead",
"clipboardWrite"
"clipboardWrite",
"https://api.teknik.io/"
],
"browser_action": {

+ 8
- 10
scripts/background.js View File

@@ -134,12 +134,12 @@ function addProcessItem(type, data) {
// Create a new object for this process and add it to the main list
var item = { id: processedItemTotal, type: type, data: data };
var id = itemList.push(item);
var index = itemList.push(item);
// Update Badge
updateBadge();
return id;
return processedItemTotal;
}

function updateProcessItem(id, type, data) {
@@ -150,25 +150,23 @@ function updateProcessItem(id, type, data) {
switch (type) {
case 'progress':
if (item.type === 'progress') {
allowUpdate = true;
item.type = type;
item.data = data;
}
break;
case 'upload':
case 'paste':
case 'shorten':
if (item.type !== 'error') {
allowUpdate = true;
item.type = type;
item.data = data;
}
break;
case 'error':
allowUpdate = true;
item.type = type;
item.data = data;
break;
}
if (allowUpdate) {
item.type = type;
item.data = data;
}
}
});
}

+ 1
- 0
scripts/popup.js View File

@@ -174,6 +174,7 @@ function fillItem(item) {
itemDiv.find('#title').html('Processing ' + item.data.type + '...');
itemDiv.find('#progress-fill').css('width', item.data.progress + '%');
itemDiv.find('#progress-fill').html(item.data.progress + '% ' + item.data.message);
itemDiv.find('#progress-bar').attr('title', item.data.progress + '% ' + item.data.message);
break;
case 'error':
itemDiv.find('#title').html(item.data.title);

+ 19
- 11
scripts/upload.js View File

@@ -36,7 +36,7 @@ function encryptFile(fileBlob, contentType, settings, itemId, callback) {
var reader = new FileReader();

// When the file has been loaded, encrypt it
reader.onload = (function (callback) {
reader.onload = (function (callback, settings) {
return function (e) {
// Create random key and iv (divide size by 8 for character length)
var keyStr = randomString((settings.uploads.keySize / 8), '#aA');
@@ -84,7 +84,7 @@ function encryptFile(fileBlob, contentType, settings, itemId, callback) {
worker.postMessage(objData, [objData.file]);
}
};
})(callback);
})(callback, settings);

reader.onprogress = function (data) {
if (data.lengthComputable) {
@@ -93,6 +93,11 @@ function encryptFile(fileBlob, contentType, settings, itemId, callback) {
updateProcessItem(itemId, 'progress', { type: 'upload', progress: percentComplete, message: 'Loaded' });
}
}
reader.onerror = function (err) {
updateProcessItem(itemId, 'error', { title: 'Upload Loading Error', message: err.message });
onError("Upload Loading Error: " + err.message);
}

// Start async read
reader.readAsArrayBuffer(fileBlob);
@@ -160,19 +165,22 @@ function uploadComplete(itemId, key, encrypted, genDelKey, evt) {
}
else
{
updateProcessItem(itemId, 'error', { title: 'Upload Error', message: 'Unable to Upload File' });
if (obj.error != null) {
onError("Upload Error: " + obj.error.message);
}
else {
onError('Upload Error: Unable to Upload File');
}
var errorMsg = 'Unable to Upload File';
if (obj.error != null) {
errorMsg = obj.error.message;
}
updateProcessItem(itemId, 'error', { title: 'Upload Error', message: errorMsg });
onError("Upload Error: " + errorMsg);
}
}

function uploadFailed(itemId, evt) {
updateProcessItem(itemId, 'error', { title: 'Upload Error', message: evt });
onError('Upload Error: ' + evt);
var errorMessage = 'Unable to upload file';
if (evt.target.status !== 0) {
errorMessage = 'Status Code: ' + evt.target.status + ' | Message: ' + evt.target.responseText;
}
updateProcessItem(itemId, 'error', { title: 'Upload Error', message: errorMessage });
onError('Upload Error: ' + errorMessage);
}

function uploadCanceled(itemId, evt) {

+ 8
- 8
views/popup.html View File

@@ -16,8 +16,8 @@
<div class="tools-panel">
<span class="tools-title">Teknik Services</span>
<span class="tools-options">
<span id="upload" class="btn"><i class="fa fa-upload"></i></span>
<span id="settings" class="btn"><i class="fa fa-cog"></i></span>
<span id="upload" class="btn" title="Upload a file"><i class="fa fa-upload"></i></span>
<span id="settings" class="btn" title="Click to open settings"><i class="fa fa-cog"></i></span>
</span>
<div class="clear"></div>
</div>
@@ -30,20 +30,20 @@
<div class="item-panel" id="process-item-template">
<div class="item-title">
<div class="title-text" id="title"></div>
<span class="btn item-panel-close" id="close"><i class="fa fa-times-circle"></i></span>
<span class="btn item-panel-close" id="close" title="Remove item from list"><i class="fa fa-times-circle"></i></span>
<div class="clear"></div>
</div>
<div class="item-details" id="item-details">
<div class="item-actions">
<span class="btn" id="copy"><i class="fa fa-clipboard"></i></span>
<span class="btn" id="open"><i class="fa fa-external-link"></i></span>
<span class="btn" id="delete"><i class="fa fa-trash"></i></span>
<span class="btn" id="copy" title="Copy to clipboard"><i class="fa fa-clipboard"></i></span>
<span class="btn" id="open" title="Open in a new tab"><i class="fa fa-external-link"></i></span>
<span class="btn" id="delete" title="Delete this item"><i class="fa fa-trash"></i></span>
</div>
<div class="item-content" id="url"></div>
<div class="clear"></div>
</div>
<div class="item-progress" id="item-progress">
<div class="progress-bar" id="progress-bar">
<div class="progress-bar" id="progress-bar" title="Progress Information">
<span class="progress-fill" id="progress-fill"></span>
</div>
</div>
@@ -54,7 +54,7 @@
<div class="item-panel" id="process-item-error-template">
<div class="item-title">
<div class="title-text" id="title"></div>
<span class="btn item-panel-close" id="close"><i class="fa fa-ban"></i></span>
<span class="btn item-panel-close" id="close"><i class="fa fa-times-circle"></i></span>
<div class="clear"></div>
</div>
<div class="item-details">

Loading…
Cancel
Save