diff --git a/README.md b/README.md index eae923a..d49be0b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ # PopupWindow -Firefox add-on, move tab to standalone window, without tabs bar, navigation bar and bookmark bar UI. +WebExtensions API add-on for moving a tab to standalone window, without tabs bar, navigation bar and bookmark bar UI. + +* Install Firefox add-on: [PopupWindow on addons.mozilla.org](https://addons.mozilla.org/firefox/addon/popup-window/) +* Install Chrome extension: [PopupWindow in Chrome Web Store](https://chrome.google.com/webstore/detail/popup-window/nnlippelgfbglbhiccffmnmlnhmbjjpe) + +# WebAppMode (WAM) +If you want to auto-enable the PopupWindow for specific web pages on FireFox, you can _additional_ install the co-add-on [https://github.com/ettoolong/WebAppMode](WebAppMode). + +* Install Firefox add-on: [WepAppMode on addons.mozilla.org](https://addons.mozilla.org/de/firefox/addon/web-app-mode/) + +# Contributing +For updating/creating language translations please create a pull request; for new languages please start with [this file](https://github.com/ettoolong/PopupWindow/blob/master/_locales/en/messages.json) and translate it, storing it with the appropriate language tag (for a list of tags, see [here](https://developer.chrome.com/docs/webstore/i18n/?localeTable#choosing-locales-to-support)). diff --git a/_locales/en/messages.json b/_locales/en/messages.json index c6bfc5d..9fbb5ed 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1,74 +1,98 @@ { - "extName": { - "message": "Popup window", - "description": "" - }, - "extDescription": { - "message": "Move tab to standalone window, without tabs bar, navigation bar and bookmark bar UI.", - "description": "" - }, - "optionPageTitle": { - "message": "Pop-up window Preferences", - "description": "" - }, + "extName": { + "message": "Popup window", + "description": "" + }, + "extDescription": { + "message": "Move tab to standalone window, without tabs bar, navigation bar and bookmark bar UI.", + "description": "" + }, + "optionPageTitle": { + "message": "Pop-up window Preferences", + "description": "" + }, "actionButtonTitle": { - "message": "Move current tab to pop-up window", - "description": "" + "message": "Move current tab to pop-up window", + "description": "" }, "contextMenuItems": { - "message": "Context menu items:", - "description": "" - }, + "message": "Context menu items:", + "description": "" + }, "tabMenu": { - "message": "Tab menu item", - "description": "" - }, - "openThisLink": { - "message": "Open this link in pop-up window", - "description": "" - }, - "moveThisPage": { - "message": "pop-up/merge current page", - "description": "" - }, - "moveThisTab": { - "message": "Move current tab to pop-up window", - "description": "" - }, - "defaultPosition": { - "message": "Default pop-up window position", - "description": "" - }, + "message": "Tab menu item", + "description": "" + }, + "openThisLink": { + "message": "Open this link in pop-up window", + "description": "" + }, + "moveThisPage": { + "message": "pop-up/merge current page", + "description": "" + }, + "moveThisTab": { + "message": "Move current tab to pop-up window", + "description": "" + }, + "defaultPosition": { + "message": "Default pop-up window position", + "description": "" + }, "center": { - "message": "Center", - "description": "" + "message": "Center", + "description": "" }, "topLeft": { - "message": "Top left corner", - "description": "" + "message": "Top left corner", + "description": "" }, "bottomLeft": { - "message": "Bottom left corner", - "description": "" + "message": "Bottom left corner", + "description": "" }, "topRight": { - "message": "Top right corner", - "description": "" + "message": "Top right corner", + "description": "" }, "bottomRight": { - "message": "Bottom right corner", - "description": "" - }, - "iconColor": { - "message": "Toolbar button icon color", - "description": "" - }, - "iconColorBlack": { - "message": "Black", - "description": "" - }, - "iconColorWhite": { - "message": "White", - "description": "" - } + "message": "Bottom right corner", + "description": "" + }, + "customPosition": { + "message": "Custom position", + "description": "" + }, + "windowPositionLeft": { + "message": "Left", + "description": "" + }, + "windowPositionTop": { + "message": "Top", + "description": "" + }, + "windowWidth": { + "message": "Default pop-up window width", + "description": "" + }, + "windowHeight": { + "message": "Default pop-up window height", + "description": "" + }, + "iconColor": { + "message": "Toolbar button icon color", + "description": "" + }, + "iconColorBlack": { + "message": "Black", + "description": "" + }, + "iconColorWhite": { + "message": "White", + "description": "" + }, + "execute": { + "message": "Pop-up/Merge page", + "description": "" + } } diff --git a/_locales/zh_TW/messages.json b/_locales/zh_TW/messages.json index 9a82555..5268bb2 100644 --- a/_locales/zh_TW/messages.json +++ b/_locales/zh_TW/messages.json @@ -1,74 +1,98 @@ { - "extName": { - "message": "Popup window", - "description": "" - }, - "extDescription": { - "message": "將 Tab 彈出至獨立視窗,去除頁籤列、網址列和書籤列等介面", - "description": "" - }, - "optionPageTitle": { - "message": "Popup window 設定頁", - "description": "" + "extName": { + "message": "Popup window", + "description": "" + }, + "extDescription": { + "message": "將 Tab 彈出至獨立視窗,去除頁籤列、網址列和書籤列等介面", + "description": "" + }, + "optionPageTitle": { + "message": "Popup window 設定頁", + "description": "" }, "actionButtonTitle": { - "message": "將目前分頁彈出至獨立視窗", - "description": "" + "message": "將目前分頁彈出至獨立視窗", + "description": "" }, "contextMenuItems": { - "message": "右鍵選單項目:", - "description": "" - }, + "message": "右鍵選單項目:", + "description": "" + }, "tabMenu": { - "message": "分頁右鍵選單", - "description": "" - }, - "openThisLink": { - "message": "將此連結彈出至獨立視窗", - "description": "" - }, - "moveThisPage": { - "message": "彈出/合併 目前頁面", - "description": "" - }, - "moveThisTab": { - "message": "將目前分頁彈出至獨立視窗", - "description": "" - }, - "defaultPosition": { - "message": "預設視窗位置", - "description": "" - }, + "message": "分頁右鍵選單", + "description": "" + }, + "openThisLink": { + "message": "將此連結彈出至獨立視窗", + "description": "" + }, + "moveThisPage": { + "message": "彈出/合併 目前頁面", + "description": "" + }, + "moveThisTab": { + "message": "將目前分頁彈出至獨立視窗", + "description": "" + }, + "defaultPosition": { + "message": "預設視窗位置", + "description": "" + }, "center": { - "message": "螢幕中央", - "description": "" + "message": "螢幕中央", + "description": "" }, "topLeft": { - "message": "左上角", - "description": "" + "message": "左上角", + "description": "" }, "bottomLeft": { - "message": "左下角", - "description": "" + "message": "左下角", + "description": "" }, "topRight": { - "message": "右上角", - "description": "" + "message": "右上角", + "description": "" }, "bottomRight": { - "message": "右下角", - "description": "" - }, - "iconColor": { - "message": "工具列圖示顏色", - "description": "" - }, - "iconColorBlack": { - "message": "黑", - "description": "" - }, - "iconColorWhite": { - "message": "白", - "description": "" - } + "message": "右下角", + "description": "" + }, + "customPosition": { + "message": "自訂位置", + "description": "" + }, + "windowPositionLeft": { + "message": "左", + "description": "" + }, + "windowPositionTop": { + "message": "上", + "description": "" + }, + "windowWidth": { + "message": "預設視窗寬度", + "description": "" + }, + "windowHeight": { + "message": "預設視窗高度", + "description": "" + }, + "iconColor": { + "message": "工具列圖示顏色", + "description": "" + }, + "iconColorBlack": { + "message": "黑", + "description": "" + }, + "iconColorWhite": { + "message": "白", + "description": "" + }, + "execute": { + "message": "彈出/合併 頁面", + "description": "" + } } diff --git a/background.js b/background.js index a7518d0..e6fbc4b 100644 --- a/background.js +++ b/background.js @@ -1,10 +1,14 @@ let defaultPreference = { defaultPosition: 0, + windowPositionLeft: 0, + windowPositionTop: 0, + windowWidth: 500, + windowHeight: 400, openThisLink: true, moveThisPage: true, moveThisTab: false, iconColor: 0, //0:black, 1:white - version: 2 + version: 4 }; let preferences = {}; let menu_openThisLink = null; @@ -61,6 +65,7 @@ const loadPreference = () => { } } if(needUpdate) { + update.version = defaultPreference.version; chrome.storage.local.set(update); } } @@ -94,7 +99,7 @@ const createContextMenu = (mode) => { }; const resetContextMenu = (type) => { - if (preferences.moveThisTab) { + if (preferences.moveThisPage) { createContextMenu(type); } else { if(menu_moveThisPage !== null) { @@ -167,10 +172,10 @@ const setBrowserActionIcon = () => { } }; -const popupWindow = (tab, targetUrl) => { +const popupWindow = (tab, targetUrl, winLeft, winTop, winWidth, winHeight) => { let screen = window.screen; - let width = 500; - let height = 400; + let width = winWidth ?? preferences.windowWidth; + let height = winHeight ?? preferences.windowHeight; let top = screen.availTop !== undefined ? screen.availTop: screen.top; let left = screen.availLeft !== undefined ? screen.availLeft: screen.left; @@ -182,6 +187,10 @@ const popupWindow = (tab, targetUrl) => { top = sTop + Math.round((sHeight - height)/2); left = sLeft + Math.round((sWidth - width)/2); } + else if (preferences.defaultPosition === 5) { + top = preferences.windowPositionTop; + left = preferences.windowPositionLeft; + } else { if (preferences.defaultPosition === 2 || preferences.defaultPosition === 4) { top = sTop + sHeight - height; @@ -194,6 +203,13 @@ const popupWindow = (tab, targetUrl) => { left = sLeft; } } + if(winTop !== undefined) { + top = winTop; + } + if(winLeft !== undefined) { + left = winLeft; + } + let setting = { type: 'popup', top: top, @@ -307,12 +323,38 @@ window.addEventListener('DOMContentLoaded', event => { loadPreference(); }); +chrome.commands.onCommand.addListener(command => { + if (command === "popupWindow") { + chrome.windows.getCurrent(windowInfo => { + chrome.tabs.query({active: true, currentWindow: true}, tabs => { + if ((typeof tabs !== 'undefined') && (tabs.length > 0)) { + let tab = tabs[0]; + if(windowInfo.type === 'popup') { + let popup = popupMapping.get(windowInfo.id); + mergeWindow(tab, popup ? popup.originalWindowId: null); + } + else { + popupWindow(tab); + } + } + }); + }); + } +}); + const messageHandler = (message, sender, sendResponse) => { if(message.action === 'popupWindow') { chrome.tabs.get(message.tabId, tab => { - popupWindow(tab); + if(message.left && message.top) { + popupWindow(tab, null, message.left, message.top, message.width, message.height); + } else { + popupWindow(tab); + } }); } + else if(message.action === 'ack') { + sendResponse({result:'ok'}); + } }; chrome.runtime.onMessage.addListener(messageHandler); diff --git a/manifest.json b/manifest.json index 7c8ee69..a009928 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "description": "__MSG_extDescription__", "manifest_version": 2, "name": "__MSG_extName__", - "version": "0.0.3", + "version": "0.1.3", "homepage_url": "https://github.com/ettoolong/PopupWindow", "icons": { "16": "icon/icon.svg", @@ -14,7 +14,7 @@ "applications": { "gecko": { "id": "PopupWindow@ettoolong", - "strict_min_version": "53.0" + "strict_min_version": "66.0" } }, "developer": { @@ -26,7 +26,6 @@ }, "permissions": [ "storage", - "tabs", "contextMenus" ], "browser_action": { @@ -39,5 +38,10 @@ "page": "options.html", "open_in_tab": false, "browser_style": true + }, + "commands": { + "popupWindow": { + "description": "__MSG_execute__" + } } } diff --git a/options.css b/options.css index f787510..2c49a30 100644 --- a/options.css +++ b/options.css @@ -6,6 +6,7 @@ div.col { .itemDiv { display: block; margin-top:4px; + min-height: 24px; } .itemLabel { @@ -18,3 +19,19 @@ select.itemInput { width: 250px; margin-left:12px; } + +input.windowPosition { + width:70px; +} + +label.windowPosition { + margin-left: 6px; +} + +.hidden { + display: none; +} + +.show { + display: inline-block; +} diff --git a/options.html b/options.html index 35fa5c9..0c74e85 100644 --- a/options.html +++ b/options.html @@ -39,7 +39,21 @@ + + + + + + + +
+ + +
+
+ +
diff --git a/options.js b/options.js index 8c0a877..5c23d01 100644 --- a/options.js +++ b/options.js @@ -20,6 +20,11 @@ const handleVelueChange = id => { saveToPreference(id, parseInt(elem.value)); }); } + else if(elemType === 'number') { + elem.addEventListener('input', event => { + saveToPreference(id, parseInt(elem.value)); + }); + } else if(elemType === 'radioGroup') { let radios = Array.from(elem.querySelectorAll('input[name='+id+']')); for(let radio of radios) { @@ -48,6 +53,9 @@ const setValueToElem = (id, value) => { } } } + else if(elemType === 'number') { + elem.value = value; + } else if(elemType === 'radioGroup') { let radios = Array.from(elem.querySelectorAll('input[name='+id+']')); for(let radio of radios) { @@ -60,6 +68,23 @@ const setValueToElem = (id, value) => { } }; +const onDefaultPositionChange = () => { + let defaultPosition = document.getElementById('defaultPosition'); + let elems = Array.from(document.querySelectorAll('.windowPosition')); + + if(defaultPosition.value === '5') { + elems.forEach(tag => { + tag.classList.add('show'); + tag.classList.remove('hidden'); + }); + } else { + elems.forEach(tag => { + tag.classList.add('hidden'); + tag.classList.remove('show'); + }); + } +} + const init = preferences => { currentPrefs = preferences; for(let p in preferences) { @@ -70,6 +95,11 @@ const init = preferences => { l10nTags.forEach(tag => { tag.textContent = chrome.i18n.getMessage(tag.getAttribute('data-l10n-id')); }); + let defaultPosition = document.getElementById('defaultPosition'); + defaultPosition.addEventListener('change', event=>{ + onDefaultPositionChange(); + }); + onDefaultPositionChange(); }; window.addEventListener('load', event => {