var app = {} var dial = { styles: {}, page: 1, maxpage: 1 }; window.onload = function(){ function initPage(){ browser.runtime.getBackgroundPage().then(function(page){ if(page.app.settings){ app = page.app; dial.initUI(); browser.runtime.onMessage.addListener(function(request, sender, sendResponse){ switch(request.command){ case 'SettingsChanged': if(app.settings){ dial.Head.removeChild(dial.Style); dial.Body.removeChild(dial.Grid); dial.initStyles(); dial.Grid = dial.initGrid('Grid', app.settings.grid, dial.Body); var url = new URL(window.location); dial.path = url.searchParams.get('path'); if(url.searchParams.get('path')) { dial.Node = app.getNode(app.settings.grid.node, dial.path + '/'); } else { dial.Node = app.getNode(app.settings.grid.node, '/'); } dial.Title.innerText = dial.Node.title; dial.populateGrid(dial.Grid, app.settings.grid, dial.Node); } break; case 'GridNodesSaved': if(app.settings) dial.populateGrid(dial.Grid, app.settings.grid, dial.Node); break; case 'GridNodeSaved': // request.gridNode if(app.settings) dial.populateGrid(dial.Grid, app.settings.grid, dial.Node); break; } }); } else{ setTimeout(initPage, 100); } }, function(){}); } initPage(); } window.onresize = function(){ if(app && app.settings) dial.updateGridLayout(dial.Grid, app.settings.grid, dial.styles.grid); } window.onwheel = function(ev){ if(app && app.settings){ if(ev.deltaY > 0){ if(dial.page < dial.maxpage){ dial.page += 1; dial.populateGrid(dial.Grid, app.settings.grid, dial.Node); } } else if(ev.deltaY < 0){ if(dial.page > 1){ dial.page -= 1; dial.populateGrid(dial.Grid, app.settings.grid, dial.Node); } } } } dial.initUI = function(){ dial.Head = document.getElementById('head'); dial.Title = document.getElementById('title'); dial.Body = document.getElementById('body'); dial.Body.setAttribute('contextmenu', 'page'); dial.Body.setAttribute('contextmenu', 'page'); dial.initStyles(); dial.initMenus(); dial.Grid = dial.initGrid('Grid', app.settings.grid, dial.Body); var url = new URL(window.location); dial.path = url.searchParams.get('path'); if(url.searchParams.get('path')) { dial.Node = app.getNode(app.settings.grid.node, dial.path + '/'); } else { dial.Node = app.getNode(app.settings.grid.node, '/'); } dial.Title.innerText = dial.Node.title; dial.populateGrid(dial.Grid, app.settings.grid, dial.Node); } dial.initStyles = function(){ dial.Style = document.createElement('style'), StyleSheet; document.head.appendChild(dial.Style); dial.styles.html = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('html { height: 100%; }')].style; dial.styles.body = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('body { user-select: none; -moz-user-select: none; display: flex; width: 100%; height: 100%; margin: 0px; padding: 0px; background-color: ' + app.settings.backgroundColor + '; background-image: ' + app.settings.backgroundImage + '; background-repeat: no-repeat; background-size: 100% 100%; }')].style; dial.styles.grid = {}; dial.styles.grid.grid = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid { border-collapse: collapse; margin: auto; }')].style; dial.styles.grid.cell = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td { margin: 0px; padding: 0px; }')].style; dial.styles.grid.link = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a { display: block; outline: none; overflow: hidden; text-decoration: none; margin: ' + app.settings.grid.cells.margin + 'px; border: 1px solid ' + app.settings.grid.cells.borderColor + '; border-radius: ' + app.settings.grid.cells.borderRadius + 'px; }')].style; //dial.styles.grid.linkHover = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a:hover { border-color: ' + app.settings.grid.cells.borderColorHover + '; border-radius: ' + app.settings.grid.cells.borderRadiusHover + 'px; }')].style; dial.styles.grid.linkHover = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a:hover { border-color: ' + app.settings.grid.cells.borderColorHover + '; margin: ' + app.settings.grid.cells.marginHover + 'px; border-radius: ' + app.settings.grid.cells.borderRadiusHover + 'px; }')].style; dial.styles.grid.linkPanel = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a>div:first-child { background-repeat: no-repeat; }')].style; dial.styles.grid.linkTitle = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a>div:last-child { height: ' + app.settings.grid.cells.titleHeight + 'px; font-size: ' + app.settings.grid.cells.titleFontSize + 'pt; font-family: ' + app.settings.grid.cells.titleFont + 'pt; text-align: center; overflow: hidden; color: ' + app.settings.grid.cells.titleColor + '; border-top: 1px solid ' + app.settings.grid.cells.borderColor + '; }')].style; dial.styles.grid.linkTitleHover = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a:hover>div:last-child { color: ' + app.settings.grid.cells.titleColorHover + '; border-top-color: ' + app.settings.grid.cells.borderColorHover + ' }')].style; dial.styles.grid.linkEmpty = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a.Empty { display: none; }')].style; dial.styles.grid.linkBack = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a.Back :first-child { background-image: url("' + app.settings.grid.cells.backIcon + '"); background-repeat: no-repeat; background-position: center center; }')].style; dial.styles.grid.linkFolder = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a.Folder :first-child { background-image: url("' + app.settings.grid.cells.folderIcon + '"); background-repeat: no-repeat; background-size: 100% 100%; }')].style; dial.styles.grid.linkBookmark = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a.Bookmark :first-child { background-repeat: no-repeat; background-size: 100% 100%; }')].style; dial.styles.grid.linkBookmarkLoading = dial.Style.sheet.cssRules[dial.Style.sheet.insertRule('.Grid td>a.BookmarkLoading :first-child { background-image: url("' + app.settings.grid.cells.loadingIcon + '"); background-repeat: no-repeat; background-position: center center; }')].style; } dial.initMenus = function(){ dial.PageMenu = document.createElement('menu'); dial.PageMenu.type = 'context'; dial.PageMenu.id = 'page' dial.PageMenuNew = document.createElement('menu'); dial.PageMenuNew.label = browser.i18n.getMessage("menuNew"); dial.PageMenuCreateBookmark = document.createElement('menuitem'); dial.PageMenuCreateBookmark.label = browser.i18n.getMessage("menuNewBookmark"); dial.PageMenuCreateBookmark.onclick = dial.createBookmark; dial.PageMenuCreateFolder = document.createElement('menuitem'); dial.PageMenuCreateFolder.label = browser.i18n.getMessage("menuNewFolder"); dial.PageMenuCreateFolder.onclick = dial.createFolder; dial.PageMenuSettings = document.createElement('menuitem'); dial.PageMenuSettings.label = browser.i18n.getMessage("menuSettings"); dial.PageMenuSettings.onclick = dial.editSettings; dial.PageMenu.appendChild(dial.PageMenuNew); dial.PageMenuNew.appendChild(dial.PageMenuCreateBookmark); dial.PageMenuNew.appendChild(dial.PageMenuCreateFolder); dial.PageMenu.appendChild(document.createElement('hr')); dial.PageMenu.appendChild(dial.PageMenuSettings); dial.Body.appendChild(dial.PageMenu); dial.ItemMenu = document.createElement('menu'); dial.ItemMenu.type = 'context'; dial.ItemMenu.id = 'item' dial.ItemMenuNew = document.createElement('menu'); dial.ItemMenuNew.label = browser.i18n.getMessage("menuNew"); dial.ItemMenuCreateBookmark = document.createElement('menuitem'); dial.ItemMenuCreateBookmark.label = browser.i18n.getMessage("menuNewBookmark"); dial.ItemMenuCreateBookmark.onclick = dial.createBookmark; dial.ItemMenuCreateFolder = document.createElement('menuitem'); dial.ItemMenuCreateFolder.label = browser.i18n.getMessage("menuNewFolder"); dial.ItemMenuCreateFolder.onclick = dial.createFolder; /* dial.ItemMenuEdit = document.createElement('menuitem'); dial.ItemMenuEdit.label = 'Edit'; //dial.ItemMenuEdit.onclick = dial.test; */ dial.ItemMenuRefresh = document.createElement('menuitem'); dial.ItemMenuRefresh.label = browser.i18n.getMessage("menuRefreshItem"); dial.ItemMenuRefresh.onclick = dial.refreshNode; dial.ItemMenuCapture = document.createElement('menuitem'); dial.ItemMenuCapture.label = browser.i18n.getMessage("menuCapturePage"); dial.ItemMenuCapture.onclick = dial.capturePage; dial.ItemMenuDelete = document.createElement('menuitem'); dial.ItemMenuDelete.label = browser.i18n.getMessage("menuDeleteItem"); dial.ItemMenuDelete.onclick = dial.deleteNode; dial.ItemMenuSettings = document.createElement('menuitem'); dial.ItemMenuSettings.label = browser.i18n.getMessage("menuSettings"); dial.ItemMenuSettings.onclick = dial.editSettings; dial.ItemMenu.appendChild(dial.ItemMenuNew); dial.ItemMenuNew.appendChild(dial.ItemMenuCreateBookmark); dial.ItemMenuNew.appendChild(dial.ItemMenuCreateFolder); dial.ItemMenu.appendChild(document.createElement('hr')); //dial.ItemMenu.appendChild(dial.ItemMenuEdit); dial.ItemMenu.appendChild(dial.ItemMenuRefresh); dial.ItemMenu.appendChild(dial.ItemMenuCapture); dial.ItemMenu.appendChild(dial.ItemMenuDelete); dial.ItemMenu.appendChild(document.createElement('hr')); dial.ItemMenu.appendChild(dial.ItemMenuSettings); dial.Body.appendChild(dial.ItemMenu); } dial.initGrid = function(name, settings, container){ var grid = document.createElement('table'); grid.className = name; grid.getLink = function(index){ var num_columns = grid.rows[0].cells.length; return grid.rows[Math.floor(index/num_columns)].cells[index % num_columns].childNodes[0]; } for(var i=0; i dial.maxpage) dial.page = dial.maxpage; if(dial.page > 1) iBase = (dial.page -1) * maxCells; for(var i = iBase; i