Add option to enable/disable inspection in context menu. Fix #83.

This commit is contained in:
FelisCatus 2014-12-22 19:34:24 +08:00
parent 038b428619
commit 73886642bf
10 changed files with 53 additions and 4 deletions

View File

@ -157,6 +157,9 @@
"options_refreshOnProfileChange": { "options_refreshOnProfileChange": {
"message": "Refresh current tab on profile change." "message": "Refresh current tab on profile change."
}, },
"options_showInspectMenu": {
"message": "Allow inspecting proxy used for page elements via context menu."
},
"options_group_switchOptions": { "options_group_switchOptions": {
"message": "Switch Options" "message": "Switch Options"
}, },

View File

@ -157,6 +157,9 @@
"options_refreshOnProfileChange": { "options_refreshOnProfileChange": {
"message": "当更改情景模式时刷新当前标签" "message": "当更改情景模式时刷新当前标签"
}, },
"options_showInspectMenu": {
"message": "右键菜单中,可检查网页元素所使用的代理。"
},
"options_group_switchOptions": { "options_group_switchOptions": {
"message": "切换选项" "message": "切换选项"
}, },

View File

@ -157,6 +157,9 @@
"options_refreshOnProfileChange": { "options_refreshOnProfileChange": {
"message": "當更改情景模式時更新當前標籤" "message": "當更改情景模式時更新當前標籤"
}, },
"options_showInspectMenu": {
"message": "右鍵選單中,可檢查網頁元素所使用的代理。"
},
"options_group_switchOptions": { "options_group_switchOptions": {
"message": "切換選項" "message": "切換選項"
}, },

View File

@ -157,6 +157,9 @@
"options_refreshOnProfileChange": { "options_refreshOnProfileChange": {
"message": "當更改情景模式時重新整理當前標籤" "message": "當更改情景模式時重新整理當前標籤"
}, },
"options_showInspectMenu": {
"message": "右鍵選單中,可檢查網頁元素所使用的代理。"
},
"options_group_switchOptions": { "options_group_switchOptions": {
"message": "切換選項" "message": "切換選項"
}, },

View File

@ -143,7 +143,7 @@ if chrome.runtime.id != OmegaTargetCurrent.SwitchySharp.extId
tabs = new OmegaTargetCurrent.ChromeTabs(actionForUrl) tabs = new OmegaTargetCurrent.ChromeTabs(actionForUrl)
tabs.watch() tabs.watch()
inspect = new OmegaTargetCurrent.Inspect (url, tab) -> options._inspect = new OmegaTargetCurrent.Inspect (url, tab) ->
if url == tab.url if url == tab.url
options.clearBadge() options.clearBadge()
tabs.processTab(tab) tabs.processTab(tab)
@ -167,8 +167,6 @@ inspect = new OmegaTargetCurrent.Inspect (url, tab) ->
color: action.resultColor color: action.resultColor
}) })
inspect.register()
options.setProxyNotControllable(null) options.setProxyNotControllable(null)
timeout = null timeout = null

View File

@ -3,14 +3,16 @@ OmegaPac = OmegaTarget.OmegaPac
Promise = OmegaTarget.Promise Promise = OmegaTarget.Promise
module.exports = class Inspect module.exports = class Inspect
_enabled: false
constructor: (@onInspect) -> constructor: (@onInspect) ->
register: -> enable: ->
# We don't need this API. However its presence indicates that Chrome >= 35, # We don't need this API. However its presence indicates that Chrome >= 35,
# which provides the menuItemId we need in contextMenu callback. # which provides the menuItemId we need in contextMenu callback.
# https://developer.chrome.com/extensions/contextMenus # https://developer.chrome.com/extensions/contextMenus
return unless chrome.i18n.getUILanguage? return unless chrome.i18n.getUILanguage?
return if @_enabled
webResource = [ webResource = [
"http://*/*" "http://*/*"
@ -56,6 +58,14 @@ module.exports = class Inspect
targetUrlPatterns: webResource targetUrlPatterns: webResource
}) })
@_enabled = true
disable: ->
return unless @_enabled
for own menuId of @propForMenuItem
try chrome.contextMenus.remove(menuId)
@_enabled = false
propForMenuItem: propForMenuItem:
'inspectPage': 'pageUrl' 'inspectPage': 'pageUrl'
'inspectFrame': 'frameUrl' 'inspectFrame': 'frameUrl'

