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-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() {
|
|
|
|
|
|
|
|
chrome.tabs.query({currentWindow: true}, function(tabs) {
|
|
|
|
CurrentWindowId = tabs[0].windowId;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-11-12 22:00:40 +01:00
|
|
|
chrome.runtime.sendMessage({command: "get_browser_tabs"}, function(response) {
|
2018-05-22 02:11:29 +02:00
|
|
|
let 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);
|
2018-05-22 02:11:29 +02:00
|
|
|
// APPEND GROUPS
|
|
|
|
AppendGroups(bggroups);
|
|
|
|
// APPEND FOLDERS
|
|
|
|
AppendFolders(bgfolders);
|
|
|
|
// APPEND TABS
|
|
|
|
let ti = 0;
|
|
|
|
let tc = tabs.length;
|
|
|
|
for (ti = 0; ti < tc; ti++) {
|
|
|
|
AppendTab(tabs[ti], false, false, false, true, false, true, false, true, false, 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(document.getElementById(tabs[ti].id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (ti = 0; ti < tc; ti++) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// SET ACTIVE TAB FOR EACH GROUP
|
|
|
|
SetActiveTabInEachGroup();
|
|
|
|
RearrangeTreeTabs(tabs, bgtabs, true);
|
|
|
|
RearrangeFolders(true);
|
|
|
|
StartChromeListeners();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
setTimeout(function() {
|
|
|
|
RefreshExpandStates();
|
|
|
|
RefreshCounters();
|
|
|
|
SetActiveTabInEachGroup();
|
|
|
|
if (browserId == "F" && opt.skip_load == false && storage.emergency_reload == undefined) {
|
|
|
|
RecheckFirefox();
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
setTimeout(function() {
|
|
|
|
UpdateData();
|
|
|
|
delete debug;
|
|
|
|
delete running;
|
|
|
|
delete schedule_save;
|
|
|
|
delete windows;
|
|
|
|
delete tabs;
|
|
|
|
delete tt_ids;
|
|
|
|
delete DefaultToolbar;
|
|
|
|
delete DefaultTheme;
|
|
|
|
delete DefaultPreferences;
|
|
|
|
if (storage.emergency_reload != undefined) {
|
|
|
|
chrome.storage.local.remove("emergency_reload");
|
|
|
|
}
|
|
|
|
}, 5000);
|
|
|
|
if (browserId != "F") {
|
|
|
|
if (Object.keys(storage["windows_BAK1"]).length > 0 && document.getElementById("button_load_bak1") != null) { document.getElementById("button_load_bak1").classList.remove("disabled"); }
|
|
|
|
if (Object.keys(storage["windows_BAK2"]).length > 0 && document.getElementById("button_load_bak2") != null) { document.getElementById("button_load_bak2").classList.remove("disabled"); }
|
|
|
|
if (Object.keys(storage["windows_BAK3"]).length > 0 && document.getElementById("button_load_bak3") != null) { document.getElementById("button_load_bak3").classList.remove("disabled"); }
|
|
|
|
}
|
2017-11-20 18:14:07 +01:00
|
|
|
});
|
2017-11-12 22:00:40 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-11-20 18:14:07 +01:00
|
|
|
}
|