2018-10-13 22:08:32 +00:00
|
|
|
document.getElementById("searchBar").onkeypress = function () {
|
|
|
|
searchTabs();
|
|
|
|
}
|
|
|
|
|
2018-05-13 22:27:16 +00:00
|
|
|
// Set click events for tab blocks
|
2018-04-20 06:06:32 +00:00
|
|
|
document.addEventListener("click", (e) => {
|
2019-02-10 10:15:12 +00:00
|
|
|
var target = (!e.target.className.includes("pTagTitleText")) ? e.target : e.target.parentElement;
|
2018-05-06 01:02:50 +00:00
|
|
|
var targetID = target.id;
|
2018-04-20 06:06:32 +00:00
|
|
|
var parentElm = target.parentElement;
|
2018-05-06 01:02:50 +00:00
|
|
|
var id = 0;
|
2018-04-20 06:06:32 +00:00
|
|
|
|
|
|
|
if (targetID == "closeBttn") {
|
2018-10-13 22:08:32 +00:00
|
|
|
closeBttnAction(target, targetID, parentElm, id);
|
2018-05-20 23:20:23 +00:00
|
|
|
} else if (targetID == "iconElm") {
|
2018-10-13 22:08:32 +00:00
|
|
|
setNewTabAction(target, targetID, parentElm, id);
|
2018-05-06 01:02:50 +00:00
|
|
|
} else if (targetID == "goTop") {
|
|
|
|
window.scrollTo(0,0);
|
|
|
|
} else if (targetID == "goBottom") {
|
2018-05-20 23:20:23 +00:00
|
|
|
window.scrollTo(0, document.body.scrollHeight);
|
2018-05-06 01:02:50 +00:00
|
|
|
} else if (targetID == "goToTab") {
|
2019-02-10 10:15:12 +00:00
|
|
|
scrollToView(200);
|
2018-05-13 22:27:16 +00:00
|
|
|
} else if (targetID == "newTab") {
|
|
|
|
createTab();
|
2018-05-20 23:20:23 +00:00
|
|
|
} else if (targetID == "hideTgglBttn") {
|
2018-10-13 22:08:32 +00:00
|
|
|
hideSelectedTabAction(target, targetID, parentElm, id);
|
2018-05-20 23:20:23 +00:00
|
|
|
} else if (targetID == "hideAllBttn") {
|
2018-10-13 22:08:32 +00:00
|
|
|
showHideTabsAction(0)
|
2018-05-20 23:20:23 +00:00
|
|
|
} else if (targetID == "showAllBttn") {
|
2018-10-13 22:08:32 +00:00
|
|
|
showHideTabsAction(1);
|
2018-05-21 09:48:34 +00:00
|
|
|
} else if (targetID == "searchMode") {
|
2018-10-13 22:08:32 +00:00
|
|
|
setSearchModeAction(target, targetID, parentElm, id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-02-10 10:15:12 +00:00
|
|
|
function closeBttnAction(target, targetID, parentElm, id) {
|
2018-10-13 22:08:32 +00:00
|
|
|
if (parentElm == oldElm) {
|
|
|
|
var index = Array.from(parentElm.parentElement.children).indexOf(parentElm);
|
|
|
|
(index - 1 < 0) ? index++ : index-- ; // Check what index to chose
|
|
|
|
var newElm = parentElm.parentElement.children[index];
|
|
|
|
|
|
|
|
id = parseInt(newElm.getAttribute("tabID"));
|
|
|
|
browser.tabs.update(id, { active: true });
|
|
|
|
setOldElm(newElm);
|
|
|
|
}
|
|
|
|
|
|
|
|
id = parseInt(parentElm.getAttribute("tabID"));
|
|
|
|
browser.tabs.remove(id);
|
|
|
|
|
|
|
|
parentElm.parentElement.removeChild(parentElm);
|
|
|
|
}
|
|
|
|
|
2019-02-10 10:15:12 +00:00
|
|
|
function setNewTabAction(target, targetID, parentElm, id) {
|
2018-10-13 22:08:32 +00:00
|
|
|
id = parseInt(target.getAttribute("tabID"));
|
|
|
|
tabsAction.get(id).then((tab) => {
|
|
|
|
browser.windows.update(tab.windowId, {focused: true});
|
|
|
|
browser.tabs.update(id, { active: true });
|
|
|
|
},id);
|
|
|
|
|
|
|
|
setOldElm(target);
|
|
|
|
}
|
|
|
|
|
2019-02-10 10:15:12 +00:00
|
|
|
function hideSelectedTabAction(target, targetID, parentElm, id) {
|
2018-10-13 22:08:32 +00:00
|
|
|
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);
|
2018-05-21 09:48:34 +00:00
|
|
|
} else {
|
2018-10-13 22:08:32 +00:00
|
|
|
parentElm.setAttribute("class", "block hiddenBGColor");
|
|
|
|
target.src = "../icons/eyeClosed.png"
|
|
|
|
hideSelectedTab(id);
|
2018-05-21 09:48:34 +00:00
|
|
|
}
|
2018-04-20 06:06:32 +00:00
|
|
|
}
|
2018-10-13 22:08:32 +00:00
|
|
|
}
|
|
|
|
|
2019-02-10 10:15:12 +00:00
|
|
|
function setSearchModeAction(target, targetID, parentElm, id) {
|
2018-10-13 22:08:32 +00:00
|
|
|
var currentMode = target.getAttribute("searchwindowsmode");
|
|
|
|
if (currentMode == "true") {
|
|
|
|
// In generateview
|
|
|
|
setSearchMode(target, "curent window", "window", false);
|
|
|
|
} else {
|
|
|
|
setSearchMode(target, "all windows", "windows", true);
|
|
|
|
}
|
|
|
|
clearNodes(listZone);
|
|
|
|
}
|
2018-04-20 06:06:32 +00:00
|
|
|
|
2018-05-21 09:48:34 +00:00
|
|
|
function setOldElm(target) {
|
|
|
|
target.querySelectorAll(".hiderImg")[0].src = "../icons/eyeOpen.png";
|
|
|
|
oldElm.setAttribute("class", "block");
|
|
|
|
oldElm = target;
|
|
|
|
target.setAttribute("class", "block block-focused");
|
|
|
|
}
|
2019-02-10 10:15:12 +00:00
|
|
|
|
|
|
|
function scrollToView(time) {
|
|
|
|
setTimeout(function () {
|
|
|
|
// Go to selected and 100px up
|
|
|
|
oldElm.scrollIntoView();
|
|
|
|
window.scrollBy(0, -100);
|
|
|
|
}, time);
|
|
|
|
}
|