Browse Source

Updated scripts to be separated concerns.

master
Teknikode 3 years ago
parent
commit
c058609d71

+ 20
- 0
content/background.html View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<textarea id="ta"></textarea>
<script src="../scripts/JQuery/jquery-3.1.1.min.js"></script>
<script src="../scripts/Crypto-js/aes.js"></script>
<script src="../scripts/Crypto-js/enc-base64.js"></script>
<script src="../scripts/Crypto-js/mode-ctr.js"></script>
<script src="../scripts/Crypto-js/lib-typedarrays.js"></script>
<script src="../scripts/Crypto-js/pad-nopadding.js"></script>
<script src="../scripts/common.js"></script>
<script src="../scripts/upload.js"></script>
<script src="../scripts/paste.js"></script>
<script src="../scripts/shorten.js"></script>
<script src="../scripts/background.js"></script>
</body>
</html>

+ 0
- 18
content/upload.js View File

@@ -1,18 +0,0 @@
function onError(error) {
console.log('Error: ${error}');
}

function onGot(item) {
var username = "";
var authToken = "";
if (item.username) {
username = item.username;
}
if (item.authToken) {
authToken = item.authToken;
}
//document.body.style.border = "10px solid " + color;
}

var getting = browser.storage.local.get();
getting.then(onGot, onError);

+ 1
- 9
manifest.json View File

@@ -35,15 +35,7 @@
},

"background": {
"scripts": [
"content/JQuery/jquery-3.1.1.min.js",
"content/Crypto-js/aes.js",
"content/Crypto-js/enc-base64.js",
"content/Crypto-js/mode-ctr.js",
"content/Crypto-js/lib-typedarrays.js",
"content/Crypto-js/pad-nopadding.js",
"content/background.js"
]
"page": "content/background.html"
},
"options_ui": {

content/Crypto-js/aes.js → scripts/Crypto-js/aes.js View File


content/Crypto-js/enc-base64.js → scripts/Crypto-js/enc-base64.js View File


content/Crypto-js/enc-utf16.js → scripts/Crypto-js/enc-utf16.js View File


content/Crypto-js/lib-typedarrays.js → scripts/Crypto-js/lib-typedarrays.js View File


content/Crypto-js/mode-ctr.js → scripts/Crypto-js/mode-ctr.js View File


content/Crypto-js/pad-nopadding.js → scripts/Crypto-js/pad-nopadding.js View File


content/JQuery/jquery-3.1.1.min.js → scripts/JQuery/jquery-3.1.1.min.js View File


content/background.js → scripts/background.js View File

@@ -106,70 +106,4 @@ browser.contextMenus.onClicked.addListener(function(info, tab) {
});
break;
}
});

function notify(title, message) {
browser.notifications.create({
"type": "basic",
"iconUrl": browser.extension.getURL("images/favicon-48.png"),
"title": title,
"message": message
});
}

function copyTextToClipboard(text) {
var textArea = document.createElement("textarea");

//
// *** This styling is an extra step which is likely not required. ***
//
// Why is it here? To ensure:
// 1. the element is able to have focus and selection.
// 2. if element was to flash render it has minimal visual impact.
// 3. less flakyness with selection and copying which **might** occur if
// the textarea element is not visible.
//
// The likelihood is the element won't even render, not even a flash,
// so some of these are just precautions. However in IE the element
// is visible whilst the popup box asking the user for permission for
// the web page to copy to the clipboard.
//

// Place in top-left corner of screen regardless of scroll position.
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;

// Ensure it has a small width and height. Setting to 1px / 1em
// doesn't work as this gives a negative w/h on some browsers.
textArea.style.width = '2em';
textArea.style.height = '2em';

// We don't need padding, reducing the size if it does flash render.
textArea.style.padding = 0;

// Clean up any borders.
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';

// Avoid flash of white box if rendered for any reason.
textArea.style.background = 'transparent';


textArea.value = text;

document.body.appendChild(textArea);

textArea.select();

try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}

document.body.removeChild(textArea);
}
});

+ 24
- 0
scripts/common.js View File

@@ -0,0 +1,24 @@
function notify(title, message) {
browser.notifications.create({
"type": "basic",
"iconUrl": browser.extension.getURL("images/favicon-48.png"),
"title": title,
"message": message
});
}

function copyTextToClipboard(text) {
var result = false;
var textarea = document.getElementById('ta');
textarea.value = text;
textarea.select();

if (document.execCommand('copy')) {
result = true;
} else {
console.error('failed to get clipboard content');
}

textarea.value = '';
return result;
}

+ 20
- 0
scripts/paste.js View File

@@ -0,0 +1,20 @@
function createPaste(text) {
// Get the paste url
var pasteAPI = "https://api.teknik.io/v1/Paste";
// Paste the passed in text
$.ajax({
type: "POST",
url: pasteAPI,
data: { code: text },
success: function (response) {
if (response.result) {
var pasteUrl = response.result.url;
copyTextToClipboard(pasteUrl);
notify("Paste Created", "Paste has been created and saved to your clipboard.");
}
else {
notify("Paste Error", response.error.message);
}
}
});
}

+ 20
- 0
scripts/shorten.js View File

@@ -0,0 +1,20 @@
function shortenUrl(url) {
// Get the shorten API url
var shortenAPI = "https://api.teknik.io/v1/Shorten";
// Shorten the url
$.ajax({
type: "POST",
url: shortenAPI,
data: { url: url },
success: function (response) {
if (response.result) {
var shortUrl = response.result.shortUrl;
copyTextToClipboard(shortUrl);
notify("Url Shortened", "The Url has been shortened and saved to your clipboard.");
}
else {
notify("Shorten Error", response.error.message);
}
}
});
}

+ 0
- 0
scripts/upload.js View File


+ 0
- 0
settings/options.css View File


Loading…
Cancel
Save