TreeTabsMigration/sidebar.js

117 lines
4.2 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);
2018-05-22 02:11:29 +02:00
2017-11-12 22:00:40 +01:00
function Run() {
2018-07-03 20:36:38 +02:00
ShowStatusBar({show: true, spinner: true, message: "Starting up"});
2018-01-01 19:50:56 +01:00
chrome.runtime.sendMessage({command: "is_bg_ready"}, function(response) {
2018-05-22 02:11:29 +02:00
if (response == true) {
Initialize();
} else {
setTimeout(function() {
2018-01-01 19:50:56 +01:00
Run();
2018-05-22 02:11:29 +02:00
},100);
}
2018-01-01 19:50:56 +01:00
});
}
2018-05-22 02:11:29 +02:00
function Initialize() {
2018-07-03 20:36:38 +02:00
chrome.windows.getCurrent({populate: true}, function(window) {
tt.CurrentWindowId = window.id;
let tabs = window.tabs;
2018-05-22 02:11:29 +02:00
chrome.storage.local.get(null, function(storage) {
GetCurrentPreferences(storage);
ApplyTheme(GetCurrentTheme(storage));
if (opt.show_toolbar) {
RecreateToolbar(GetCurrentToolbar(storage));
SetToolbarEvents(false, true, true, "mousedown");
RestoreToolbarShelf();
RestoreToolbarSearchFilter();
}
2018-07-03 20:36:38 +02:00
chrome.runtime.sendMessage({command: "get_browser_tabs"}, function(bgtabs) {
chrome.runtime.sendMessage({command: "get_folders", windowId: tt.CurrentWindowId}, function(f) {
tt.folders = Object.assign({}, f);
chrome.runtime.sendMessage({command: "get_groups", windowId: tt.CurrentWindowId}, function(g) {
tt.groups = Object.assign({}, g);
2018-05-22 02:11:29 +02:00
// APPEND GROUPS
2018-07-03 20:36:38 +02:00
AppendGroups(tt.groups);
2018-05-22 02:11:29 +02:00
// APPEND FOLDERS
2018-07-03 20:36:38 +02:00
AppendFolders(tt.folders);
2018-05-22 02:11:29 +02:00
// APPEND TABS
let ti = 0;
let tc = tabs.length;
2018-07-03 20:36:38 +02:00
let ttTabs = [];
2018-05-22 02:11:29 +02:00
for (ti = 0; ti < tc; ti++) {
2018-07-03 20:36:38 +02:00
ttTabs.push(AppendTab({ tab: tabs[ti], Append: true, SkipSetActive: true, AdditionalClass: (bgtabs[tabs[ti].id].expand != "" ? bgtabs[tabs[ti].id].expand : undefined) }));
2018-05-22 02:11:29 +02:00
}
2018-07-03 20:36:38 +02:00
if (opt.skip_load == false) {
for (ti = 0; ti < tc; ti++) {
if (bgtabs[tabs[ti].id] && !tabs[ti].pinned) {
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(ttTabs[ti]);
}
2018-05-22 02:11:29 +02:00
}
}
}
2018-07-03 20:36:38 +02:00
// SET ACTIVE TAB FOR EACH GROUP, REARRENGE EVERYTHING AND START BROWSER LISTENERS
2018-05-22 02:11:29 +02:00
SetActiveTabInEachGroup();
RearrangeFolders(true);
2018-07-03 20:36:38 +02:00
RearrangeTreeTabs(bgtabs, true);
StartSidebarListeners();
2018-05-22 02:11:29 +02:00
SetMenu();
SetEvents();
SetManagerEvents();
HideMenus();
if (opt.switch_with_scroll) {
BindTabsSwitchingToMouseWheel("pin_list");
}
if (opt.syncro_tabbar_tabs_order || opt.syncro_tabbar_groups_tabs_order) {
RearrangeBrowserTabs();
}
RestorePinListRowSettings();
StartAutoSaveSession();
if (browserId == "V") {
VivaldiRefreshMediaIcons();
}
2018-07-03 20:36:38 +02:00
2018-05-22 02:11:29 +02:00
setTimeout(function() {
RefreshExpandStates();
RefreshCounters();
SetActiveTabInEachGroup();
if (browserId == "F" && opt.skip_load == false && storage.emergency_reload == undefined) {
RecheckFirefox();
}
}, 1000);
2018-07-03 20:36:38 +02:00
ShowStatusBar({show: true, spinner: false, message: "Ready.", hideTimeout: 2000});
2018-05-22 02:11:29 +02:00
setTimeout(function() {
UpdateData();
2018-07-03 20:36:38 +02:00
delete b;
2018-05-22 02:11:29 +02:00
delete DefaultToolbar;
delete DefaultTheme;
delete DefaultPreferences;
if (storage.emergency_reload != undefined) {
chrome.storage.local.remove("emergency_reload");
}
}, 5000);
if (browserId != "F") {
2018-07-03 20:36:38 +02:00
if (storage.windows_BAK1 && Object.keys(storage["windows_BAK1"]).length > 0 && document.getElementById("button_load_bak1") != null) { document.getElementById("button_load_bak1").classList.remove("disabled"); }
if (storage.windows_BAK2 && Object.keys(storage["windows_BAK2"]).length > 0 && document.getElementById("button_load_bak2") != null) { document.getElementById("button_load_bak2").classList.remove("disabled"); }
if (storage.windows_BAK3 && Object.keys(storage["windows_BAK3"]).length > 0 && document.getElementById("button_load_bak3") != null) { document.getElementById("button_load_bak3").classList.remove("disabled"); }
2018-05-22 02:11:29 +02:00
}
2017-11-20 18:14:07 +01:00
});
2017-11-12 22:00:40 +01:00
});
});
});
});
2017-11-20 18:14:07 +01:00
}