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
// ********** TOOLBAR ***************
2018-03-13 14:39:34 +01:00
// RESTORE LAST USED SEARCH TYPE (URL OR TITLE) IN TOOLBAR SEARCH
2017-11-20 18:14:07 +01:00
function RestoreToolbarSearchFilter ( ) {
2018-07-03 20:36:38 +02:00
chrome . runtime . sendMessage ( { command : "get_search_filter" , windowId : tt . CurrentWindowId } , function ( response ) {
2018-03-13 14:39:34 +01:00
let ButtonFilter = document . getElementById ( "button_filter_type" ) ;
2017-11-20 18:14:07 +01:00
if ( response == "url" ) {
2018-03-13 14:39:34 +01:00
ButtonFilter . classList . add ( "url" ) ;
ButtonFilter . classList . remove ( "title" ) ;
2017-11-20 18:14:07 +01:00
} else {
2018-03-13 14:39:34 +01:00
ButtonFilter . classList . add ( "title" ) ;
ButtonFilter . classList . remove ( "url" ) ;
2017-11-20 18:14:07 +01:00
}
} ) ;
}
2018-03-13 14:39:34 +01:00
// RESTORE LAST ACTIVE SHELF (SEARCH, TOOLS, GROUPS, SESSION OR FOLDER) IN TOOLBAR
2017-11-12 22:00:40 +01:00
function RestoreToolbarShelf ( ) {
2018-07-03 20:36:38 +02:00
chrome . runtime . sendMessage ( { command : "get_active_shelf" , windowId : tt . CurrentWindowId } , function ( response ) {
2018-03-13 14:39:34 +01:00
let filterBox = document . getElementById ( "filter_box" ) ;
2018-07-03 20:36:38 +02:00
filterBox . setAttribute ( "placeholder" , labels . searchbox ) ;
2018-03-13 14:39:34 +01:00
filterBox . style . opacity = "1" ;
document . querySelectorAll ( ".on" ) . forEach ( function ( s ) {
s . classList . remove ( "on" ) ;
} ) ;
document . querySelectorAll ( ".toolbar_shelf" ) . forEach ( function ( s ) {
s . classList . add ( "hidden" ) ;
} ) ;
if ( response == "search" && document . getElementById ( "button_search" ) != null ) {
document . getElementById ( "toolbar_search" ) . classList . remove ( "hidden" ) ;
document . getElementById ( "button_search" ) . classList . add ( "on" ) ;
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
if ( response == "tools" && document . getElementById ( "button_tools" ) != null ) {
document . getElementById ( "toolbar_shelf_tools" ) . classList . remove ( "hidden" ) ;
document . getElementById ( "button_tools" ) . classList . add ( "on" ) ;
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
if ( response == "groups" && document . getElementById ( "button_groups" ) != null ) {
document . getElementById ( "toolbar_shelf_groups" ) . classList . remove ( "hidden" ) ;
document . getElementById ( "button_groups" ) . classList . add ( "on" ) ;
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
if ( response == "backup" && document . getElementById ( "button_backup" ) != null ) {
document . getElementById ( "toolbar_shelf_backup" ) . classList . remove ( "hidden" ) ;
document . getElementById ( "button_backup" ) . classList . add ( "on" ) ;
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
if ( response == "folders" && document . getElementById ( "button_folders" ) != null ) {
document . getElementById ( "toolbar_shelf_folders" ) . classList . remove ( "hidden" ) ;
document . getElementById ( "button_folders" ) . classList . add ( "on" ) ;
2017-11-12 22:00:40 +01:00
}
2017-11-20 18:14:07 +01:00
if ( browserId != "F" ) {
2018-03-13 14:39:34 +01:00
chrome . storage . local . get ( null , function ( storage ) {
let bak1 = storage [ "windows_BAK1" ] ? storage [ "windows_BAK1" ] : [ ] ;
let bak2 = storage [ "windows_BAK2" ] ? storage [ "windows_BAK2" ] : [ ] ;
let bak3 = storage [ "windows_BAK3" ] ? storage [ "windows_BAK3" ] : [ ] ;
if ( bak1 . length && document . getElementById ( "#button_load_bak1" ) != null ) {
document . getElementById ( "button_load_bak1" ) . classList . remove ( "disabled" ) ;
} else {
document . getElementById ( "button_load_bak1" ) . classList . add ( "disabled" ) ;
}
if ( bak2 . length && document . getElementById ( "#button_load_bak2" ) != null ) {
document . getElementById ( "button_load_bak2" ) . classList . remove ( "disabled" ) ;
} else {
document . getElementById ( "button_load_bak2" ) . classList . add ( "disabled" ) ;
}
if ( bak3 . length && document . getElementById ( "#button_load_bak3" ) != null ) {
document . getElementById ( "button_load_bak3" ) . classList . remove ( "disabled" ) ;
} else {
document . getElementById ( "button_load_bak3" ) . classList . add ( "disabled" ) ;
}
} ) ;
2017-11-12 22:00:40 +01:00
}
RefreshGUI ( ) ;
} ) ;
2017-07-26 22:23:39 +02:00
}
2018-03-13 14:39:34 +01:00
// FUNCTION TO TOGGLE SHELFS AND SAVE IT
function ShelfToggle ( mousebutton , button , toolbarId , SendMessage ) {
if ( mousebutton == 1 ) {
if ( button . classList . contains ( "on" ) ) {
document . querySelectorAll ( ".on" ) . forEach ( function ( s ) {
s . classList . remove ( "on" ) ;
} ) ;
document . querySelectorAll ( ".toolbar_shelf" ) . forEach ( function ( s ) {
s . classList . add ( "hidden" ) ;
} ) ;
} else {
document . querySelectorAll ( ".toolbar_shelf:not(#" + toolbarId + ")" ) . forEach ( function ( s ) {
s . classList . add ( "hidden" ) ;
} ) ;
document . getElementById ( toolbarId ) . classList . remove ( "hidden" ) ;
2018-07-03 20:36:38 +02:00
chrome . runtime . sendMessage ( { command : "set_active_shelf" , active _shelf : SendMessage , windowId : tt . CurrentWindowId } ) ;
2018-03-13 14:39:34 +01:00
document . querySelectorAll ( ".on:not(#" + button . id + ")" ) . forEach ( function ( s ) {
s . classList . remove ( "on" ) ;
} ) ;
button . classList . add ( "on" ) ;
2017-07-26 22:23:39 +02:00
}
2018-03-13 14:39:34 +01:00
RefreshGUI ( ) ;
}
2017-11-12 22:00:40 +01:00
}
2017-07-26 22:23:39 +02:00
2018-05-22 02:11:29 +02:00
function RemoveToolbar ( ) {
let toolbar = document . getElementById ( "toolbar" ) ;
while ( toolbar . hasChildNodes ( ) ) {
toolbar . removeChild ( toolbar . firstChild ) ;
}
}
function RecreateToolbar ( NewToolbar ) {
let toolbar = document . getElementById ( "toolbar" ) ;
for ( var shelf in NewToolbar ) {
let NewShelf = document . createElement ( "div" ) ;
NewShelf . id = shelf ;
NewShelf . classList = "toolbar_shelf" ;
toolbar . appendChild ( NewShelf ) ;
NewToolbar [ shelf ] . forEach ( function ( button ) {
let Newbutton = document . createElement ( "div" ) ;
Newbutton . id = button ;
Newbutton . classList = "button" ;
NewShelf . appendChild ( Newbutton ) ;
let NewbuttonIMG = document . createElement ( "div" ) ;
NewbuttonIMG . classList = "button_img" ;
Newbutton . appendChild ( NewbuttonIMG ) ;
} ) ;
}
let toolbar _main = document . getElementById ( "toolbar_main" ) ;
let SearchShelf = document . getElementById ( "toolbar_search" ) ;
if ( toolbar _main != null && SearchShelf != null ) {
toolbar _main . classList . remove ( "toolbar_shelf" ) ;
let SearchBox = document . createElement ( "div" ) ;
SearchBox . id = "toolbar_search_input_box" ;
SearchShelf . appendChild ( SearchBox ) ;
let SearchInput = document . createElement ( "input" ) ;
SearchInput . classList = "text_input" ;
SearchInput . id = "filter_box" ;
SearchInput . type = "text" ;
2018-07-03 20:36:38 +02:00
SearchInput . placeholder = labels . searchbox ;
2018-05-22 02:11:29 +02:00
SearchBox . appendChild ( SearchInput ) ;
let ClearX = document . createElement ( "div" ) ;
ClearX . id = "button_filter_clear" ;
ClearX . type = "reset" ;
ClearX . style . opacity = "0" ;
ClearX . style . position = "absolute" ;
SearchBox . appendChild ( ClearX ) ;
let SearchButtons = document . createElement ( "div" ) ;
SearchButtons . id = "toolbar_search_buttons" ;
SearchShelf . appendChild ( SearchButtons ) ;
let FilterType = document . getElementById ( "button_filter_type" ) ;
SearchButtons . appendChild ( FilterType ) ;
let GoPrev = document . getElementById ( "filter_search_go_prev" ) ;
SearchButtons . appendChild ( GoPrev ) ;
let GoNext = document . getElementById ( "filter_search_go_next" ) ;
SearchButtons . appendChild ( GoNext ) ;
Loadi18n ( ) ;
}
}
function RecreateToolbarUnusedButtons ( buttonsIds ) {
let unused _buttons = document . getElementById ( "toolbar_unused_buttons" ) ;
buttonsIds . forEach ( function ( button ) {
let Newbutton = document . createElement ( "div" ) ;
Newbutton . id = button ;
Newbutton . classList = "button" ;
unused _buttons . appendChild ( Newbutton ) ;
let NewbuttonIMG = document . createElement ( "div" ) ;
NewbuttonIMG . classList = "button_img" ;
Newbutton . appendChild ( NewbuttonIMG ) ;
} ) ;
}
function SaveToolbar ( ) {
let unused _buttons = [ ] ;
let toolbar = { } ;
let u = document . querySelectorAll ( "#toolbar_unused_buttons .button" ) ;
u . forEach ( function ( b ) {
unused _buttons . push ( b . id ) ;
} ) ;
let t = document . getElementById ( "toolbar" ) ;
t . childNodes . forEach ( function ( s ) {
toolbar [ s . id ] = [ ] ;
let t = document . querySelectorAll ( "#" + s . id + " .button" ) . forEach ( function ( b ) {
toolbar [ s . id ] . push ( b . id ) ;
} ) ;
} ) ;
chrome . storage . local . set ( { toolbar : toolbar } ) ;
chrome . storage . local . set ( { unused _buttons : unused _buttons } ) ;
setTimeout ( function ( ) {
chrome . runtime . sendMessage ( { command : "reload_toolbar" , toolbar : toolbar , opt : opt } ) ;
} , 50 ) ;
}
// ASSIGN MOUSE EVENTS FOR TOOLBAR BUTTONS, (Buttons AND ToolbarShelfToggle), PARAMETERS DECIDE IF BUTTONS ARE CLICKABLE
2018-03-13 14:39:34 +01:00
// IN OPTIONS PAGE - TOOLBAR BUTTONS SAMPLES, MUST NOT CALL FUNCTIONS ON CLICKS, BUT STILL SHELFS BUTTONS MUST TOGGLE AND MOREOVER ON CLICK AND NOT ON MOUSEDOWN THIS IS WHERE ToolbarShelfToggleClickType="Click" IS NECESSARY
function SetToolbarEvents ( CleanPreviousBindings , Buttons , ToolbarShelfToggle , ToolbarShelfToggleClickType ) {
2017-07-26 22:23:39 +02:00
2018-03-13 14:39:34 +01:00
let ClearSearch = document . getElementById ( "button_filter_clear" ) ;
let FilterBox = document . getElementById ( "filter_box" ) ;
if ( ClearSearch != null && FilterBox != null ) {
if ( CleanPreviousBindings ) {
FilterBox . removeEventListener ( "oninput" , function ( ) { } ) ;
ClearSearch . removeEventListener ( "onmousedown" , function ( ) { } ) ;
}
if ( Buttons ) {
// FILTER ON INPUT
FilterBox . oninput = function ( event ) {
FindTab ( this . value ) ;
}
// CLEAR FILTER BUTTON
ClearSearch . onmousedown = function ( event ) {
if ( event . which == 1 ) {
this . style . opacity = "0" ;
this . style . opacity = "0" ;
this . setAttribute ( "title" , "" ) ;
FindTab ( "" ) ;
}
}
2017-07-26 22:23:39 +02:00
}
2018-03-13 14:39:34 +01:00
}
document . querySelectorAll ( ".button" ) . forEach ( function ( s ) {
2017-11-12 22:00:40 +01:00
2018-03-13 14:39:34 +01:00
if ( CleanPreviousBindings ) {
s . removeEventListener ( "onmousedown" , function ( ) { } ) ;
s . removeEventListener ( "onclick" , function ( ) { } ) ;
s . removeEventListener ( "click" , function ( ) { } ) ;
}
if ( ToolbarShelfToggle ) {
if ( s . id == "button_search" ) {
s . addEventListener ( ToolbarShelfToggleClickType , function ( event ) {
if ( event . which == 1 ) {
ShelfToggle ( event . which , this , "toolbar_search" , "search" ) ;
}
} ) ;
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
if ( s . id == "button_tools" ) {
s . addEventListener ( ToolbarShelfToggleClickType , function ( event ) {
if ( event . which == 1 ) {
ShelfToggle ( event . which , this , "toolbar_shelf_tools" , "tools" ) ;
}
} ) ;
}
if ( s . id == "button_groups" ) {
s . addEventListener ( ToolbarShelfToggleClickType , function ( event ) {
if ( event . which == 1 ) {
ShelfToggle ( event . which , this , "toolbar_shelf_groups" , "groups" ) ;
}
} ) ;
}
if ( s . id == "button_backup" ) {
s . addEventListener ( ToolbarShelfToggleClickType , function ( event ) {
if ( event . which == 1 ) {
ShelfToggle ( event . which , this , "toolbar_shelf_backup" , "backup" ) ;
}
} ) ;
}
if ( s . id == "button_folders" ) {
s . addEventListener ( ToolbarShelfToggleClickType , function ( event ) {
if ( event . which == 1 ) {
ShelfToggle ( event . which , this , "toolbar_shelf_folders" , "folders" ) ;
}
} ) ;
2017-11-12 22:00:40 +01:00
}
2017-07-26 22:23:39 +02:00
}
2018-03-13 14:39:34 +01:00
if ( Buttons ) {
// NEW TAB
if ( s . id == "button_new" ) {
s . onclick = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
OpenNewTab ( false , tt . active _group ) ;
2018-03-13 14:39:34 +01:00
}
}
s . onmousedown = function ( event ) {
// DUPLICATE TAB
if ( event . which == 2 ) {
event . preventDefault ( ) ;
2018-07-03 20:36:38 +02:00
let activeTab = document . querySelector ( "#" + tt . active _group + " .active_tab" ) != null ? document . querySelector ( "#" + tt . active _group + " .active_tab" ) : document . querySelector ( ".pin.active_tab" ) != null ? document . querySelector ( ".pin.active_tab" ) : null ;
2018-03-13 14:39:34 +01:00
if ( activeTab != null ) {
2018-05-22 02:11:29 +02:00
DuplicateTab ( activeTab ) ;
}
2018-03-13 14:39:34 +01:00
}
// SCROLL TO TAB
if ( event . which == 3 ) {
2018-05-22 02:11:29 +02:00
chrome . tabs . query ( { currentWindow : true , active : true } , function ( activeTab ) {
if ( activeTab [ 0 ] . pinned && opt . pin _list _multi _row == false ) {
ScrollToTab ( activeTab [ 0 ] . id ) ;
}
if ( activeTab [ 0 ] . pinned == false ) {
let Tab = document . getElementById ( activeTab [ 0 ] . id ) ;
let groupId = GetParentsByClass ( Tab , "group" ) [ 0 ] . id ;
SetActiveGroup ( groupId , true , true ) ;
}
} ) ;
2018-03-13 14:39:34 +01:00
}
2018-01-01 19:50:56 +01:00
}
2017-07-26 22:23:39 +02:00
}
2018-03-13 14:39:34 +01:00
// PIN TAB
if ( s . id == "button_pin" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
let Tabs = document . querySelectorAll ( ".pin.active_tab, .pin.selected_tab, #" + tt . active _group + " .active_tab, #" + tt . active _group + " .selected_tab" ) ;
2018-03-13 14:39:34 +01:00
Tabs . forEach ( function ( s ) {
chrome . tabs . update ( parseInt ( s . id ) , { pinned : Tabs [ 0 ] . classList . contains ( "tab" ) } ) ;
} )
}
}
2018-01-01 19:50:56 +01:00
}
2018-03-13 14:39:34 +01:00
// VERTICAL TABS OPTIONS
if ( s . id == "button_options" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
chrome . tabs . create ( { url : "options.html" } ) ;
}
}
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
// UNDO CLOSE
if ( s . id == "button_undo" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
chrome . sessions . getRecentlyClosed ( null , function ( sessions ) {
if ( sessions . length > 0 ) {
chrome . sessions . restore ( null , function ( restored ) { } ) ;
}
} ) ;
}
}
}
2017-11-12 22:00:40 +01:00
2018-03-13 14:39:34 +01:00
// MOVE TAB TO NEW WINDOW (DETACH)
2018-07-03 20:36:38 +02:00
if ( s . id == "button_detach" || s . id == "button_move" ) { // move is legacy name of detach button
2018-03-13 14:39:34 +01:00
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
if ( document . querySelectorAll ( "#" + tt . active _group + " .selected_folder" ) . length > 0 ) {
2018-03-13 14:39:34 +01:00
let detach = GetSelectedFolders ( ) ;
Detach ( detach . TabsIds , detach . Folders ) ;
} else {
let tabsArr = [ ] ;
2018-07-03 20:36:38 +02:00
document . querySelectorAll ( ".pin.selected_tab, .pin.active_tab, #" + tt . active _group + " .selected_tab, #" + tt . active _group + " .active_tab" ) . forEach ( function ( s ) {
2018-03-13 14:39:34 +01:00
tabsArr . push ( parseInt ( s . id ) ) ;
2018-05-22 02:11:29 +02:00
if ( s . childNodes [ 1 ] . childNodes . length > 0 ) {
document . querySelectorAll ( "#" + s . childNodes [ 1 ] . id + " .tab" ) . forEach ( function ( t ) {
2018-03-13 14:39:34 +01:00
tabsArr . push ( parseInt ( t . id ) ) ;
} ) ;
}
} ) ;
Detach ( tabsArr ) ;
}
}
}
}
2017-11-12 22:00:40 +01:00
2018-03-13 14:39:34 +01:00
// GO TO PREVIOUS SEARCH RESULT
if ( s . id == "filter_search_go_prev" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
let filtered = document . querySelectorAll ( "#" + tt . active _group + " .tab.filtered" ) ;
2018-03-13 14:39:34 +01:00
if ( filtered . length > 0 ) {
document . querySelectorAll ( ".highlighted_search" ) . forEach ( function ( s ) {
s . classList . remove ( "highlighted_search" ) ;
} ) ;
2018-07-03 20:36:38 +02:00
if ( tt . SearchIndex == 0 ) {
tt . SearchIndex = filtered . length - 1 ;
2018-03-13 14:39:34 +01:00
} else {
2018-07-03 20:36:38 +02:00
tt . SearchIndex -- ;
2018-03-13 14:39:34 +01:00
}
2018-07-03 20:36:38 +02:00
filtered [ tt . SearchIndex ] . classList . add ( "highlighted_search" ) ;
ScrollToTab ( filtered [ tt . SearchIndex ] . id ) ;
2018-03-13 14:39:34 +01:00
}
}
}
2018-01-01 19:50:56 +01:00
}
2018-03-13 14:39:34 +01:00
// GO TO NEXT SEARCH RESULT
if ( s . id == "filter_search_go_next" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
let filtered = document . querySelectorAll ( "#" + tt . active _group + " .tab.filtered" ) ;
2018-03-13 14:39:34 +01:00
if ( filtered . length > 0 ) {
document . querySelectorAll ( ".highlighted_search" ) . forEach ( function ( s ) {
s . classList . remove ( "highlighted_search" ) ;
} ) ;
2018-07-03 20:36:38 +02:00
if ( tt . SearchIndex == filtered . length - 1 ) {
tt . SearchIndex = 0 ;
2018-03-13 14:39:34 +01:00
} else {
2018-07-03 20:36:38 +02:00
tt . SearchIndex ++ ;
2018-03-13 14:39:34 +01:00
}
2018-07-03 20:36:38 +02:00
filtered [ tt . SearchIndex ] . classList . add ( "highlighted_search" ) ;
ScrollToTab ( filtered [ tt . SearchIndex ] . id ) ;
2018-03-13 14:39:34 +01:00
}
}
}
2017-11-20 18:14:07 +01:00
}
2018-05-22 02:11:29 +02:00
// SHOW/HIDE GROUPS TOOLBAR
if ( s . id == "button_groups_toolbar_hide" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
GroupsToolbarToggle ( ) ;
}
}
}
// SHOW GROUP MANAGER
if ( s . id == "button_manager_window" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 && document . getElementById ( "manager_window" ) . style . top == "-500px" ) {
OpenManagerWindow ( ) ;
} else {
HideRenameDialogs ( ) ;
}
}
}
2018-03-13 14:39:34 +01:00
// NEW GROUP
if ( s . id == "button_new_group" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
AddNewGroup ( ) ;
}
}
2018-01-01 19:50:56 +01:00
}
2018-03-13 14:39:34 +01:00
// REMOVE GROUP
if ( s . id == "button_remove_group" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
if ( tt . active _group != "tab_list" ) {
GroupRemove ( tt . active _group , event . shiftKey ) ;
2018-03-13 14:39:34 +01:00
}
}
}
2018-01-01 19:50:56 +01:00
}
2018-03-13 14:39:34 +01:00
// EDIT GROUP
if ( s . id == "button_edit_group" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
if ( tt . active _group != "tab_list" ) {
ShowGroupEditWindow ( tt . active _group ) ;
2018-03-13 14:39:34 +01:00
}
}
}
}
// EXPORT GROUP
if ( s . id == "button_export_group" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
ExportGroup ( tt . active _group , tt . groups [ tt . active _group ] . name , false ) ;
2018-03-13 14:39:34 +01:00
}
}
}
// IMPORT GROUP
if ( s . id == "button_import_group" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-05-22 02:11:29 +02:00
let inputFile = ShowOpenFileDialog ( ".tt_group" ) ;
2018-03-13 14:39:34 +01:00
inputFile . onchange = function ( event ) {
2018-05-22 02:11:29 +02:00
ImportGroup ( true , false ) ;
2018-03-13 14:39:34 +01:00
}
}
}
2017-11-20 18:14:07 +01:00
}
2017-11-12 22:00:40 +01:00
2018-03-13 14:39:34 +01:00
// NEW FOLDER
if ( s . id == "button_new_folder" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
let FolderId = AddNewFolder ( { SetEvents : true } ) ;
ShowRenameFolderDialog ( FolderId ) ;
2018-03-13 14:39:34 +01:00
}
}
}
// RENAME FOLDER
if ( s . id == "button_edit_folder" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
if ( document . querySelectorAll ( "#" + tt . active _group + " .selected_folder" ) . length > 0 ) {
ShowRenameFolderDialog ( document . querySelectorAll ( "#" + tt . active _group + " .selected_folder" ) [ 0 ] . id ) ;
2018-03-13 14:39:34 +01:00
}
}
}
}
// REMOVE FOLDERS
if ( s . id == "button_remove_folder" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
document . querySelectorAll ( "#" + tt . active _group + " .selected_folder" ) . forEach ( function ( s ) {
2018-03-13 14:39:34 +01:00
RemoveFolder ( s . id ) ;
} ) ;
}
}
}
// DISCARD TABS
if ( s . id == "button_unload" || s . id == "button_discard" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-07-03 20:36:38 +02:00
if ( document . querySelectorAll ( ".pin.selected_tab:not(.active_tab), #" + tt . active _group + " .selected_tab:not(.active_tab)" ) . length > 0 ) {
2018-03-13 14:39:34 +01:00
DiscardTabs (
2018-07-03 20:36:38 +02:00
Array . prototype . map . call ( document . querySelectorAll ( ".pin:not(.active_tab), #" + tt . active _group + " .selected_tab:not(.active_tab)" ) , function ( s ) {
2018-03-13 14:39:34 +01:00
return parseInt ( s . id ) ;
} )
) ;
} else {
DiscardTabs (
Array . prototype . map . call ( document . querySelectorAll ( ".pin:not(.active_tab), .tab:not(.active_tab)" ) , function ( s ) {
return parseInt ( s . id ) ;
} )
) ;
}
}
}
}
// IMPORT BACKUP
if ( s . id == "button_import_bak" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-05-22 02:11:29 +02:00
let inputFile = ShowOpenFileDialog ( ".tt_session" ) ;
2018-03-13 14:39:34 +01:00
inputFile . onchange = function ( event ) {
2018-05-22 02:11:29 +02:00
ImportSession ( true , false , false ) ;
2018-03-13 14:39:34 +01:00
}
}
}
}
// EXPORT BACKUP
if ( s . id == "button_export_bak" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-05-22 02:11:29 +02:00
let d = new Date ( ) ;
2018-07-03 20:36:38 +02:00
ExportSession ( ( d . toLocaleString ( ) . replace ( "/" , "." ) . replace ( "/" , "." ) . replace ( ":" , "꞉ " ) . replace ( ":" , "꞉ " ) ) , true , false , false ) ;
2018-03-13 14:39:34 +01:00
}
}
}
// MERGE BACKUP
if ( s . id == "button_import_merge_bak" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
2018-05-22 02:11:29 +02:00
let inputFile = ShowOpenFileDialog ( ".tt_session" ) ;
2018-03-13 14:39:34 +01:00
inputFile . onchange = function ( event ) {
2018-05-22 02:11:29 +02:00
ImportSession ( false , false , true ) ;
// ImportMergeTabs();
2018-03-13 14:39:34 +01:00
}
}
}
}
2017-11-12 22:00:40 +01:00
2018-03-13 14:39:34 +01:00
// CHANGE FILTERING TYPE
if ( s . id == "button_filter_type" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
if ( this . classList . contains ( "url" ) ) {
this . classList . remove ( "url" ) ;
this . classList . add ( "title" ) ;
2018-07-03 20:36:38 +02:00
chrome . runtime . sendMessage ( { command : "set_search_filter" , search _filter : "title" , windowId : tt . CurrentWindowId } ) ;
2018-03-13 14:39:34 +01:00
} else {
this . classList . remove ( "title" ) ;
this . classList . add ( "url" ) ;
2018-07-03 20:36:38 +02:00
chrome . runtime . sendMessage ( { command : "set_search_filter" , search _filter : "url" , windowId : tt . CurrentWindowId } ) ;
2018-03-13 14:39:34 +01:00
}
FindTab ( document . getElementById ( "filter_box" ) . value ) ;
}
}
}
2018-05-22 02:11:29 +02:00
// EMERGENCY RELOAD
if ( s . id == "button_reboot" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
chrome . runtime . sendMessage ( { command : "reload" } ) ;
chrome . runtime . sendMessage ( { command : "reload_sidebar" } ) ;
location . reload ( ) ;
}
}
}
2018-03-13 14:39:34 +01:00
// SORT TABS
// if (s.id == "button_sort") {
// s.onmousedown = function(event) {
// if (event.which == 1) {
// SortTabs();
// }
// }
// }
// REPEAT SEARCH
// if (s.id == "repeat_search") {
// s.onmousedown = function(event) {
// if (event.which == 1) {
// FindTab(document.getElementById("filter_box").value);
// }
// }
// }
if ( browserId != "F" ) {
// BOOKMARKS
if ( s . id == "button_bookmarks" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
chrome . tabs . create ( { url : "chrome://bookmarks/" } ) ;
}
}
}
// DOWNLOADS
if ( s . id == "button_downloads" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
chrome . tabs . create ( { url : "chrome://downloads/" } ) ;
}
}
}
// HISTORY
if ( s . id == "button_history" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
chrome . tabs . create ( { url : "chrome://history/" } ) ;
}
}
}
// EXTENSIONS
if ( s . id == "button_extensions" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
chrome . tabs . create ( { url : "chrome://extensions" } ) ;
}
}
}
// SETTINGS
if ( s . id == "button_settings" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 ) {
chrome . tabs . create ( { url : "chrome://settings/" } ) ;
}
}
}
// LOAD BACKUPS
if ( s . id == "button_load_bak1" || s . id == "button_load_bak2" || s . id == "button_load_bak3" ) {
s . onmousedown = function ( event ) {
if ( event . which == 1 && this . classList . contains ( "disabled" ) == false ) {
let BakN = ( this . id ) . substr ( 15 ) ;
2018-05-22 02:11:29 +02:00
chrome . storage . local . get ( null , function ( storage ) {
if ( Object . keys ( storage [ "windows_BAK" + BakN ] ) . length > 0 ) { chrome . storage . local . set ( { "windows" : storage [ "windows_BAK" + BakN ] } ) ; }
if ( Object . keys ( storage [ "tabs_BAK" + BakN ] ) . length > 0 ) { chrome . storage . local . set ( { "tabs" : storage [ "tabs_BAK" + BakN ] } ) ; alert ( "Loaded backup" ) ; }
2018-03-13 14:39:34 +01:00
chrome . runtime . sendMessage ( { command : "reload" } ) ; chrome . runtime . sendMessage ( { command : "reload_sidebar" } ) ; location . reload ( ) ;
} ) ;
}
}
}
}
}
2017-11-12 22:00:40 +01:00
} ) ;
2017-07-26 22:23:39 +02:00
}