From 6211e856830075986cb0acb81113b3989b49f3f8 Mon Sep 17 00:00:00 2001 From: "karol@jagiello.it" <1cyfraikilkaliter> Date: Mon, 9 Jul 2018 00:16:44 +0200 Subject: [PATCH] 1.7.2 - 1. Added one option for new tabs from toolbar 2. Added hints in options page 3. New tabs in background are added in queue, so order is always correct 4. Changed visual style for tab counters --- ..Themes/Quantum dark by kroppy.tt_theme | 1 + ..files_firefox/manifest.json | 2 +- ..files_opera/manifest.json | 2 +- ..files_vivaldi/manifest.json | 2 +- ..legacy when needed/legacy.js | 201 ----------- _locales/en/messages.json | 55 ++- background.js | 14 +- listeners_bg.js | 415 ++++++++++++----------- manifest.json | 21 +- options.html | 22 ++ options/options.js | 4 +- options/sample_tabs.js | 6 +- scripts/backup.js | 2 +- scripts/common.js | 2 + scripts/events.js | 24 +- scripts/folders.js | 4 + scripts/listeners.js | 7 + scripts/menu.js | 16 +- scripts/refresh.js | 49 +-- scripts/tabs.js | 58 ++-- scripts/toolbar.js | 7 +- sidebar.html | 2 + theme/theme.css | 71 +++- theme/theme_size_preset_0.css | 8 +- theme/theme_size_preset_1.css | 8 +- theme/theme_size_preset_2.css | 7 + theme/theme_size_preset_3.css | 6 + theme/theme_size_preset_4.css | 6 + 28 files changed, 519 insertions(+), 503 deletions(-) create mode 100644 ..Themes/Quantum dark by kroppy.tt_theme delete mode 100644 ..legacy when needed/legacy.js diff --git a/..Themes/Quantum dark by kroppy.tt_theme b/..Themes/Quantum dark by kroppy.tt_theme new file mode 100644 index 0000000..60a635a --- /dev/null +++ b/..Themes/Quantum dark by kroppy.tt_theme @@ -0,0 +1 @@ +{"ToolbarShow":true,"ColorsSet":{"attention_background":"#cf4010","attention_border":"#cf4010","button_background":"#323234","button_border":"#323234","button_hover_background":"#7f7f80","button_hover_border":"#7f7f80","button_icons":"#bebebe","button_icons_hover":"#bebebe","button_on_background":"#4a4a4f","button_on_icons":"#bebebe","button_shelf_background":"#4a4a4f","button_shelf_border":"#4a4a4f","button_shelf_hover_background":"#7f7f80","button_shelf_hover_border":"#7f7f80","button_shelf_icons":"#bebebe","button_shelf_icons_hover":"#bebebe","children_padding_left":"11px","close_hover_background":"#454547","close_hover_border":"#454547","close_hover_x":"#f9f9fa","close_x":"#f9f9fa","drag_indicator":"#b5b5b5","expand_closed_background":"#a8a8a8","expand_hover_background":"#dcdcdc","expand_open_background":"#0a84ff","filter_box_background":"#474749","filter_box_border":"#29292a","filter_box_font":"#e4e4e4","filter_clear_icon":"#bebebe","folder_icon_closed":"#a8a8a8","folder_icon_hover":"#dcdcdc","folder_icon_open":"#0a84ff","group_list_background":"#18181b","group_list_borders":"#0c0c0d","group_list_button_hover_background":"#252526","group_list_default_font_color":"#b1b1b1","pin_list_background":"#323234","pin_list_border_bottom":"#0c0c0d","scrollbar_height":"11px","scrollbar_thumb":"#525049","scrollbar_thumb_hover":"#2b2a26","scrollbar_track":"#45443f","scrollbar_width":"12px","tab_active_background":"#4a4a4f","tab_active_border":"#0a84ff","tab_active_hover_background":"#3a3a3f","tab_active_hover_border":"#0a84ff","tab_active_hover_title_font_color":"#e5e5e5","tab_active_hover_title_font_weight":"bold","tab_active_selected_background":"#3f7ebe","tab_active_selected_border":"#0a84ff","tab_active_selected_title_font_color":"#e8e8e8","tab_active_selected_title_font_weight":"normal","tab_active_title_font_color":"#e5e5e5","tab_active_title_font_weight":"bold","tab_background":"#323234","tab_border":"#323234","tab_discarded_background":"#323234","tab_discarded_border":"#323234","tab_discarded_hover_background":"#252526","tab_discarded_hover_border":"#515151","tab_discarded_hover_title_font_color":"#9e9e9e","tab_filtered":"#827e00","tab_filtered_active_border":"#d2cb00","tab_filtered_active_highlighted_search_border":"#ed9900","tab_filtered_active_highlighted_search_hover_border":"#ea9800","tab_filtered_active_hover_border":"#d2cb00","tab_filtered_active_hover_title_font_color":"#919191","tab_filtered_active_hover_title_font_weight":"normal","tab_filtered_active_title_font_color":"#919191","tab_filtered_active_title_font_weight":"normal","tab_filtered_border":"#e8e000","tab_filtered_highlighted":"#b37400","tab_filtered_highlighted_search_border":"#ed9900","tab_filtered_highlighted_search_hover_border":"#ea9800","tab_filtered_hover_border":"#d2cb00","tab_filtered_selected":"#0f8079","tab_filtered_selected_active":"#1299a9","tab_filtered_selected_active_border":"#0f8079","tab_filtered_selected_active_highlighted_search_border":"#ed9900","tab_filtered_selected_active_highlighted_search_hover_background":"#c68100","tab_filtered_selected_active_highlighted_search_hover_border":"#ea9800","tab_filtered_selected_active_hover_border":"#0d6d67","tab_filtered_selected_active_hover_title_font_color":"#cfcfcf","tab_filtered_selected_active_hover_title_font_weight":"normal","tab_filtered_selected_active_title_font_color":"#cfcfcf","tab_filtered_selected_active_title_font_weight":"normal","tab_filtered_selected_border":"#0f8079","tab_filtered_selected_highlighted_search_border":"#ed9900","tab_filtered_selected_highlighted_search_hover_border":"#ea9800","tab_filtered_selected_hover_border":"#0d6d67","tab_header_border_radius":"0px","tab_hover_background":"#252526","tab_hover_border":"#515151","tab_hover_title_font_color":"#c1c1c1","tab_hover_title_font_weight":"normal","tab_list_background":"#323234","tab_selected_active_hover_background":"#356a9f","tab_selected_active_hover_border":"#359aff","tab_selected_active_hover_title_font_color":"#e8e8e8","tab_selected_active_hover_title_font_weight":"normal","tab_selected_background":"#3f7ebe","tab_selected_border":"#3f7ebe","tab_selected_discarded_background":"#2e5c8b","tab_selected_discarded_border":"#2e5c8b","tab_selected_discarded_hover_background":"#25496d","tab_selected_discarded_hover_border":"#336699","tab_selected_discarded_title_font_color":"#9e9e9e","tab_selected_hover_background":"#356a9f","tab_selected_hover_border":"#4d88c4","tab_selected_hover_title_font_color":"#c7c7c7","tab_selected_hover_title_font_weight":"normal","tab_selected_title_font_color":"#c1c1c1","tab_selected_title_font_weight":"normal","tab_title":"#adadad","tab_title_active":"#cacaca","tab_title_discarded":"#7e7e7e","tab_title_font_color":"#c1c1c1","tab_title_font_style":"normal","tab_title_font_weight":"normal","tabs_menu_background":"#4a4a4f","tabs_menu_border":"#27272b","tabs_menu_font":"#efefef","tabs_menu_hover_background":"#727275","tabs_menu_hover_border":"#727275","tabs_menu_separator":"#6b6b6e","toolbar_background":"#323234","toolbar_border_bottom":"#0c0c0d","toolbar_shelf_background":"#4a4a4f"},"TabsSizeSetNumber":2,"TabsMargins":"1","theme_name":"Quantum dark","theme_version":4} \ No newline at end of file diff --git a/..files_firefox/manifest.json b/..files_firefox/manifest.json index 7d3afd3..f212733 100644 --- a/..files_firefox/manifest.json +++ b/..files_firefox/manifest.json @@ -48,5 +48,5 @@ "page": "options.html", "open_in_tab": true }, - "version": "1.7.1" + "version": "1.7.2" } \ No newline at end of file diff --git a/..files_opera/manifest.json b/..files_opera/manifest.json index c7c72df..37cfb4e 100644 --- a/..files_opera/manifest.json +++ b/..files_opera/manifest.json @@ -31,5 +31,5 @@ "description": "close tree" } }, - "version": "1.6.1" + "version": "1.7.2" } diff --git a/..files_vivaldi/manifest.json b/..files_vivaldi/manifest.json index 1220c67..2f02911 100644 --- a/..files_vivaldi/manifest.json +++ b/..files_vivaldi/manifest.json @@ -25,5 +25,5 @@ "description": "close tree" } }, - "version": "1.7.0" + "version": "1.7.2" } diff --git a/..legacy when needed/legacy.js b/..legacy when needed/legacy.js deleted file mode 100644 index 93a1aed..0000000 --- a/..legacy when needed/legacy.js +++ /dev/null @@ -1,201 +0,0 @@ -// 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/ - - -if (localStorage.getItem("t0") != null){ - LoadV015(0); -} - - - -function OldHashTab(tab){ - if (tabs[tab.id] == undefined){ - tabs[tab.id] = {ttid: "", hash: 0, h: 0, parent: tab.pinned ? "pin_list" : "tab_list", index: tab.index, expand: ""}; - } - var hash = 0; - if (tab.url.length === 0){ - return 0; - } - for (var i = 0; i < tab.url.length; i++){ - hash = (hash << 5)-hash; - hash = hash+tab.url.charCodeAt(i); - hash |= 0; - } - tabs[tab.id].h = hash; -} - - -function LoadV015(retry){ - var loaded_options = {}; - for (var parameter in DefaultPreferences) { - opt[parameter] = DefaultPreferences[parameter]; - } - // set loaded options - if (localStorage.getItem("current_options") !== null){ - loaded_options = JSON.parse(localStorage["current_options"]); - } - for (var parameter in opt) { - if (loaded_options[parameter] != undefined && opt[parameter] != undefined){ - opt[parameter] = loaded_options[parameter]; - } - } - SavePreferences(); - if (localStorage.getItem("current_options") !== null){ - localStorage.removeItem("current_options"); - - } - - chrome.tabs.query({windowType: "normal"}, function(qtabs){ - // create current tabs object - qtabs.forEach(function(Tab){ - OldHashTab(Tab); - }); - - var reference_tabs = {}; - var tabs_to_save = []; - var tabs_matched = 0; - - // compare saved tabs from storage to current session tabs, but can be skipped if set in options - qtabs.forEach(function(Tab){ - for (var t = 0; t < 9999; t++){ - if (localStorage.getItem("t"+t) !== null){ - var LoadedTab = JSON.parse(localStorage["t"+t]); - if (LoadedTab[1] === tabs[Tab.id].h && reference_tabs[LoadedTab[0]] == undefined){ - reference_tabs[LoadedTab[0]] = Tab.id; - tabs[Tab.id].parent = LoadedTab[2]; - tabs[Tab.id].index = LoadedTab[3]; - tabs[Tab.id].expand = LoadedTab[4]; - tabs_matched++; - break; - } - - } else { - break; - } - - } - }); - - // replace parents tabIds to new ones, for that purpose reference_tabs was made before - for (var tabId in tabs){ - if (reference_tabs[tabs[tabId].parent] != undefined){ - tabs[tabId].parent = reference_tabs[tabs[tabId].parent]; - } - } - - - // create new hashes - qtabs.forEach(function(Tab){ - ChromeHashURL(Tab); - }); - qtabs.forEach(function(Tab){ - tabs_to_save.push({id: Tab.id, hash: tabs[Tab.id].hash, parent: tabs[Tab.id].parent, index: tabs[Tab.id].index, expand: tabs[Tab.id].expand}); - }); - - localStorage["t_count"] = JSON.stringify(qtabs.length); - localStorage["tabs"] = JSON.stringify(tabs_to_save); - for (var t = 0; t < 9999; t++){ - if (localStorage.getItem("t"+t) !== null){ - localStorage.removeItem("t"+t); - } - } - ConvertLegacyStorage(); - }); -} - - -function ConvertLegacyStorage() { - if (localStorage.getItem("current_theme") != null || localStorage.getItem("preferences") != null || localStorage.getItem("tabs") != null || localStorage.getItem("windows") != null) { - let current_theme = ""; - if (localStorage.getItem("current_theme") != null) { - current_theme = localStorage["current_theme"]; - } - let LSthemes = []; - if (localStorage.getItem("themes") != null) { - LSthemes = LoadData("themes", []); - } - SLThemes = {}; - LSthemes.forEach(function(themeName) { - let them = LoadData("theme"+themeName, {"TabsSizeSetNumber": 2, "ToolbarShow": true, "toolbar": DefaultToolbar}); - SLThemes[themeName] = them; - }); - - let LSpreferences = Object.assign({}, DefaultPreferences); - if (localStorage.getItem("preferences") != null) { - LSpreferences = LoadData("preferences", {}); - } - - let LStabs = {}; - if (localStorage.getItem("tabs") != null) { - LStabs = LoadData("tabs", {}); - } - let LSwindows = {}; - if (localStorage.getItem("windows") != null) { - LSwindows = LoadData("windows", {}); - } - let LStabs_BAK1 = {}; - if (localStorage.getItem("tabs_BAK1") != null) { - LStabs_BAK1 = LoadData("tabs_BAK1", {}); - } - let LStabs_BAK2 = {}; - if (localStorage.getItem("tabs_BAK2") != null) { - LStabs_BAK2 = LoadData("tabs_BAK2", {}); - } - let LStabs_BAK3 = {}; - if (localStorage.getItem("tabs_BAK3") != null) { - LStabs_BAK3 = LoadData("tabs_BAK3", {}); - } - - let LSwindows_BAK1 = {}; - if (localStorage.getItem("windows_BAK1") != null) { - LSwindows_BAK1 = LoadData("windows_BAK1", {}); - } - let LSwindows_BAK2 = {}; - if (localStorage.getItem("windows_BAK2") != null) { - LSwindows_BAK2 = LoadData("windows_BAK2", {}); - } - let LSwindows_BAK3 = {}; - if (localStorage.getItem("windows_BAK3") != null) { - LSwindows_BAK3 = LoadData("windows_BAK3", {}); - } - - - let LSt_count = 0; - if (localStorage.getItem("t_count") != null) { - LSt_count = LoadData("t_count", {}); - } - let LSw_count = 0; - if (localStorage.getItem("w_count") != null) { - LSw_count = LoadData("w_count", {}); - } - chrome.storage.local.set({tabs: LStabs}); - chrome.storage.local.set({windows: LSwindows}); - chrome.storage.local.set({tabs_BAK1: LStabs_BAK1}); - chrome.storage.local.set({tabs_BAK2: LStabs_BAK2}); - chrome.storage.local.set({tabs_BAK3: LStabs_BAK3}); - - chrome.storage.local.set({windows_BAK1: LSwindows_BAK1}); - chrome.storage.local.set({windows_BAK2: LSwindows_BAK2}); - chrome.storage.local.set({windows_BAK3: LSwindows_BAK3}); - chrome.storage.local.set({t_count: LSt_count}); - chrome.storage.local.set({w_count: LSw_count}); - - - chrome.storage.local.set({preferences: LSpreferences}); - chrome.storage.local.set({current_theme: current_theme}); - chrome.storage.local.set({themes: SLThemes}); - localStorage.clear(); - window.location.reload(); - } -} - -function LoadData(KeyName, ExpectReturnDefaultType) { - var data = ExpectReturnDefaultType; - try { - data = JSON.parse(localStorage[KeyName]); - return data; - } catch(e) { - return ExpectReturnDefaultType; - } -} diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 34e47b8..cf69c75 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -245,6 +245,9 @@ "menu_groups_hibernate": { "message": "Hibernate" }, + "menu_group_tabs_close": { + "message": "Close tabs" + }, @@ -400,25 +403,37 @@ "message": " at the bottom" }, "options_append_child_tab_after": { - "message": "after parent (no automatic tree)" + "message": "after parent tab (no automatic tree)" }, "options_append_orphan_tab": { - "message": "Append orphan tabs (new tabs, tabs opened from shortcuts or from bookmarks)" + "message": "Append orphan tabs" }, "options_append_orphan_tab_top": { - "message": "at the top" + "message": "at the top of the group" }, "options_append_orphan_tab_after_active": { - "message": "after active" + "message": "after active tab" }, "options_append_orphan_tab_bottom": { - "message": "at the bottom" + "message": "at the bottom of the group" }, "options_append_orphan_tab_as_child": { "message": "treat as active's tab child" }, + "options_toolbar_new_tab": { + "message": "Toolbar + (new tab button) should append tab" + }, + "options_toolbar_new_tab_as_regular_orphan": { + "message": "as a regular orphan tab (option above)" + }, + "options_toolbar_new_tab_root_of_group": { + "message": "at the bottom of the group" + }, + + + "options_after_closing_active_tab": { "message": "After closing active tab," }, @@ -590,15 +605,37 @@ }, - - - - "options_toolbar_look": { "message": " Toolbar's look " }, + "hint_orphan_tab": { + "message": "Orphan tab is a tab opened from an external source, which can be:" + }, + "hint_ctrl_t": { + "message": "ctrl+t shortcut" + }, + "hint_from_pin": { + "message": "link that opens new tab from pinned tab" + }, + "hint_from_bookmark": { + "message": "bookmark" + }, + "hint_from_external_link": { + "message": "external link" + }, + "hint_from_popup": { + "message": "popup opened as a tab (settings in browser, popup blocker or similar)" + }, + "hint_explained_new_tab_settings": { + "message": "+ button in Tree Tabs toolbar, places new tabs in the root of the active group, unless set differently." + }, + "hint_explained_orphan_after_active_settings": { + "message": "If 'Append orphan tabs' is set to 'after active' and active tab is not in active group, tab will append to the root of the active group instead. But only if sidebar is open." + }, + + "button_background": { "message": "Toolbar buttons background" diff --git a/background.js b/background.js index e90a6e6..43a590f 100644 --- a/background.js +++ b/background.js @@ -260,9 +260,7 @@ function QuantumLoadTabs(retry) { QuantumAppendWinTTId(winId); } - if (b.windows[winId].activeTabId == undefined) { // legacy - b.windows[winId].activeTabId = [0,0]; // legacy - } // legacy + b.windows[winId].activeTabId = 0; // legacy for (let tIndex = 0; tIndex < tabsCount; tIndex++) { @@ -272,8 +270,7 @@ function QuantumLoadTabs(retry) { let tabPinned = w[winIndex].tabs[tabIndex].pinned; if (tab.active) { - b.windows[winId].activeTabId[0] = tabId; - b.windows[winId].activeTabId[1] = tabId; + b.windows[winId].activeTabId = tabId; } // LOAD TTID FROM FIREFOX GET TAB VALUE @@ -404,7 +401,7 @@ function QuantumAppendWinTTId(windowId) { if (b.windows[windowId] != undefined) { b.windows[windowId].ttid = NewTTWindowId; } else { - b.windows[windowId] = {activeTabId: [0,0], ttid: NewTTWindowId, 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, active_tab_ttid: "", prev_active_tab: 0, prev_active_tab_ttid: "", name: labels.ungrouped_group, font: ""}}, folders: {}}; + b.windows[windowId] = {activeTabId: 0, ttid: NewTTWindowId, 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, active_tab_ttid: "", prev_active_tab: 0, prev_active_tab_ttid: "", name: labels.ungrouped_group, font: ""}}, folders: {}}; } // if (b.schedule_save > 0) browser.sessions.setWindowValue( windowId, "TTdata", b.windows[windowId] ); } @@ -493,8 +490,7 @@ function ChromiumLoadTabs(retry) { ChromiumHashURL(w[wIndex].tabs[tabIndex]); if (w[wIndex].tabs[tabIndex].active) { - b.windows[w[wIndex].id].activeTabId[0] = w[wIndex].tabs[tabIndex].id; - b.windows[w[wIndex].id].activeTabId[1] = w[wIndex].tabs[tabIndex].id; + b.windows[w[wIndex].id].activeTabId = w[wIndex].tabs[tabIndex].id; } } @@ -607,7 +603,7 @@ async function ChromiumAutoSaveData(BAK, LoopTimer) { } function ChromiumAddWindowData(winId) { - b.windows[winId] = {activeTabId: [0,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: {}}; + b.windows[winId] = {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 ChromiumHashURL(tab) { diff --git a/listeners_bg.js b/listeners_bg.js index e6a814b..76ba87b 100644 --- a/listeners_bg.js +++ b/listeners_bg.js @@ -229,6 +229,8 @@ function QuantumStartListeners() { browser.sidebarAction.open(); }); chrome.tabs.onCreated.addListener(function(tab) { + let prevActiveTabId = b.windows[tab.windowId].activeTabId; + b.NewTabsQueue.push(tab.id); let t = Promise.resolve(browser.sessions.getTabValue(tab.id, "TTdata")).then(function(TabData) { if (TabData != undefined) { b.tabs[tab.id] = Object.assign({}, TabData); @@ -236,7 +238,7 @@ function QuantumStartListeners() { chrome.runtime.sendMessage({command: "tab_created", windowId: tab.windowId, tabId: tab.id, tab: tab, ParentId: originalParent, InsertAfterId: undefined, Append: undefined}); } else { QuantumAppendTabTTId(tab); - OnMessageTabCreated(tab.id); + OnMessageTabCreated(tab.id, prevActiveTabId); } }); }); @@ -317,10 +319,7 @@ function QuantumStartListeners() { }); chrome.tabs.onActivated.addListener(function(activeInfo) { if (b.windows[activeInfo.windowId]) { - if (b.windows[activeInfo.windowId].activeTabId[1] != activeInfo.tabId) { - b.windows[activeInfo.windowId].activeTabId[0] = b.windows[activeInfo.windowId].activeTabId[1]; - b.windows[activeInfo.windowId].activeTabId[1] = activeInfo.tabId; - } + b.windows[activeInfo.windowId].activeTabId = activeInfo.tabId; } chrome.runtime.sendMessage({command: "tab_activated", windowId: activeInfo.windowId, tabId: activeInfo.tabId}); b.schedule_save++; @@ -362,8 +361,9 @@ function QuantumStartListeners() { function ChromiumStartListeners() { // start all listeners chrome.tabs.onCreated.addListener(function(tab) { + b.NewTabsQueue.push(tab.id); ChromiumHashURL(tab); - OnMessageTabCreated(tab.id); + OnMessageTabCreated(tab.id, b.windows[tab.windowId].activeTabId); }); chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) { if (b.EmptyTabs.indexOf(tabId) != -1) { @@ -432,10 +432,7 @@ function ChromiumStartListeners() { // start all listeners }); chrome.tabs.onActivated.addListener(function(activeInfo) { if (b.windows[activeInfo.windowId]) { - if (b.windows[activeInfo.windowId].activeTabId[1] != activeInfo.tabId) { - b.windows[activeInfo.windowId].activeTabId[0] = b.windows[activeInfo.windowId].activeTabId[1]; - b.windows[activeInfo.windowId].activeTabId[1] = activeInfo.tabId; - } + b.windows[activeInfo.windowId].activeTabId = activeInfo.tabId; } chrome.runtime.sendMessage({command: "tab_activated", windowId: activeInfo.windowId, tabId: activeInfo.tabId}); b.schedule_save++; @@ -457,257 +454,263 @@ function ChromiumStartListeners() { // start all listeners -function OnMessageTabCreated(tabId) { - chrome.tabs.get(tabId, function(NewTab) { // get tab again as reported tab's url is empty! Also for some reason firefox sends tab with "active == false" even if tab is active (THIS IS POSSIBLY A NEW BUG IN FF 60!) - - let ParentId; - let AfterId; - let append; - - if (b.windows[NewTab.windowId] && NewTab.active) { - b.windows[NewTab.windowId].groups[b.windows[NewTab.windowId].active_group].active_tab = NewTab.id; - } +function OnMessageTabCreated(tabId, activeTabId) { + if (b.NewTabsQueue.length > 0 && b.NewTabsQueue[0] == tabId) { + chrome.tabs.get(tabId, function(NewTab) { // get tab again as reported tab's url is empty! Also for some reason firefox sends tab with "active == false" even if tab is active (THIS IS POSSIBLY A NEW BUG IN FF 60!) - if (NewTab.url == b.newTabUrl) { - b.EmptyTabs.push(tabId); - } - - - if (NewTab.pinned) { + let ParentId; + let AfterId; + let append; - let PinTabs = GetChildren("pin_list"); - b.tabs[NewTab.id].parent = "pin_list"; - b.tabs[NewTab.id].index = NewTab.index; - if (browserId == "F") { - b.tabs[NewTab.id].parent_ttid = ""; + if (b.windows[NewTab.windowId] && NewTab.active) { + b.windows[NewTab.windowId].groups[b.windows[NewTab.windowId].active_group].active_tab = NewTab.id; } - for (let i = PinTabs.indexOf(NewTab.openerTabId)+1; i < PinTabs.length; i++) { // shift next siblings indexes - b.tabs[PinTabs[i]].index += 1; + + if (NewTab.url == b.newTabUrl) { + b.EmptyTabs.push(tabId); } - - } else { - - if (opt.append_orphan_tab == "as_child" && opt.orphaned_tabs_to_ungrouped == false) { + + if (NewTab.pinned) { + let PinTabs = GetChildren("pin_list"); + b.tabs[NewTab.id].parent = "pin_list"; + if (browserId == "F") { + b.tabs[NewTab.id].parent_ttid = ""; + } + for (let i = PinTabs.indexOf(NewTab.openerTabId)+1; i < PinTabs.length; i++) { // shift next siblings indexes + b.tabs[PinTabs[i]].index += 1; + } + b.tabs[NewTab.id].index = NewTab.index; + + } else { - // let atb = NewTab.active ? 0 : 1; - NewTab.openerTabId = b.windows[NewTab.windowId].activeTabId[NewTab.active ? 0 : 1]; - } - - if (NewTab.openerTabId) { // child case - - let OpenerSiblings = GetChildren(b.tabs[NewTab.openerTabId].parent); - - if (opt.append_child_tab == "after") { // place tabs flat - b.tabs[NewTab.id].parent = b.tabs[NewTab.openerTabId].parent; - if (browserId == "F") { - b.tabs[NewTab.id].parent_ttid = b.tabs[NewTab.openerTabId].parent_ttid; - } - b.tabs[NewTab.id].index = b.tabs[NewTab.openerTabId].index+1; - for (let i = OpenerSiblings.indexOf(NewTab.openerTabId)+1; i < OpenerSiblings.length; i++) { // shift next siblings indexes - b.tabs[OpenerSiblings[i]].index += 1; - } - AfterId = NewTab.openerTabId; - - } else { - - if (opt.max_tree_depth == 0) { // place tabs flat if limit is set to 0 + if (opt.append_orphan_tab == "as_child" && opt.orphaned_tabs_to_ungrouped == false) { + NewTab.openerTabId = activeTabId; + } + + if (NewTab.openerTabId) { // child case + + let OpenerSiblings = GetChildren(b.tabs[NewTab.openerTabId].parent); + if (opt.append_child_tab == "after") { // place tabs flat b.tabs[NewTab.id].parent = b.tabs[NewTab.openerTabId].parent; - if (browserId == "F"){ + if (browserId == "F") { b.tabs[NewTab.id].parent_ttid = b.tabs[NewTab.openerTabId].parent_ttid; } - - if (opt.append_child_tab_after_limit == "after") { // max tree depth, place tab after parent - b.tabs[NewTab.id].index = b.tabs[NewTab.openerTabId].index+1; - for (let i = OpenerSiblings.indexOf(NewTab.openerTabId)+1; i < OpenerSiblings.length; i++) { // shift next siblings indexes - b.tabs[OpenerSiblings[i]].index += 1; - } - AfterId = NewTab.openerTabId; - } - - if (opt.append_child_tab_after_limit == "top" && opt.append_child_tab != "after") { // max tree depth, place tab on top (above parent) - b.tabs[NewTab.id].index = 0; - for (let i = 0; i < OpenerSiblings.length; i++) { // shift all siblings indexes - b.tabs[OpenerSiblings[i]].index += 1; - } - ParentId = b.tabs[NewTab.id].parent; - } - - if (opt.append_child_tab_after_limit == "bottom" && opt.append_child_tab != "after") { // max tree depth, place tab on bottom (below parent) - if (OpenerSiblings.length > 0) { - b.tabs[NewTab.id].index = b.tabs[OpenerSiblings[OpenerSiblings.length-1]].index+1; - } else { - b.tabs[NewTab.id].index = 1; - } - ParentId = b.tabs[NewTab.id].parent; - append = true; + for (let i = OpenerSiblings.indexOf(NewTab.openerTabId)+1; i < OpenerSiblings.length; i++) { // shift next siblings indexes + b.tabs[OpenerSiblings[i]].index += 1; } + b.tabs[NewTab.id].index = b.tabs[NewTab.openerTabId].index+1; + AfterId = NewTab.openerTabId; } else { + + if (opt.max_tree_depth == 0) { // place tabs flat if limit is set to 0 - let Parents = GetTabParents(NewTab.openerTabId); - let OpenerChildren = GetChildren(NewTab.openerTabId); - - if (opt.max_tree_depth < 0 || (opt.max_tree_depth > 0 && Parents.length < opt.max_tree_depth)) { // append to tree on top and bottom - - b.tabs[NewTab.id].parent = NewTab.openerTabId; + b.tabs[NewTab.id].parent = b.tabs[NewTab.openerTabId].parent; if (browserId == "F"){ - b.tabs[NewTab.id].parent_ttid = b.tabs[NewTab.openerTabId].ttid; + b.tabs[NewTab.id].parent_ttid = b.tabs[NewTab.openerTabId].parent_ttid; + } + + if (opt.append_child_tab_after_limit == "after") { // max tree depth, place tab after parent + for (let i = OpenerSiblings.indexOf(NewTab.openerTabId)+1; i < OpenerSiblings.length; i++) { // shift next siblings indexes + b.tabs[OpenerSiblings[i]].index += 1; + } + b.tabs[NewTab.id].index = b.tabs[NewTab.openerTabId].index+1; + AfterId = NewTab.openerTabId; } - if (opt.append_child_tab == "top") { // place child tab at the top (reverse hierarchy) - b.tabs[NewTab.id].index = 0; - for (let i = 0; i < OpenerChildren.length; i++) { // shift all siblings indexes - b.tabs[OpenerChildren[i]].index += 1; + if (opt.append_child_tab_after_limit == "top" && opt.append_child_tab != "after") { // max tree depth, place tab on top (above parent) + for (let i = 0; i < OpenerSiblings.length; i++) { // shift all siblings indexes + b.tabs[OpenerSiblings[i]].index += 1; } + b.tabs[NewTab.id].index = 0; ParentId = b.tabs[NewTab.id].parent; } - - if (opt.append_child_tab == "bottom") { // place child tab at the bottom - if (OpenerChildren.length > 0) { - b.tabs[NewTab.id].index = b.tabs[OpenerChildren[OpenerChildren.length-1]].index+1; + + if (opt.append_child_tab_after_limit == "bottom" && opt.append_child_tab != "after") { // max tree depth, place tab on bottom (below parent) + if (OpenerSiblings.length > 0) { + b.tabs[NewTab.id].index = b.tabs[OpenerSiblings[OpenerSiblings.length-1]].index+1; } else { - b.tabs[NewTab.id].index = 0; + b.tabs[NewTab.id].index = 1; } ParentId = b.tabs[NewTab.id].parent; append = true; } - + } else { - if (opt.max_tree_depth > 0 && Parents.length >= opt.max_tree_depth) { // if reached depth limit of the tree - - b.tabs[NewTab.id].parent = b.tabs[NewTab.openerTabId].parent; + let Parents = GetTabParents(NewTab.openerTabId); + let OpenerChildren = GetChildren(NewTab.openerTabId); + + if (opt.max_tree_depth < 0 || (opt.max_tree_depth > 0 && Parents.length < opt.max_tree_depth)) { // append to tree on top and bottom + + b.tabs[NewTab.id].parent = NewTab.openerTabId; if (browserId == "F"){ - b.tabs[NewTab.id].parent_ttid = b.tabs[NewTab.openerTabId].parent_ttid; + b.tabs[NewTab.id].parent_ttid = b.tabs[NewTab.openerTabId].ttid; } - - if (opt.append_child_tab_after_limit == "after") { // tab will append after opener - b.tabs[NewTab.id].index = b.tabs[NewTab.openerTabId].index+1; - for (let i = OpenerSiblings.indexOf(NewTab.openerTabId)+1; i < OpenerSiblings.length; i++) { // shift next siblings indexes - b.tabs[OpenerSiblings[i]].index += 1; - } - AfterId = NewTab.openerTabId; - } - - if (opt.append_child_tab_after_limit == "top") { // tab will append on top - b.tabs[NewTab.id].index = 0; + + if (opt.append_child_tab == "top") { // place child tab at the top (reverse hierarchy) for (let i = 0; i < OpenerChildren.length; i++) { // shift all siblings indexes b.tabs[OpenerChildren[i]].index += 1; } + b.tabs[NewTab.id].index = 0; ParentId = b.tabs[NewTab.id].parent; } - if (opt.append_child_tab_after_limit == "bottom") { // tab will append on bottom - if (OpenerSiblings.length > 0) { - b.tabs[NewTab.id].index = b.tabs[OpenerSiblings[OpenerSiblings.length-1]].index+1; + if (opt.append_child_tab == "bottom") { // place child tab at the bottom + if (OpenerChildren.length > 0) { + b.tabs[NewTab.id].index = b.tabs[OpenerChildren[OpenerChildren.length-1]].index+1; } else { - b.tabs[NewTab.id].index = 1; + b.tabs[NewTab.id].index = 0; } ParentId = b.tabs[NewTab.id].parent; append = true; } - + + } else { + + if (opt.max_tree_depth > 0 && Parents.length >= opt.max_tree_depth) { // if reached depth limit of the tree + + b.tabs[NewTab.id].parent = b.tabs[NewTab.openerTabId].parent; + if (browserId == "F"){ + b.tabs[NewTab.id].parent_ttid = b.tabs[NewTab.openerTabId].parent_ttid; + } + + if (opt.append_child_tab_after_limit == "after") { // tab will append after opener + for (let i = OpenerSiblings.indexOf(NewTab.openerTabId)+1; i < OpenerSiblings.length; i++) { // shift next siblings indexes + b.tabs[OpenerSiblings[i]].index += 1; + } + b.tabs[NewTab.id].index = b.tabs[NewTab.openerTabId].index+1; + AfterId = NewTab.openerTabId; + } + + if (opt.append_child_tab_after_limit == "top") { // tab will append on top + for (let i = 0; i < OpenerChildren.length; i++) { // shift all siblings indexes + b.tabs[OpenerChildren[i]].index += 1; + } + b.tabs[NewTab.id].index = 0; + ParentId = b.tabs[NewTab.id].parent; + } + + if (opt.append_child_tab_after_limit == "bottom") { // tab will append on bottom + if (OpenerSiblings.length > 0) { + b.tabs[NewTab.id].index = b.tabs[OpenerSiblings[OpenerSiblings.length-1]].index+1; + } else { + b.tabs[NewTab.id].index = 1; + } + ParentId = b.tabs[NewTab.id].parent; + append = true; + } + + } } - } - } - } - } else { // orphan tab - - if (opt.orphaned_tabs_to_ungrouped == true) { // if set to append orphan tabs to ungrouped group - let TabListTabs = GetChildren("tab_list"); - b.tabs[NewTab.id].index = b.tabs[TabListTabs[TabListTabs.length-1]].index+1; - ParentId = "tab_list"; - append = true; - // chrome.runtime.sendMessage({command: "set_active_group", windowId: NewTab.windowId, groupId: "tab_list"}); - } else { + } + } + + } else { // orphan tab - if (opt.append_orphan_tab == "after_active") { + if (opt.orphaned_tabs_to_ungrouped == true) { // if set to append orphan tabs to ungrouped group + let TabListTabs = GetChildren("tab_list"); + b.tabs[NewTab.id].index = b.tabs[TabListTabs[TabListTabs.length-1]].index+1; + ParentId = "tab_list"; + append = true; + } else { - if (b.windows[NewTab.windowId] && b.windows[NewTab.windowId].activeTabId) { - let activeTabId = b.windows[NewTab.windowId].activeTabId[1] != NewTab.id ? b.windows[NewTab.windowId].activeTabId[1] : b.windows[NewTab.windowId].activeTabId[0]; + if (opt.append_orphan_tab == "after_active") { - // console.log(b.tabs[activeTabId].index); - if (b.tabs[activeTabId]) { - let ActiveSiblings = GetChildren(b.tabs[activeTabId].parent); - b.tabs[NewTab.id].parent = b.tabs[activeTabId].parent; - b.tabs[NewTab.id].index = b.tabs[activeTabId].index+1; - for (let i = ActiveSiblings.indexOf(activeTabId)+1; i < ActiveSiblings.length; i++) { // shift next siblings indexes - // let prev = b.tabs[ActiveSiblings[i]].index; - b.tabs[ActiveSiblings[i]].index += 1; - // console.log(prev + " " + b.tabs[ActiveSiblings[i]].index ); + if (b.windows[NewTab.windowId] && b.windows[NewTab.windowId].activeTabId) { + if (b.tabs[activeTabId]) { + + let ActiveSiblings = GetChildren(b.tabs[activeTabId].parent); + b.tabs[NewTab.id].parent = b.tabs[activeTabId].parent; + for (let i = ActiveSiblings.indexOf(activeTabId)+1; i < ActiveSiblings.length; i++) { // shift next siblings indexes + b.tabs[ActiveSiblings[i]].index += 1; + } + b.tabs[NewTab.id].index = b.tabs[activeTabId].index+1; + if (browserId == "F"){ + b.tabs[NewTab.id].parent_ttid = b.tabs[activeTabId].parent_ttid; + } + + AfterId = activeTabId; + + } else { // FAIL, no active tab! + let GroupTabs = GetChildren(b.windows[NewTab.windowId].active_group); + b.tabs[NewTab.id].parent = b.windows[NewTab.windowId].active_group; + if (browserId == "F"){ + b.tabs[NewTab.id].parent_ttid = ""; + } + if (GroupTabs.length > 0) { + b.tabs[NewTab.id].index = b.tabs[GroupTabs[GroupTabs.length-1]].index+1; + } else { + b.tabs[NewTab.id].index = 0; + } + ParentId = b.windows[NewTab.windowId].active_group; } - if (browserId == "F"){ - b.tabs[NewTab.id].parent_ttid = b.tabs[activeTabId].parent_ttid; - } - AfterId = activeTabId; - } else { // FAIL, no active tab! - let GroupTabs = GetChildren(b.windows[NewTab.windowId].active_group); - b.tabs[NewTab.id].parent = b.windows[NewTab.windowId].active_group; + } else { + b.tabs[NewTab.id].parent = "tab_list"; if (browserId == "F"){ b.tabs[NewTab.id].parent_ttid = ""; } - if (GroupTabs.length > 0) { - b.tabs[NewTab.id].index = b.tabs[GroupTabs[GroupTabs.length-1]].index+1; - } else { - b.tabs[NewTab.id].index = 0; - } - ParentId = b.windows[NewTab.windowId].active_group; + b.tabs[NewTab.id].index = NewTab.index; + ParentId = "tab_list"; } - } else { - b.tabs[NewTab.id].parent = "tab_list"; + } + + if (opt.append_orphan_tab == "top") { + let GroupTabs = GetChildren(b.windows[NewTab.windowId].active_group); + b.tabs[NewTab.id].parent = b.windows[NewTab.windowId].active_group; if (browserId == "F"){ b.tabs[NewTab.id].parent_ttid = ""; } - b.tabs[NewTab.id].index = NewTab.index; - ParentId = "tab_list"; - } - // console.log(b.tabs[NewTab.id].index); - } - - if (opt.append_orphan_tab == "top") { - let GroupTabs = GetChildren(b.windows[NewTab.windowId].active_group); - b.tabs[NewTab.id].parent = b.windows[NewTab.windowId].active_group; - if (browserId == "F"){ - b.tabs[NewTab.id].parent_ttid = ""; - } - b.tabs[NewTab.id].index = 0; - for (let i = 0; i < GroupTabs.length; i++) { // shift all tabs indexes in group - b.tabs[GroupTabs[i]].index += 1; - } - ParentId = b.windows[NewTab.windowId].active_group; - } - - if (opt.append_orphan_tab == "bottom") { - let GroupTabs = GetChildren(b.windows[NewTab.windowId].active_group); - b.tabs[NewTab.id].parent = b.windows[NewTab.windowId].active_group; - if (browserId == "F"){ - b.tabs[NewTab.id].parent_ttid = ""; - } - if (GroupTabs.length > 0) { - b.tabs[NewTab.id].index = b.tabs[GroupTabs[GroupTabs.length-1]].index+1; - } else { + for (let i = 0; i < GroupTabs.length; i++) { // shift all tabs indexes in group + b.tabs[GroupTabs[i]].index += 1; + } b.tabs[NewTab.id].index = 0; + ParentId = b.windows[NewTab.windowId].active_group; } - ParentId = b.windows[NewTab.windowId].active_group; - append = true; - } - - } + if (opt.append_orphan_tab == "bottom") { + let GroupTabs = GetChildren(b.windows[NewTab.windowId].active_group); + b.tabs[NewTab.id].parent = b.windows[NewTab.windowId].active_group; + if (browserId == "F"){ + b.tabs[NewTab.id].parent_ttid = ""; + } + if (GroupTabs.length > 0) { + b.tabs[NewTab.id].index = b.tabs[GroupTabs[GroupTabs.length-1]].index+1; + } else { + b.tabs[NewTab.id].index = 0; + } + ParentId = b.windows[NewTab.windowId].active_group; + append = true; + } + } + } + + if (opt.move_tabs_on_url_change === "all_new") { + setTimeout(function() { + chrome.tabs.get(NewTab.id, function(CheckTabsUrl) { + AppendTabToGroupOnRegexMatch(CheckTabsUrl.id, CheckTabsUrl.windowId, CheckTabsUrl.url); + }); + }, 100); + } + } + setTimeout(function() { + b.schedule_save++; + }, 500); + + chrome.runtime.sendMessage({command: "tab_created", windowId: NewTab.windowId, tabId: NewTab.id, tab: NewTab, ParentId: ParentId, InsertAfterId: AfterId, Append: append}); + + if (b.NewTabsQueue.indexOf(NewTab.id) != -1) { + b.NewTabsQueue.splice(b.NewTabsQueue.indexOf(NewTab.id), 1); } - if (opt.move_tabs_on_url_change === "all_new") { - setTimeout(function() { - chrome.tabs.get(NewTab.id, function(CheckTabsUrl) { - AppendTabToGroupOnRegexMatch(CheckTabsUrl.id, CheckTabsUrl.windowId, CheckTabsUrl.url); - }); - }, 100); - } - } + }); + + } else { + console.log("tab_created in queue"); setTimeout(function() { - b.schedule_save++; - }, 500); - chrome.runtime.sendMessage({command: "tab_created", windowId: NewTab.windowId, tabId: NewTab.id, tab: NewTab, ParentId: ParentId, InsertAfterId: AfterId, Append: append}); - }); + OnMessageTabCreated(tabId, activeTabId); + }, 100); + + } } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 7d3afd3..0e7a66c 100644 --- a/manifest.json +++ b/manifest.json @@ -14,7 +14,8 @@ "19": "icons/16.png", "16": "icons/16.png" }, - "permissions": [ "tabs", "sessions", "storage", "unlimitedStorage", "bookmarks", "tabHide" ], + "permissions": [ "", "tabs", "sessions", "storage", "unlimitedStorage", "bookmarks", "tabHide" ], + "sidebar_action": { "default_icon": { "16": "icons/16.png", @@ -28,16 +29,6 @@ "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", @@ -48,5 +39,11 @@ "page": "options.html", "open_in_tab": true }, - "version": "1.7.1" + "commands": { + "close_tree": { + "suggested_key": { "default": "Alt+W" }, + "description": "close tree" + } + }, + "version": "100" } \ No newline at end of file diff --git a/options.html b/options.html index 5eee67b..09e0531 100644 --- a/options.html +++ b/options.html @@ -221,6 +221,13 @@ +
  • + + +