Convirted to be ES6 compliant.
This commit is contained in:
parent
6e683fd2af
commit
177d79fb4f
|
@ -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/>
|
||||||
|
|
|
@ -3,32 +3,52 @@ 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;
|
||||||
|
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(/(localhost)\b/)) ? urlLink.replace("localhost", "127.0.0.1") : urlLink;
|
||||||
urlLink = (urlLink.match(/^(http:\/\/|https:\/\/)/)) ? urlLink : "http://" + urlLink;
|
urlLink = (urlLink.match(/^(http:\/\/|https:\/\/)/)) ? urlLink : "http://" + urlLink;
|
||||||
|
|
||||||
browserStorage.clear();
|
browserStorage.clear();
|
||||||
browserStorage.set({ userSelectedTabPage : urlLink });
|
|
||||||
|
|
||||||
tabPgInput.value = urlLink;
|
tabPgInput.value = urlLink;
|
||||||
console.log("Saved Alt Tab Page: " + urlLink);
|
bannerTag.style.padding = "0.5em";
|
||||||
|
bannerTag.style.background = "#80e03d";
|
||||||
|
bannerTag.style.color = "#ffffff";
|
||||||
|
bannerTag.append(text);
|
||||||
|
messageDiv.append(bannerTag);
|
||||||
|
|
||||||
|
browserStorage.set({ userSelectedTabPage : 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);
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue