TreeTabsMigration/sidebar.js

137 lines
4.8 KiB
JavaScript
Raw Normal View History

2017-11-12 22:00:40 +01:00
// Copyright (c) 2017 kroppy. All rights reserved.
// Use of this source code is governed by a Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) license
// that can be found at https://creativecommons.org/licenses/by-nc-nd/4.0/
2017-07-26 22:23:39 +02:00
2017-11-12 22:00:40 +01:00
document.addEventListener("DOMContentLoaded", Run(), false);
function Loadi18n() {
// toolbar labels
2018-03-13 14:39:34 +01:00
document.querySelectorAll(".button").forEach(function(s){
s.title = chrome.i18n.getMessage(s.id);
2017-11-12 22:00:40 +01:00
});
2018-03-13 14:39:34 +01:00
// menu labels and edit group dialog labels
document.querySelectorAll(".menu_item, .edit_dialog_button").forEach(function(s){
s.textContent = chrome.i18n.getMessage(s.id);
2017-11-12 22:00:40 +01:00
});
}
function RestorePinListRowSettings() {
2018-03-13 14:39:34 +01:00
plist = document.getElementById("pin_list");
2017-11-12 22:00:40 +01:00
if (opt.pin_list_multi_row) {
2018-03-13 14:39:34 +01:00
plist.style.whiteSpace = "normal";
plist.style.overflowX = "hidden";
2017-11-12 22:00:40 +01:00
} else {
2018-03-13 14:39:34 +01:00
plist.style.whiteSpace = "";
plist.style.overflowX = "";
2017-11-12 22:00:40 +01:00
}
RefreshGUI();
}
function Run() {
2018-01-01 19:50:56 +01:00
chrome.runtime.sendMessage({command: "is_bg_ready"}, function(response) {
setTimeout(function() {
if (response == true) {
Load();
} else {
Run();
}
},200);
});
}
function Load() {
2017-11-12 22:00:40 +01:00
chrome.windows.getCurrent({populate: false}, function(window) {
CurrentWindowId = window.id;
2018-01-01 19:50:56 +01:00
chrome.runtime.sendMessage({command: "get_preferences"}, function(response) {
opt = Object.assign({}, response);
2017-11-12 22:00:40 +01:00
chrome.runtime.sendMessage({command: "get_browser_tabs"}, function(response) {
bgtabs = Object.assign({}, response);
2018-01-01 19:50:56 +01:00
chrome.runtime.sendMessage({command: "get_folders", windowId: CurrentWindowId}, function(response) {
bgfolders = Object.assign({}, response);
chrome.runtime.sendMessage({command: "get_groups", windowId: CurrentWindowId}, function(response) {
bggroups = Object.assign({}, response);
chrome.runtime.sendMessage({command: "get_theme", windowId: CurrentWindowId}, function(response) {
ApplyTheme(response);
Initialize();
});
2017-11-20 18:14:07 +01:00
});
2017-11-12 22:00:40 +01:00
});
});
});
});
2017-11-20 18:14:07 +01:00
}
2017-11-12 22:00:40 +01:00
function Initialize() {
2017-11-20 18:14:07 +01:00
// APPEND GROUPS
2018-01-01 19:50:56 +01:00
AppendGroups(bggroups);
2017-11-20 18:14:07 +01:00
chrome.tabs.query({currentWindow: true}, function(tabs) {
2018-01-01 19:50:56 +01:00
// APPEND FOLDERS
AppendFolders(bgfolders);
2017-11-20 18:14:07 +01:00
// APPEND TABS
2017-11-12 22:00:40 +01:00
let tc = tabs.length;
for (var ti = 0; ti < tc; ti++) {
2018-03-13 14:39:34 +01:00
AppendTab(tabs[ti], false, false, false, true, false, true, false, true, false, false);
2017-11-12 22:00:40 +01:00
}
for (var ti = 0; ti < tc; ti++) {
if (bgtabs[tabs[ti].id] && !tabs[ti].pinned) {
2018-03-13 14:39:34 +01:00
let TabParent = document.getElementById("ct"+bgtabs[tabs[ti].id].parent) ;
if (TabParent != null && document.querySelector("[id='"+tabs[ti].id+"'] #ct"+bgtabs[tabs[ti].id].parent) == null) {
TabParent.appendChild(document.getElementById(tabs[ti].id));
2017-07-26 22:23:39 +02:00
}
2017-11-12 22:00:40 +01:00
}
}
for (var ti = 0; ti < tc; ti++) {
2018-03-13 14:39:34 +01:00
if (bgtabs[tabs[ti].id] && !tabs[ti].pinned && bgtabs[tabs[ti].id].expand != "") {
document.getElementById(tabs[ti].id).classList.add(bgtabs[tabs[ti].id].expand);
2017-11-12 22:00:40 +01:00
}
}
2018-01-01 19:50:56 +01:00
// SET ACTIVE TAB FOR EACH GROUP
2018-03-13 14:39:34 +01:00
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
chrome.runtime.sendMessage({command: "get_active_group", windowId: CurrentWindowId}, function(response) {
for (var group in bggroups) {
if (response && tabs[0].pinned && response == group) {
SetActiveTab(tabs[0].id);
continue;
}
let activeInGroup = document.querySelector("#"+group+" [id='"+bggroups[group].active_tab+"']");
if (activeInGroup != null) {
activeInGroup.classList.add("active_tab");
}
}
if (response) {
SetActiveGroup(response, true, true);
} else {
SetActiveGroup("tab_list", true, true);
}
});
2017-07-26 22:23:39 +02:00
});
2017-11-12 22:00:40 +01:00
RearrangeTreeTabs(tabs, bgtabs, true);
2018-01-01 19:50:56 +01:00
RearrangeFolders(true);
2017-11-12 22:00:40 +01:00
StartChromeListeners();
SetMenu();
2018-03-13 14:39:34 +01:00
SetEvents();
HideMenus();
if (opt.switch_with_scroll) {
BindTabsSwitchingToMouseWheel("pin_list");
}
2018-01-01 19:50:56 +01:00
if (opt.syncro_tabbar_tabs_order || opt.syncro_tabbar_groups_tabs_order) {
RearrangeBrowserTabs();
}
2017-11-12 22:00:40 +01:00
RestorePinListRowSettings();
2018-01-01 19:50:56 +01:00
if (browserId == "V") {
VivaldiRefreshMediaIcons();
}
2017-11-20 18:14:07 +01:00
setTimeout(function() {
RefreshExpandStates();
2018-01-01 19:50:56 +01:00
RefreshCounters();
2018-03-13 14:39:34 +01:00
}, 3000);
2017-11-12 22:00:40 +01:00
setTimeout(function() {
UpdateData();
delete bgtabs;
delete theme;
2017-11-20 18:14:07 +01:00
}, 5000);
2018-01-01 19:50:56 +01:00
if (browserId != "F") {
chrome.storage.local.get(null, function(items) {
2018-03-13 14:39:34 +01:00
if (Object.keys(items["windows_BAK1"]).length > 0 && document.getElementById("button_load_bak1") != null) { document.getElementById("button_load_bak1").classList.remove("disabled"); }
if (Object.keys(items["windows_BAK2"]).length > 0 && document.getElementById("button_load_bak2") != null) { document.getElementById("button_load_bak2").classList.remove("disabled"); }
if (Object.keys(items["windows_BAK3"]).length > 0 && document.getElementById("button_load_bak3") != null) { document.getElementById("button_load_bak3").classList.remove("disabled"); }
2017-11-12 22:00:40 +01:00
});
}
});
2017-07-26 22:23:39 +02:00
}