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>
<font size="4">
<div id="alertMessage"> </div>
<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.
<br/><br/>

View File

@ -1,34 +1,54 @@
// Declare variables.
const browserStorage = browser.storage.local;
const tabPgInput = document.querySelector("#tabPageToLoad");
const saveBttn = document.querySelector("#saveButtonAction");
const delBttn = document.querySelector("#delButtonAction");
const tabPgInput = document.querySelector("#tabPageToLoad");
const saveBttn = document.querySelector("#saveButtonAction");
const delBttn = document.querySelector("#delButtonAction");
const messageDiv = document.querySelector("#alertMessage");
/* Asign signal handaling in settings page. */
// Save desired url....
saveBttn.addEventListener('click', () => {
var urlLink = tabPgInput.value;
urlLink = (urlLink.match(/(localhost)\b/)) ? urlLink.replace("localhost", "127.0.0.1") : urlLink;
urlLink = (urlLink.match(/^(http:\/\/|https:\/\/)/)) ? urlLink : "http://" + urlLink;
let urlLink = tabPgInput.value;
let bannerTag = document.createElement("P");
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.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;
console.log("Saved Alt Tab Page: " + urlLink);
browserStorage.set({ userSelectedTabPage : urlLink });
console.log("Saved Alt Tab Page to: " + urlLink);
clearMessages();
});
// Delete desired url and set Default marker....
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";
browserStorage.clear();
console.log("Deleted Alt Tab Page...");
clearMessages();
});
// On start load from settings
function loadOnStart(restoredSettings) {
var homeTabURL = restoredSettings.userSelectedTabPage;
const loadOnStart = (restoredSettings) => {
let homeTabURL = restoredSettings.userSelectedTabPage;
console.log("Trying to load settings if any...");
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);

View File

@ -1,11 +1,11 @@
function redirectToPreferedHome() {
var tabPgSettings = browser.storage.local.get();
const redirectToPreferedHome = () => {
let tabPgSettings = browser.storage.local.get();
tabPgSettings.then(finishLoad, onError);
}
function finishLoad(toLoadSettings) {
var loadSelectedPage = browser.tabs;
var pageToLoad = toLoadSettings.userSelectedTabPage;
const finishLoad = (toLoadSettings) => {
let loadSelectedPage = browser.tabs;
let pageToLoad = toLoadSettings.userSelectedTabPage;
console.log("Trying to load settings if any...");
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();