Commit cae1943b authored by karol@jagiello.it's avatar karol@jagiello.it
Browse files

1.9.1

parent 8ee99621
This diff is collapsed.
......@@ -182,6 +182,10 @@ function StartBackgroundListeners() {
sendResponse(b.bg_running);
return;
}
if (message.command == "is_bg_safe_mode") {
sendResponse(b.safe_mode);
return;
}
if (message.command == "reload") {
window.location.reload();
return;
......@@ -309,6 +313,32 @@ function StartBackgroundListeners() {
b.schedule_save++;
return;
}
if (message.command == "all_tabs_exist") {
let yes = true;
for (let Win in message.windows) {
for (let Tab in message.windows[Win].tabs) {
if (b.tabs[message.windows[Win].tabs[Tab].id] == undefined) {
yes = false;
}
}
}
sendResponse(yes);
return;
}
if (message.command == "does_tabs_match") {
let match = true;
for (let Win in message.windows) {
for (let Tab in message.windows[Win].tabs) {
if (b.tabs[message.windows[Win].tabs[Tab].id] != undefined) {
if (message.windows[Win].tabs[Tab].parent !== b.tabs[message.windows[Win].tabs[Tab].id].parent) {
match = false;
}
}
}
}
sendResponse(match);
return;
}
if (message.command == "discard_tab") {
DiscardTab(message.tabId);
return;
......@@ -547,14 +577,6 @@ function SafeModeCheck() {
}
});
}
if (browserId == "O") {
chrome.runtime.sendMessage({command: "reload_sidebar"});
window.location.reload();
}
if (browserId == "V") {
chrome.runtime.sendMessage({command: "reload_sidebar"});
window.location.reload();
}
}
}, 2000);
}
......
// VIVALDI
function VivaldiLegacyAddWindowData(win) {
b.windows[win.id] = { activeTabId: 0, group_bar: opt.groups_toolbar_default, search_filter: "url", active_shelf: "", active_group: "tab_list", groups: { tab_list: { id: "tab_list", index: 0, active_tab: 0, prev_active_tab: 0, name: labels.ungrouped_group, font: "" } }, folders: {} };
}
function VivaldiLegacyHashURL(tab) {
if (b.tabs[tab.id] == undefined) { b.tabs[tab.id] = { hash: 0, parent: tab.pinned ? "pin_list" : (b.windows[tab.windowId] ? b.windows[tab.windowId].active_group : "tab_list"), index: (Object.keys(b.tabs).length + 1), expand: "n" }; }
let hash = 0;
for (let charIndex = 0; charIndex < tab.url.length; charIndex++) {
hash += tab.url.charCodeAt(charIndex);
}
b.tabs[tab.id].hash = hash;
}
function VivaldiStart() {
chrome.windows.getAll({ windowTypes: ['normal'], populate: true }, function(w) {
chrome.storage.local.get(null, function(storage) {
// LOAD PREFERENCES
Preferences_GetCurrentPreferences(storage);
// LEGACY START TO CONVERT DATA
if ((storage.data_version == undefined && storage.tabs != undefined && storage.tabs.length) || (storage.data_version != undefined && storage.data_version < 2)) {
b.safe_mode = true;
let refTabs = {};
let refWins = {};
let tabs_matched = 0;
let LoadedWindows = storage.windows ? storage.windows : [];
let LoadedTabs = storage.tabs ? storage.tabs : [];
let CurrentTabsCount = 0;
for (let win of w) {
CurrentTabsCount += win.tabs.length;
}
for (let win of w) {
let url1 = win.tabs[0].url;
let url2 = win.tabs[win.tabs.length - 1].url;
VivaldiLegacyAddWindowData(win);
if (opt.skip_load == false) {
for (let loadedWin of LoadedWindows) {
if ((loadedWin.url1 == url1 || loadedWin.url2 == url2) && refWins[loadedWin.id] == undefined) {
refWins[loadedWin.id] = win.id;
if (loadedWin.group_bar) b.windows[win.id].group_bar = loadedWin.group_bar;
if (loadedWin.search_filter) b.windows[win.id].search_filter = loadedWin.search_filter;
if (loadedWin.active_shelf) b.windows[win.id].active_shelf = loadedWin.active_shelf;
if (loadedWin.active_group) b.windows[win.id].active_group = loadedWin.active_group;
if (Object.keys(loadedWin.groups).length > 0) b.windows[win.id].groups = Object.assign({}, loadedWin.groups);
if (Object.keys(loadedWin.folders).length > 0) b.windows[win.id].folders = Object.assign({}, loadedWin.folders);
break;
}
}
}
}
for (let win of w) {
for (let tab of win.tabs) {
VivaldiLegacyHashURL(tab);
if (tab.active) b.windows[win.id].activeTabId = tab.id;
}
}
if (opt.skip_load == false && LoadedTabs.length > 0) {
for (let win of w) {
for (tab of win.tabs) {
for (let loadedTab of LoadedTabs) {
if (loadedTab.hash == b.tabs[tab.id].hash && refTabs[loadedTab.id] == undefined) {
refTabs[loadedTab.id] = tab.id;
if (loadedTab.parent) b.tabs[tab.id].parent = loadedTab.parent;
if (loadedTab.index) b.tabs[tab.id].index = loadedTab.index;
if (loadedTab.expand) b.tabs[tab.id].expand = loadedTab.expand;
tabs_matched++;
break;
}
}
}
}
for (let tabId in b.tabs) {
if (refTabs[b.tabs[tabId].parent] != undefined) b.tabs[tabId].parent = refTabs[b.tabs[tabId].parent];
}
for (let windowId in b.windows) {
for (let group in b.windows[windowId].groups) {
if (refTabs[b.windows[windowId].groups[group].active_tab]) b.windows[windowId].groups[group].active_tab = refTabs[b.windows[windowId].groups[group].active_tab];
if (refTabs[b.windows[windowId].groups[group].prev_active_tab]) b.windows[windowId].groups[group].prev_active_tab = refTabs[b.windows[windowId].groups[group].prev_active_tab];
}
}
}
for (let win of w) {
if (b.windows[win.id]) b.windows[win.id].ttid = JSON.parse(win.extData).ext_id;
for (let tab of win.tabs) {
if (b.tabs[tab.id]) b.tabs[tab.id].ttid = JSON.parse(tab.extData).ext_id;
}
}
let Windows = {};
let Tabs = {};
for (let win of w) {
if (b.windows[win.id] != undefined && b.windows[win.id].ttid != undefined && b.windows[win.id].group_bar != undefined && b.windows[win.id].search_filter != undefined && b.windows[win.id].active_shelf != undefined && b.windows[win.id].active_group != undefined && b.windows[win.id].groups != undefined && b.windows[win.id].folders != undefined) {
Windows[b.windows[win.id].ttid] = { ttid: b.windows[win.id].ttid, group_bar: b.windows[win.id].group_bar, search_filter: b.windows[win.id].search_filter, active_shelf: b.windows[win.id].active_shelf, active_group: b.windows[win.id].active_group, groups: b.windows[win.id].groups, folders: b.windows[win.id].folders };
for (let groupId in b.windows[win.id].groups) {
if (b.tabs[b.windows[win.id].groups[groupId].active_tab]) Windows[b.windows[win.id].ttid].groups[groupId].active_tab = b.tabs[b.windows[win.id].groups[groupId].active_tab].ttid;
if (b.tabs[b.windows[win.id].groups[groupId].prev_active_tab]) Windows[b.windows[win.id].ttid].groups[groupId].prev_active_tab = b.tabs[b.windows[win.id].groups[groupId].prev_active_tab].ttid;
}
}
for (let tab of win.tabs) {
if (b.tabs[tab.id] != undefined && b.tabs[tab.id].ttid != undefined && b.tabs[tab.id].parent != undefined && b.tabs[tab.id].index != undefined && b.tabs[tab.id].expand != undefined) {
Tabs[b.tabs[tab.id].ttid] = { ttid: b.tabs[tab.id].ttid, parent: (b.tabs[b.tabs[tab.id].parent] ? b.tabs[b.tabs[tab.id].parent].ttid : b.tabs[tab.id].parent), index: b.tabs[tab.id].index, expand: b.tabs[tab.id].expand };
}
}
}
chrome.storage.local.set({ data_version: 2, windows: Windows, tabs: Tabs });
chrome.storage.local.remove("t_count");
chrome.storage.local.remove("w_count");
chrome.runtime.sendMessage({command: "reload_sidebar"});
window.location.reload();
}
if (storage.data_version == undefined || storage.data_version == 2) {
// load tabs and windows from storage
let refTabs = {};
......@@ -251,8 +147,18 @@ async function VivaldiAutoSaveData(BAK, LoopTimer) {
function VivaldiAddWindowData(win) {
let extData = JSON.parse(win.extData);
if (b.windows[win.id] == undefined) b.windows[win.id] = { ttid: (win.extData.match("ext_id") != null ? JSON.parse(win.extData).ext_id : win.index), activeTabId: 0, group_bar: opt.groups_toolbar_default, search_filter: "url", active_shelf: "", active_group: "tab_list", groups: { tab_list: { id: "tab_list", index: 0, active_tab: 0, prev_active_tab: 0, name: labels.ungrouped_group, font: "" } }, folders: {} };
let extData = win.extData.match("ext_id") != null ? JSON.parse(win.extData).ext_id : win.index;
if (b.windows[win.id] == undefined) b.windows[win.id] = { ttid: extData, activeTabId: 0, group_bar: opt.groups_toolbar_default, search_filter: "url", active_shelf: "", active_group: "tab_list", groups: { tab_list: { id: "tab_list", index: 0, active_tab: 0, prev_active_tab: 0, name: labels.ungrouped_group, font: "" } }, folders: {} };
if (extData == win.index) {
let retry = setInterval(function() {
chrome.windows.get(win.id, {populate: false}, function(retry_win) {
if (retry_win.extData.match("ext_id") != null) {
b.windows[retry_win.id].ttid = JSON.parse(retry_win.extData).ext_id;
clearInterval(retry);
}
});
}, 2000);
}
return b.windows[win.id].ttid;
}
......
......@@ -14,7 +14,8 @@
"19": "icons/16.png",
"16": "icons/16.png"
},
"permissions": [ "tabs", "sessions", "storage", "unlimitedStorage", "bookmarks", "tabHide" ],
"permissions": [ "<all_urls>", "tabs", "sessions", "storage", "unlimitedStorage", "bookmarks", "tabHide" ],
"sidebar_action": {
"default_icon": {
"16": "icons/16.png",
......@@ -28,25 +29,21 @@
"browser_action": {
"default_icon": "icons/24.png"
},
"commands": {
"_execute_browser_action": {
"suggested_key": { "default": "F1" },
"description": "toggle Tree Tabs"
},
"close_tree": {
"suggested_key": { "default": "Alt+W" },
"description": "close tree"
}
},
"applications": {
"gecko": {
"id": "TreeTabs@jagiello.it",
"strict_min_version": "63.0"
"strict_min_version": "57.0"
}
},
"options_ui": {
"page": "options/options.html",
"open_in_tab": true
},
"version": "1.9.0"
"commands": {
"close_tree": {
"suggested_key": { "default": "Alt+W" },
"description": "close tree"
}
},
"version": "1.9.1"
}
\ No newline at end of file
......@@ -375,8 +375,6 @@ function Manager_ImportMergeTabs(LoadedWindows) {
if (opt.debug) Utils_log("f: Manager_ImportMergeTabs");
Manager_ShowStatusBar({show: true, spinner: true, message: chrome.i18n.getMessage("status_bar_loaded_tree_structure")});
chrome.windows.getAll({windowTypes: ['normal'], populate: true}, function(CurrentWindows) {
let TotalTabsCount = 0;
let tabsMade = 0;
let New = {};
for (let CurrentWindow of CurrentWindows) { // Current Windows
for (let LoadedWindow of LoadedWindows) { // Loaded Windows
......@@ -410,7 +408,6 @@ function Manager_ImportMergeTabs(LoadedWindows) {
}
}
for (let LoadedWindow of LoadedWindows) { // CONVERT ARRAY TABS TO OBJECTS, FOR MISSING WINDOWS
TotalTabsCount += LoadedWindow.tabs.length;
if (New[LoadedWindow.id] == undefined) {
New[LoadedWindow.id] = Object.assign({}, LoadedWindow);
let NewTabs = {};
......@@ -423,7 +420,6 @@ function Manager_ImportMergeTabs(LoadedWindows) {
for (let windowId in New) { // Loaded Windows
if (New[windowId].oldId == undefined) { // missing window, lets make one
let FirstTabId = Object.keys(New[windowId].tabs)[0];
let tabsMade = 0;
let window_params;
if (browserId == "F") {
if ((New[windowId].tabs[FirstTabId].url).startsWith("about")) {
......@@ -441,10 +437,7 @@ function Manager_ImportMergeTabs(LoadedWindows) {
New[windowId].oldId = New[windowId].id;
New[windowId].id = new_window.id;
if (new_window.tabs[0]) {
tabsMade++;
New[windowId].tabs[FirstTabId].oldId = New[windowId].tabs[FirstTabId].id;
New[windowId].tabs[FirstTabId].id = new_window.tabs[0].id;
if (New[windowId].tabs[FirstTabId].parent == "pin_list") chrome.tabs.update(new_window.tabs[0].id, {pinned: true});
......@@ -462,12 +455,10 @@ function Manager_ImportMergeTabs(LoadedWindows) {
params = {active: false, windowId: new_window.id, url: New[windowId].tabs[Tab].url};
}
chrome.tabs.create(params, function(new_tab) {
tabsMade++;
if (new_tab) {
New[windowId].tabs[Tab].oldId = New[windowId].tabs[Tab].id;
New[windowId].tabs[Tab].id = new_tab.id;
if (New[windowId].tabs[Tab].parent == "pin_list") chrome.tabs.update(new_tab.id, {pinned: true});
if (browserId == "F" && New[windowId].tabs[Tab].favicon > 0) browser.sessions.setTabValue(new_tab.id, "CachedFaviconUrl", New[windowId].favicons[New[windowId].tabs[Tab].favicon]);
}
});
......@@ -503,17 +494,13 @@ function Manager_ImportMergeTabs(LoadedWindows) {
params = {active: false, windowId: New[windowId].id, url: New[windowId].tabs[Tab].url};
}
chrome.tabs.create(params, function(new_tab) {
tabsMade++;
if (new_tab) {
New[windowId].tabs[Tab].oldId = New[windowId].tabs[Tab].id;
New[windowId].tabs[Tab].id = new_tab.id;
if (New[windowId].tabs[Tab].parent == "pin_list") chrome.tabs.update(new_tab.id, {pinned: true});
if (browserId == "F" && New[windowId].tabs[Tab].favicon > 0) browser.sessions.setTabValue(new_tab.id, "CachedFaviconUrl", New[windowId].favicons[New[windowId].tabs[Tab].favicon]);
}
});
} else {
tabsMade++;
}
}
});
......@@ -522,28 +509,32 @@ function Manager_ImportMergeTabs(LoadedWindows) {
}
let STOP = 0;
let WaitForFinish = setInterval(function() {
if (STOP > 10) clearInterval(WaitForFinish); STOP++;
if (tabsMade == TotalTabsCount) {
setTimeout(function() {
for (let windowId in New) {
for (let Tab in New[windowId].tabs) {
if (New[windowId].tabs[New[windowId].tabs[Tab].parent]) {
New[windowId].tabs[Tab].parent = New[windowId].tabs[New[windowId].tabs[Tab].parent].id;
if (STOP > 60) clearInterval(WaitForFinish); STOP++; // stop after 5 minutes
chrome.runtime.sendMessage({command: "all_tabs_exist", windows: New}, function(exist) {
if (exist == true) {
chrome.runtime.sendMessage({command: "does_tabs_match", windows: New}, function(match) {
if (match == false) {
for (let windowId in New) {
for (let Tab in New[windowId].tabs) {
if (New[windowId].tabs[New[windowId].tabs[Tab].parent]) {
New[windowId].tabs[Tab].parent = New[windowId].tabs[New[windowId].tabs[Tab].parent].id;
}
}
for (let Tab in New[windowId].tabs) {
chrome.runtime.sendMessage({command: "update_tab", tabId: New[windowId].tabs[Tab].id, tab: {index: New[windowId].tabs[Tab].index, expand: New[windowId].tabs[Tab].expand, parent: New[windowId].tabs[Tab].parent}});
if (browserId != "O" && browserId != "F") setTimeout(function() {chrome.runtime.sendMessage({command: "discard_tab", tabId: New[windowId].tabs[Tab].id});}, 5000);
}
if (New[windowId].id == tt.CurrentWindowId) {
Manager_RecreateTreeStructure(New[windowId].groups, New[windowId].folders, New[windowId].tabs);
} else {
chrome.runtime.sendMessage({command: "remote_update", groups: New[windowId].groups, folders: New[windowId].folders, tabs: New[windowId].tabs, windowId: New[windowId].id});
}
STOP = 61;
}
}
for (let Tab in New[windowId].tabs) {
chrome.runtime.sendMessage({command: "update_tab", tabId: New[windowId].tabs[Tab].id, tab: {index: New[windowId].tabs[Tab].index, expand: New[windowId].tabs[Tab].expand, parent: New[windowId].tabs[Tab].parent}});
if (browserId != "O" && browserId != "F") chrome.runtime.sendMessage({command: "discard_tab", tabId: New[windowId].tabs[Tab].id});
}
if (New[windowId].id == tt.CurrentWindowId) {
Manager_RecreateTreeStructure(New[windowId].groups, New[windowId].folders, New[windowId].tabs);
} else {
chrome.runtime.sendMessage({command: "remote_update", groups: New[windowId].groups, folders: New[windowId].folders, tabs: New[windowId].tabs, windowId: New[windowId].id});
}
}
}, 3000);
STOP = 11;
}
});
}
});
}, 3000);
});
}
......@@ -565,24 +556,24 @@ function Manager_RecreateSession(LoadedWindows) {
chrome.windows.create(window_params, function(new_window) {
chrome.runtime.sendMessage({command: "save_groups", windowId: new_window.id, groups: LoadedWindow.groups});
chrome.runtime.sendMessage({command: "save_folders", windowId: new_window.id, folders: LoadedWindow.folders});
NewTabs[LoadedWindow.tabs[0].id] = {id: LoadedWindow.tabs[0].id, newId: new_window.tabs[0].id, expand: LoadedWindow.tabs[0].expand, favicon: LoadedWindow.tabs[0].favicon, index: LoadedWindow.tabs[0].index, parent: LoadedWindow.tabs[0].parent, title: LoadedWindow.tabs[0].title};
NewTabs[LoadedWindow.tabs[0].id] = {id: new_window.tabs[0].id, expand: LoadedWindow.tabs[0].expand, favicon: LoadedWindow.tabs[0].favicon, index: LoadedWindow.tabs[0].index, parent: LoadedWindow.tabs[0].parent, title: LoadedWindow.tabs[0].title};
if (browserId == "F" && LoadedWindow.tabs[0].favicon > 0) browser.sessions.setTabValue(new_window.tabs[0].id, "CachedFaviconUrl", LoadedWindow.favicons[LoadedWindow.tabs[0].favicon]);
for (let Tab of LoadedWindow.tabs) {
if (Tab.id != LoadedWindow.tabs[0].id) { // skip first tab
let params;
if (browserId == "F") {
if ((Tab.url).startsWith("about")) {
params = {active: false, windowId: tt.CurrentWindowId};
params = {active: false, windowId: new_window.id};
} else {
params = {active: false, windowId: tt.CurrentWindowId, url: Tab.url, discarded: true, title: Tab.title};
params = {active: false, windowId: new_window.id, url: Tab.url, discarded: true, title: Tab.title};
}
} else {
params = {active: false, windowId: new_window.id, url: Tab.url};
}
chrome.tabs.create(params, function(new_tab) {
NewTabs[Tab.id] = {id: Tab.id, newId: 0, favicon: Tab.favicon, index: Tab.index, parent: Tab.parent, title: Tab.title, expand: Tab.expand};
NewTabs[Tab.id] = {id: 0, favicon: Tab.favicon, index: Tab.index, parent: Tab.parent, title: Tab.title, expand: Tab.expand};
if (new_tab) {
NewTabs[Tab.id].newId = new_tab.id;
NewTabs[Tab.id].id = new_tab.id;
if (browserId == "F" && Tab.favicon > 0) browser.sessions.setTabValue(new_tab.id, "CachedFaviconUrl", LoadedWindow.favicons[Tab.favicon]);
}
});
......@@ -590,23 +581,26 @@ function Manager_RecreateSession(LoadedWindows) {
}
let STOP = 0;
let WaitForFinish = setInterval(function() {
if (STOP > 10) clearInterval(WaitForFinish); STOP++;
if (STOP > 60) clearInterval(WaitForFinish); STOP++; // stop after 5 minutes
if (Object.keys(NewTabs).length == LoadedWindow.tabs.length) {
for (let tabId in NewTabs) {
if (NewTabs[NewTabs[tabId].parent] != undefined) NewTabs[tabId].parent = NewTabs[NewTabs[tabId].parent].newId;
if (NewTabs[tabId].parent == "pin_list") chrome.tabs.update(parseInt(NewTabs[tabId].newId), {pinned: true});
if (browserId != "O" && browserId != "F") chrome.runtime.sendMessage({command: "discard_tab", tabId: parseInt(NewTabs[tabId].newId)});
}
for (let tabId in NewTabs) {
chrome.runtime.sendMessage({command: "update_tab", tabId: parseInt(NewTabs[tabId].newId), tab: {index: NewTabs[tabId].index, expand: NewTabs[tabId].expand, parent: NewTabs[tabId].parent}});
}
chrome.runtime.sendMessage({command: "sidebar_started", windowId: new_window.id}, function(response) {
if (response) {
chrome.runtime.sendMessage({command: "remote_update", groups: LoadedWindow.groups, folders: LoadedWindow.folders, tabs: NewTabs, windowId: new_window.id});
STOP = 11;
setTimeout(function() {
for (let Tab in NewTabs) {
if (NewTabs[NewTabs[Tab].parent] != undefined) NewTabs[Tab].parent = NewTabs[NewTabs[Tab].parent].id;
if (NewTabs[Tab].parent == "pin_list") chrome.tabs.update(NewTabs[Tab].id, {pinned: true});
if (browserId != "O" && browserId != "F") setTimeout(function() {chrome.runtime.sendMessage({command: "discard_tab", tabId: NewTabs[Tab].id});}, 5000);
}
});
STOP = 7;
for (let Tab in NewTabs) {
chrome.runtime.sendMessage({command: "update_tab", tabId: parseInt(NewTabs[Tab].id), tab: {index: NewTabs[Tab].index, expand: NewTabs[Tab].expand, parent: NewTabs[Tab].parent}});
}
chrome.runtime.sendMessage({command: "sidebar_started", windowId: new_window.id}, function(response) {
if (response) {
chrome.runtime.sendMessage({command: "remote_update", groups: LoadedWindow.groups, folders: LoadedWindow.folders, tabs: NewTabs, windowId: new_window.id}, function(response) {
// if (response)
});
}
});
STOP = 61;
}, 5000);
}
}, 5000);
});
......@@ -614,14 +608,13 @@ function Manager_RecreateSession(LoadedWindows) {
}
function Manager_RecreateGroup(LoadedGroup) {
if (opt.debug) Utils_log("f: Manager_RecreateGroup");
let NewGroupId = Groups_AddNewGroup(LoadedGroup.group.name, LoadedGroup.group.font);
let NewFolders = {};
let RefTabs = {};
// let RefTabs = {};
let NewTabs = {};
let LastTabId = "NO_TAB_YET";
// let LastTabId = "NO_TAB_YET";
if (Object.keys(LoadedGroup.folders).length > 0) {
for (var folder in LoadedGroup.folders) {
let newId = Folders_AddNewFolder({ParentId: NewGroupId, Name: LoadedGroup.folders[folder].name, ExpandState: LoadedGroup.folders[folder].expand});
......@@ -651,42 +644,45 @@ function Manager_RecreateGroup(LoadedGroup) {
params = {active: false, windowId: tt.CurrentWindowId, url: Tab.url};
}
chrome.tabs.create(params, function(new_tab) {
NewTabs[Tab.id] = {id: new_tab.id, favicon: Tab.favicon, index: Tab.index, parent: Tab.parent, title: Tab.title, expand: Tab.expand};
if (new_tab) {
NewTabs[Tab.id].id = new_tab.id;
if (browserId == "F" && Tab.favicon > 0) browser.sessions.setTabValue(new_tab.id, "CachedFaviconUrl", LoadedGroup.favicons[Tab.favicon]);
NewTabs[new_tab.id] = {id: new_tab.id, favicon: Tab.favicon, index: Tab.index, parent: Tab.parent, title: Tab.title, expand: Tab.expand};
RefTabs[Tab.id] = new_tab.id;
if (browserId != "O" && browserId != "F") chrome.runtime.sendMessage({command: "discard_tab", tabId: new_tab.id});
LastTabId = new_tab.id;
} else {
RefTabs[Tab.id] = "failed: "+Tab.id;
if (browserId != "O" && browserId != "F") setTimeout(function() {chrome.runtime.sendMessage({command: "discard_tab", tabId: new_tab.id});}, 5000);
// LastTabId = new_tab.id;
}
// else {
// RefTabs[Tab.id] = "failed: "+Tab.id;
// }
});
}
}
let STOP = 0;
let WaitForFinish = setInterval(function() {
if (STOP > 600) clearInterval(WaitForFinish); STOP++;// just stop after 10 minutes
if (STOP > 300) clearInterval(WaitForFinish); STOP++;// just stop after 5 minutes
if (document.getElementById("°" + NewGroupId) != null) {
if (Object.keys(LoadedGroup.folders).length > 0 && LoadedGroup.tabs.length == 0) {
Manager_RecreateTreeStructure({}, NewFolders, {});
STOP = 601;
STOP = 301;
}
if (LoadedGroup.tabs.length > 0 && Object.keys(RefTabs).length == LoadedGroup.tabs.length && document.getElementById(LastTabId) != null) {
for (let tabId in NewTabs) {
if (RefTabs[NewTabs[tabId].parent] != undefined) {
NewTabs[tabId].parent = RefTabs[NewTabs[tabId].parent];
} else {
if ((NewTabs[tabId].parent).startsWith("f_") && LoadedGroup.folders[NewTabs[tabId].parent]) {
NewTabs[tabId].parent = LoadedGroup.folders[NewTabs[tabId].parent].newId;
if (LoadedGroup.tabs.length > 0 && Object.keys(NewTabs).length == LoadedGroup.tabs.length /* && document.getElementById(LastTabId) != null */) {
setTimeout(function() {
for (let tabId in NewTabs) {
if (NewTabs[NewTabs[tabId].parent] != undefined) {
NewTabs[tabId].parent = NewTabs[NewTabs[tabId].parent].id;
} else {
if ((NewTabs[tabId].parent).startsWith("g_") || NewTabs[tabId].parent == "tab_list") {
NewTabs[tabId].parent = NewGroupId;
if ((NewTabs[tabId].parent).startsWith("f_") && LoadedGroup.folders[NewTabs[tabId].parent]) {
NewTabs[tabId].parent = LoadedGroup.folders[NewTabs[tabId].parent].newId;
} else {
if ((NewTabs[tabId].parent).startsWith("g_") || NewTabs[tabId].parent == "tab_list") {
NewTabs[tabId].parent = NewGroupId;
}
}
}
}
}
Manager_RecreateTreeStructure({}, NewFolders, NewTabs);
STOP = 601;
Manager_RecreateTreeStructure({}, NewFolders, NewTabs);
STOP = 301;
}, 5000);
}
}
}, 1000);
......@@ -720,8 +716,8 @@ function Manager_RecreateTreeStructure(groups, folders, tabs) { // groups, folde
if (tb != null && tbp != null && tb != undefined && tbp != undefined) {
tbp.appendChild(tb);
if (tabs[tab].expand != "") tb.classList.add(tabs[tab].expand);
if (tb.classList.contains("pin")) chrome.tabs.update(tabs[tab].id, {pinned: false});
}
if (tb.classList.contains("pin")) chrome.tabs.update(tabs[tab].id, {pinned: false});
}
}
}
......
......@@ -470,9 +470,9 @@ async function Tabs_LoadFavicon(tabId, Img, TryUrls, TabHeaderNode, i) {
async function Tabs_SaveTabs() {
setInterval(function() {
if (opt.debug) Utils_log("f: Tabs_SaveTabs");
if (tt.schedule_update_data > 1) tt.schedule_update_data = 1;
if (tt.schedule_update_data > 0) {
if (opt.debug) Utils_log("f: Tabs_SaveTabs");
let pins_data = [];
let tabs_data = [];
for (let tabId in tt.tabs) {
......
......@@ -174,7 +174,7 @@ function StartSidebarListeners() {
return;
}
if (message.command == "tab_removed") {
if (opt.debug) {Utils_log("chrome event: " + message.command + ", tabId: " + message.tabId);}
if (opt.debug) Utils_log("chrome event: " + message.command + ", tabId: " + message.tabId);
let mTab = document.getElementById(message.tabId);
if (mTab != null && tt.tabs[message.tabId]) {
let ctParent = mTab.childNodes[1];
......@@ -214,17 +214,18 @@ function StartSidebarListeners() {
if (message.command == "tab_updated") {
if (opt.debug) Utils_log("chrome event: " + message.command + ", tabId: " + message.tabId);
if (tt.tabs[message.tabId]) {
if (message.changeInfo.favIconUrl != undefined || message.changeInfo.url != undefined) {
// if (message.changeInfo.favIconUrl != undefined || message.changeInfo.url != undefined) {
if (message.changeInfo.favIconUrl != undefined || message.changeInfo.title != undefined) {
if (browserId == "F" && (message.changeInfo.favIconUrl == undefined || message.changeInfo.favIconUrl == "")) browser.sessions.setTabValue(message