New version, added hideshow functionality, theme changed a bit.

This commit is contained in:
2018-05-20 18:20:23 -05:00
parent 38972fd87c
commit ca3d2b3513
18 changed files with 166 additions and 55 deletions

View File

@@ -1,36 +1,57 @@
// Set click events for tab blocks
document.addEventListener("click", (e) => {
var target = e.target;
var target = undefined;
if (!e.target.className.includes("pTagTitleText")) {
target = e.target;
} else {
target = e.target.parentElement;
}
var targetID = target.id;
var parentElm = target.parentElement;
var id = 0;
if (targetID == "closeBttn") {
id = parseInt(parentElm.getAttribute("tabID"));
browser.tabs.remove(id);
parentElm.parentElement.removeChild(parentElm);
} else if (targetID == "iconElm" || targetID == "faveIcon") {
if (targetID == "faveIcon")
target = parentElm.parentElement;
} else if (targetID == "iconElm") {
id = parseInt(target.getAttribute("tabID"));
browser.tabs.update(id, { active: true });
browser.tabs.update(id, { active: true });
target.querySelectorAll(".hiderImg")[0].src = "../icons/eyeOpen.png";
oldElm.setAttribute("class", "block");
oldElm = target;
target.setAttribute("class", "block block-focused");
} else if (targetID == "goTop") {
window.scrollTo(0,0);
} else if (targetID == "goBottom") {
window.scrollTo(0,document.body.scrollHeight);
window.scrollTo(0, document.body.scrollHeight);
} else if (targetID == "goToTab") {
// Go to selected and 100px up
oldElm.scrollIntoView();
window.scrollBy(0, -100);
} else if (targetID == "newTab") {
createTab();
} else if (targetID == "hideTgglBttn") {
id = parseInt(parentElm.getAttribute("tabID"));
if (id != oldElm.getAttribute("tabID")) {
if (target.src.includes("eyeClosed.png")) {
parentElm.setAttribute("class", "block");
target.src = "../icons/eyeOpen.png"
unhideSelectedTab(id);
} else {
parentElm.setAttribute("class", "block hiddenBGColor");
target.src = "../icons/eyeClosed.png"
hideSelectedTab(id);
}
}
} else if (targetID == "hideAllBttn") {
doAllTabs(0)
} else if (targetID == "showAllBttn") {
doAllTabs(1);
}
});

View File

@@ -3,6 +3,7 @@ const searchBar = document.getElementById("searchBar");
const errHandler = document.getElementById("errorZone");
const listZone = document.getElementById("listZone");
const notFoundText = document.createTextNode("Search not found...");
const tabImg = browser.extension.getURL("icons/tab.png");
var oldElm = "";
var plusTag = ""
@@ -18,28 +19,39 @@ function logTabs(tabs) {
function createContainer(tab) {
var id = tab.id;
var spanTag = document.createElement("SPAN");
var spanTag = document.createElement("DIV");
var pTag = document.createElement("P");
var iconText = document.createTextNode(tab.title);
var centerTag = document.createElement("CENTER");
var closeImgTag = document.createElement("IMG");
var icoImgTag = document.createElement("IMG");
var hidnStImgTag = document.createElement("IMG");
var icoImgTag = document.createElement("IMG"); // Used to properly set bg
spanTag.setAttribute("tabID", tab.id);
spanTag.title = tab.title;
spanTag.id = "iconElm";
spanTag.className = "block";
closeImgTag.id = "closeBttn";
closeImgTag.className = "closeImg";
closeImgTag.src = "../icons/x.png";
icoImgTag.id = "faveIcon";
icoImgTag.className = "thumbImg";
icoImgTag.onerror = function() { icoImgTag.src = "../icons/tab.png"; }
icoImgTag.src = tab.favIconUrl;
hidnStImgTag.id = "hideTgglBttn"
hidnStImgTag.className= "hiderImg";
pTag.className = "pTagTitleText";
if (!tab.hidden) {
spanTag.className = "block";
hidnStImgTag.src = "../icons/eyeOpen.png";
} else {
spanTag.className = "block hiddenBGColor";
hidnStImgTag.src = "../icons/eyeClosed.png";
}
spanTag.style.backgroundImage = "url(" + tab.favIconUrl + ")";
icoImgTag.src = tab.favIconUrl;
icoImgTag.onerror = function() { spanTag.style.backgroundImage = "url(" + tabImg + ")"; }
centerTag.appendChild(icoImgTag);
spanTag.appendChild(closeImgTag);
spanTag.appendChild(centerTag);
spanTag.appendChild(iconText);
spanTag.appendChild(hidnStImgTag);
pTag.appendChild(iconText);
spanTag.appendChild(pTag);
listZone.appendChild(spanTag);
// Set oldElm so eventListeners.js has starting ref

View File

@@ -0,0 +1,60 @@
// tabsAction.discard(id);
function unhideSelectedTab(id) {
tabsAction.show(id).then(successMsg, errMsg);
}
function hideSelectedTab(id) {
tabsAction.hide(id).then(successMsg, errMsg);
}
function successMsg(ev) { console.log("Tab is hidden..." + ev); }
function errMsg(ev) {
var msg = "" + ev;
if (msg.includes("extensions.webextensions.tabhide.enabled")) {
var errText = document.createTextNode(msg);
listZone.style.display = "none";
errHandler.style.display = "block";
errHandler.appendChild(errText);
setTimeout(function () {
listZone.style.display = "block";
errHandler.style.display = "none";
clearNodes(errHandler);
}, 4000);
}
}
function doAllTabs(doType) {
// 0 == hide and 1 == unhide
tabsAction.query({currentWindow: true}).then((tabs) => {
var tabCollectionIDs = [];
for (var i = 0; i < tabs.length; i++) {
tabCollectionIDs.push(tabs[i].id);
}
if (doType == 0) {
hideSelectedTab(tabCollectionIDs);
} else {
unhideSelectedTab(tabCollectionIDs);
}
}, doType);
var imgs = document.querySelectorAll(".hiderImg");
if (doType == 0) {
for (var i = 0; i < imgs.length; i++) {
imgs[i].parentElement.setAttribute("class", "block hiddenBGColor");
imgs[i].src = "../icons/eyeClosed.png";
}
oldElm.querySelectorAll(".hiderImg")[0].src = "../icons/eyeOpen.png";
oldElm.setAttribute("class", "block block-focused");
} else {
for (var i = 0; i < imgs.length; i++) {
imgs[i].parentElement.setAttribute("class", "block");
imgs[i].src = "../icons/eyeOpen.png";
}
oldElm.setAttribute("class", "block block-focused");
}
}