Convirted to be ES6 compliant.

This commit is contained in:
Maxim Stewart 2018-11-04 19:05:11 -06:00
parent 6e683fd2af
commit 177d79fb4f
3 changed files with 45 additions and 22 deletions

View File

@ -11,6 +11,7 @@
<body> <body>
<font size="4"> <font size="4">
<div id="alertMessage"> </div>
<p> <p>
Alt Tab Page allows the user to select their preferred load page for new tabs and defaults to Google's when not in use. Alt Tab Page allows the user to select their preferred load page for new tabs and defaults to Google's when not in use.
<br/><br/> <br/><br/>

View File

@ -1,34 +1,54 @@
// Declare variables. // Declare variables.
const browserStorage = browser.storage.local; const browserStorage = browser.storage.local;
const tabPgInput = document.querySelector("#tabPageToLoad"); const tabPgInput = document.querySelector("#tabPageToLoad");
const saveBttn = document.querySelector("#saveButtonAction"); const saveBttn = document.querySelector("#saveButtonAction");
const delBttn = document.querySelector("#delButtonAction"); const delBttn = document.querySelector("#delButtonAction");
const messageDiv = document.querySelector("#alertMessage");
/* Asign signal handaling in settings page. */ /* Asign signal handaling in settings page. */
// Save desired url.... // Save desired url....
saveBttn.addEventListener('click', () => { saveBttn.addEventListener('click', () => {
var urlLink = tabPgInput.value; let urlLink = tabPgInput.value;
urlLink = (urlLink.match(/(localhost)\b/)) ? urlLink.replace("localhost", "127.0.0.1") : urlLink; let bannerTag = document.createElement("P");
urlLink = (urlLink.match(/^(http:\/\/|https:\/\/)/)) ? urlLink : "http://" + urlLink; let text = document.createTextNode("Saved Alt Tab Page to: " + urlLink);
urlLink = (urlLink.match(/(localhost)\b/)) ? urlLink.replace("localhost", "127.0.0.1") : urlLink;
urlLink = (urlLink.match(/^(http:\/\/|https:\/\/)/)) ? urlLink : "http://" + urlLink;
browserStorage.clear(); browserStorage.clear();
browserStorage.set({ userSelectedTabPage : urlLink }); tabPgInput.value = urlLink;
bannerTag.style.padding = "0.5em";
bannerTag.style.background = "#80e03d";
bannerTag.style.color = "#ffffff";
bannerTag.append(text);
messageDiv.append(bannerTag);
tabPgInput.value = urlLink; browserStorage.set({ userSelectedTabPage : urlLink });
console.log("Saved Alt Tab Page: " + urlLink); console.log("Saved Alt Tab Page to: " + urlLink);
clearMessages();
}); });
// Delete desired url and set Default marker.... // Delete desired url and set Default marker....
delBttn.addEventListener('click', () => { delBttn.addEventListener('click', () => {
browserStorage.clear(); let bannerTag = document.createElement("P");
let text = document.createTextNode("Deleted " + tabPgInput.value +
" as setting and defaulting to Google...");
bannerTag.style.padding = "0.5em";
bannerTag.style.background = "#80e03d";
bannerTag.style.color = "#ffffff";
bannerTag.append(text);
messageDiv.append(bannerTag);
tabPgInput.value = "Default"; tabPgInput.value = "Default";
browserStorage.clear();
console.log("Deleted Alt Tab Page..."); console.log("Deleted Alt Tab Page...");
clearMessages();
}); });
// On start load from settings // On start load from settings
function loadOnStart(restoredSettings) { const loadOnStart = (restoredSettings) => {
var homeTabURL = restoredSettings.userSelectedTabPage; let homeTabURL = restoredSettings.userSelectedTabPage;
console.log("Trying to load settings if any..."); console.log("Trying to load settings if any...");
if (homeTabURL !== "Default" && homeTabURL !== undefined) { if (homeTabURL !== "Default" && homeTabURL !== undefined) {
@ -38,7 +58,11 @@ function loadOnStart(restoredSettings) {
} }
} }
function onError(e) { console.error(e); } const clearMessages = () => {
setTimeout(function () {
messageDiv.innerHTML = "";
}, 4000);
}
const onError = (e) => { console.error(e); }
browserStorage.get().then(loadOnStart, onError); browserStorage.get().then(loadOnStart, onError);

View File

@ -1,11 +1,11 @@
function redirectToPreferedHome() { const redirectToPreferedHome = () => {
var tabPgSettings = browser.storage.local.get(); let tabPgSettings = browser.storage.local.get();
tabPgSettings.then(finishLoad, onError); tabPgSettings.then(finishLoad, onError);
} }
function finishLoad(toLoadSettings) { const finishLoad = (toLoadSettings) => {
var loadSelectedPage = browser.tabs; let loadSelectedPage = browser.tabs;
var pageToLoad = toLoadSettings.userSelectedTabPage; let pageToLoad = toLoadSettings.userSelectedTabPage;
console.log("Trying to load settings if any..."); console.log("Trying to load settings if any...");
if (pageToLoad !== "Default" && pageToLoad !== undefined) { if (pageToLoad !== "Default" && pageToLoad !== undefined) {
@ -15,7 +15,5 @@ function finishLoad(toLoadSettings) {
} }
} }
function onError(error) { console.log(`Error: ${error}`); } const onError = (error) => { console.log(`Error: ${error}`); }
redirectToPreferedHome(); redirectToPreferedHome();