diff --git a/CHANGELOG.md b/CHANGELOG.md index 9df5e91..76535e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### v1.1.1 8/1/2018 + + - feat: add an option to turn on the button of context menu in the page + - fix: do not await sync complete when access storage + ### v1.1.0 7/29/2018 - feat: add an operation to store all tabs in all windows (in context menus and keyboard shortcut) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 0cfcf17..b872230 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -53,6 +53,9 @@ "opt_desc_pinNewList": { "message": "Auto pin new list" }, + "opt_desc_pageContext": { + "message": "Turn on the button of context menu in the page" + }, "opt_desc_syncOptions": { "message": "Sync settings" }, @@ -173,4 +176,4 @@ "ui_title_down_btn": { "message": "move list down" } -} \ No newline at end of file +} diff --git a/src/_locales/zh_CN/messages.json b/src/_locales/zh_CN/messages.json index 9ee887e..a64ec11 100644 --- a/src/_locales/zh_CN/messages.json +++ b/src/_locales/zh_CN/messages.json @@ -50,6 +50,9 @@ "opt_desc_pinNewList": { "message": "自动固定新列表" }, + "opt_desc_pageContext": { + "message": "开启页面中的右键菜单中的按钮" + }, "opt_desc_addHistory": { "message": "将储存的标签加入浏览器历史记录中" }, @@ -173,4 +176,4 @@ "ui_title_down_btn": { "message": "向下移动列表" } -} \ No newline at end of file +} diff --git a/src/background.js b/src/background.js index 4f92887..54ff2cd 100644 --- a/src/background.js +++ b/src/background.js @@ -36,35 +36,24 @@ const updateBrowserAction = action => { } } -const setupContextMenus = () => { - browser.contextMenus.removeAll() - browser.contextMenus.create({ - id: 'STORE_SELECTED_TABS', - title: __('menu_STORE_SELECTED_TABS'), - contexts: ['browser_action'], - }) - browser.contextMenus.create({ - id: 'STORE_ALL_TABS_IN_CURRENT_WINDOW', - title: __('menu_STORE_ALL_TABS_IN_CURRENT_WINDOW'), - contexts: ['browser_action'], - }) - browser.contextMenus.create({ - id: 'SHOW_TAB_LIST', - title: __('menu_SHOW_TAB_LIST'), - contexts: ['browser_action'], - }) - browser.contextMenus.create({ - id: 'STORE_ALL_TABS_IN_ALL_WINDOWS', - title: __('menu_STORE_ALL_TABS_IN_ALL_WINDOWS'), - contexts: ['browser_action'], - }) - - window.contextMenusClickedHandler = info => { - if (info.menuItemId === 'STORE_SELECTED_TABS') tabs.storeSelectedTabs() - else if (info.menuItemId === 'STORE_ALL_TABS_IN_CURRENT_WINDOW') tabs.storeAllTabs() - else if (info.menuItemId === 'SHOW_TAB_LIST') tabs.openTabLists() - else if (info.menuItemId === 'STORE_ALL_TABS_IN_ALL_WINDOWS') tabs.storeAllTabInAllWindows() +const setupContextMenus = async pageContext => { + await browser.contextMenus.removeAll() + const contexts = ['browser_action'] + if (pageContext) contexts.push('page') + const menus = { + STORE_SELECTED_TABS: tabs.storeSelectedTabs, + STORE_ALL_TABS_IN_CURRENT_WINDOW: tabs.storeAllTabs, + SHOW_TAB_LIST: tabs.openTabLists, + STORE_ALL_TABS_IN_ALL_WINDOWS: tabs.storeAllTabInAllWindows, + } + for (const key of Object.keys(menus)) { + await browser.contextMenus.create({ + id: key, + title: __('menu_' + key), + contexts, + }) } + window.contextMenusClickedHandler = info => menus[info.menuItemId]() } const init = async () => { @@ -72,14 +61,15 @@ const init = async () => { _.defaults(opts, options.getDefaultOptions()) await storage.setOptions(opts) updateBrowserAction(opts.browserAction) - setupContextMenus() - browser.runtime.onMessage.addListener(msg => { + setupContextMenus(opts.pageContext) + browser.runtime.onMessage.addListener(async msg => { console.log(msg) if (msg.optionsChanged) { const changes = msg.optionsChanged console.log(changes) if (changes.browserAction) updateBrowserAction(changes.browserAction) - browser.runtime.sendMessage({optionsChangeHandledStatus: 'success'}) + if ('pageContext' in changes) await setupContextMenus(changes.pageContext) + await browser.runtime.sendMessage({optionsChangeHandledStatus: 'success'}) if (PRODUCTION) Object.keys(changes).map(key => ga('send', 'event', 'Options', key, changes[key])) } }) @@ -110,4 +100,4 @@ const init = async () => { }) } -init() \ No newline at end of file +init() diff --git a/src/common/options.js b/src/common/options.js index 8bee408..44fc4d4 100644 --- a/src/common/options.js +++ b/src/common/options.js @@ -107,6 +107,12 @@ export const optionsList = [ type: Boolean, default: false, }, + { + name: 'pageContext', + desc: __('opt_desc_pageContext'), + type: Boolean, + default: true, + }, { name: 'syncOptions', desc: __('opt_desc_syncOptions'), @@ -125,4 +131,4 @@ const getDefaultOptions = () => optionsList.reduce((opts, item) => { return Object.assign(opts, {[item.name]: item.default}) }, {}) -export default {getDefaultOptions, optionsList} \ No newline at end of file +export default {getDefaultOptions, optionsList} diff --git a/src/manifest.json b/src/manifest.json index f99eaff..300a9e0 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "__MSG_ext_name__", - "version": "1.1.0", + "version": "1.1.1", "default_locale": "en", "description": "__MSG_ext_desc__", "author": "WangJie ", @@ -53,4 +53,4 @@ "open_in_tab": true }, "content_security_policy": "script-src 'self' 'unsafe-eval' https://www.google-analytics.com; object-src 'self'" -} \ No newline at end of file +} diff --git a/src/page/Options.vue b/src/page/Options.vue index e739f0c..c403e99 100644 --- a/src/page/Options.vue +++ b/src/page/Options.vue @@ -55,6 +55,7 @@ import storage from '@/common/storage' import options from '@/common/options' import __ from '@/common/i18n' +import _ from 'lodash' export default { data() { @@ -70,7 +71,7 @@ export default { }, methods: { __, - async optionsChanged(key, value) { + optionsChanged: _.debounce(async function (key, value) { console.log(1) console.log(key, value) // when type of option is string options can not be set correctly after first storage.setOptions() called @@ -78,7 +79,7 @@ export default { await storage.setOptions(this.options) console.log(2) chrome.runtime.sendMessage({optionsChanged: {[key]: value}}) - }, + }, 100), async init() { const opts = await storage.getOptions() Object.keys(opts).map(key => {