View File

@ -9,6 +9,7 @@ parseExternalProfile = require('./parse_external_profile')
ProxyAuth = require('./proxy_auth') ProxyAuth = require('./proxy_auth')
class ChromeOptions extends OmegaTarget.Options class ChromeOptions extends OmegaTarget.Options
_inspect: null
parseExternalProfile: (details) -> parseExternalProfile: (details) ->
parseExternalProfile(details, @_options, @_fixedProfileConfig.bind(this)) parseExternalProfile(details, @_options, @_fixedProfileConfig.bind(this))
@ -178,6 +179,14 @@ class ChromeOptions extends OmegaTarget.Options
chrome.browserAction.setPopup({popup: 'popup.html'}) chrome.browserAction.setPopup({popup: 'popup.html'})
Promise.resolve() Promise.resolve()
setInspect: (settings) ->
if @_inspect
if settings.showMenu
@_inspect.enable()
else
@_inspect.disable()
return Promise.resolve()
_alarms: null _alarms: null
schedule: (name, periodInMinutes, callback) -> schedule: (name, periodInMinutes, callback) ->
name = 'omega.' + name name = 'omega.' + name

View File

@ -6,6 +6,7 @@ module.exports = ->
"-quickSwitchProfiles": [] "-quickSwitchProfiles": []
"-revertProxyChanges": false "-revertProxyChanges": false
"-confirmDeletion": true "-confirmDeletion": true
"-showInspectMenu": true
"-downloadInterval": 1440 "-downloadInterval": 1440
"+proxy": "+proxy":
bypassList: [ bypassList: [

View File

@ -263,6 +263,12 @@ class Options
if changes['-downloadInterval']? if changes['-downloadInterval']?
@schedule 'updateProfile', @_options['-downloadInterval'], => @schedule 'updateProfile', @_options['-downloadInterval'], =>
@updateProfile() @updateProfile()
if changes['-showInspectMenu']? or changes == @_options
showMenu = @_options['-showInspectMenu']
if not showMenu?
showMenu = true
@_setOptions({'-showInspectMenu': true}, {persist: true})
@setInspect(showMenu: showMenu)
handler() handler()
@_storage.watch null, handler @_storage.watch null, handler
@ -281,6 +287,15 @@ class Options
else else
@setQuickSwitch(null) @setQuickSwitch(null)
###*
# Apply the settings related to element proxy inspection.
# In base class, this method is not implemented and will not do anything.
# @param {{}} settings
# @param {boolean} settings.showMenu Whether to show the menu or not
# @returns {Promise} A promise which is fulfilled when the settings apply
###
setInspect: -> Promise.resolve()
###* ###*
# @callback watchCallback # @callback watchCallback
# @param {Object.<string, {}>} changes A map from keys to values. # @param {Object.<string, {}>} changes A map from keys to values.

View File

@ -10,6 +10,10 @@ section.settings-group
label label
input#refresh-on-profile-change(type='checkbox' ng-model='options["-refreshOnProfileChange"]') input#refresh-on-profile-change(type='checkbox' ng-model='options["-refreshOnProfileChange"]')
span {{'options_refreshOnProfileChange' | tr}} span {{'options_refreshOnProfileChange' | tr}}
div.checkbox
label
input(type='checkbox' ng-model='options["-showInspectMenu"]')
span {{'options_showInspectMenu' | tr}}
section.settings-group section.settings-group
h3 {{'options_group_switchOptions' | tr}} h3 {{'options_group_switchOptions' | tr}}
div.form-group div.form-group