1. add add temp condition button on the failed resources page.

2. fix the bug that `Allow inspecting proxy used for page elements via context menu.` did not work
This commit is contained in:
proxy.zeroomega 2024-09-15 23:03:12 +08:00
parent 986e3f8d09
commit c175be96ff
7 changed files with 51 additions and 25 deletions

View File

@ -14,6 +14,16 @@ options = null
chrome.runtime.onStartup.addListener ->
globalThis.isBrowserRestart = true
chrome.contextMenus.onClicked.addListener((info, tab) ->
options?.ready.then( ->
switch info.menuItemId
when 'inspectPage', 'inspectLink', 'inspectElement', 'inspectFrame'
options._inspect.inspect(info, tab)
)
)
upgradeMigrateFn = (details) ->
if details.reason is 'update'
manifest = chrome.runtime.getManifest()

View File

@ -5,8 +5,9 @@ window.UglifyJS_NoUnsafeEval = true
globalThis.zeroDetectModeCB = null
globalThis.startupCheck = undefined
createContextMenu = ->
chrome.contextMenus?.create({
initContextMenu = ->
chrome.contextMenus.removeAll()
chrome.contextMenus.create({
id: 'enableQuickSwitch'
title: chrome.i18n.getMessage('contextMenu_enableQuickSwitch')
type: 'checkbox'
@ -14,26 +15,15 @@ createContextMenu = ->
contexts: ["action"]
})
chrome.contextMenus?.create({
chrome.contextMenus.create({
id: 'reportIssue'
title: chrome.i18n.getMessage('popup_reportIssues')
contexts: ["action"]
})
initContextMenu()
chrome.runtime.onInstalled.addListener( ->
# We don't need this API. However its presence indicates that Chrome >= 35
# which provides info.checked we need in contextMenu callback.
# https://developer.chrome.com/extensions/contextMenus
if chrome.i18n.getUILanguage?
createContextMenu()
)
if browser?.proxy?.onRequest?
#firefox bug fix?
createContextMenu()
chrome.contextMenus?.onClicked.addListener((info, tab) ->
chrome.contextMenus.onClicked.addListener((info, tab) ->
switch info.menuItemId
when 'reportIssue'
OmegaDebug.reportIssue()

View File

@ -120,8 +120,8 @@ angular.module('omegaTarget', []).factory 'omegaTarget', ($q) ->
callBackground('applyProfile', name)
applyProfileNoReply: (name) ->
callBackgroundNoReply('applyProfile', name)
addTempRule: (domain, profileName) ->
callBackground('addTempRule', domain, profileName)
addTempRule: (domain, profileName, toggle) ->
callBackground('addTempRule', domain, profileName, toggle)
addCondition: (condition, profileName) ->
callBackground('addCondition', condition, profileName)
addProfile: (profile) ->

View File

@ -15,7 +15,6 @@ module.exports = class Inspect
return unless chrome.i18n.getUILanguage?
return if @_enabled
return
webResource = [
"http://*/*"
@ -37,7 +36,7 @@ module.exports = class Inspect
id: 'inspectFrame'
title: chrome.i18n.getMessage('contextMenu_inspectFrame')
contexts: ['frame']
onclick: @inspect.bind(this)
#onclick: @inspect.bind(this)
documentUrlPatterns: webResource
})
@ -45,7 +44,7 @@ module.exports = class Inspect
id: 'inspectLink'
title: chrome.i18n.getMessage('contextMenu_inspectLink')
contexts: ['link']
onclick: @inspect.bind(this)
#onclick: @inspect.bind(this)
targetUrlPatterns: webResource
})
@ -57,7 +56,7 @@ module.exports = class Inspect
'video'
'audio'
]
onclick: @inspect.bind(this)
#onclick: @inspect.bind(this)
targetUrlPatterns: webResource
})
@ -70,7 +69,7 @@ module.exports = class Inspect
@_enabled = false
propForMenuItem:
'inspectPage': 'pageUrl'
#'inspectPage': 'pageUrl'
'inspectFrame': 'frameUrl'
'inspectLink': 'linkUrl'
'inspectElement': 'srcUrl'

View File

@ -810,9 +810,13 @@ class Options
# Add a temp rule.
# @param {String} domain The domain for the temp rule.
# @param {String} profileName The profile to apply for the domain.
# @param {1, -1, undefined, null, 0}
# 1: force add temp rule;
# -1: force delete temp rule;
# 0, null or undefined : toggle it
# @returns {Promise} A promise which is fulfilled when the rule is applied.
###
addTempRule: (domain, profileName) ->
addTempRule: (domain, profileName, toggle) ->
@log.method('Options#addTempRule', this, arguments)
return Promise.resolve() if not @_currentProfileName
profile = OmegaPac.Profiles.byName(profileName, @_options)
@ -824,8 +828,14 @@ class Options
@_tempProfile.color = currentProfile.color
@_tempProfile.defaultProfileName = currentProfile.name
changed = 0
changed = 0 # 0: nothing change, 1 add or modified, -1 delete
rule = @_tempProfileRules[domain]
if toggle
if rule and toggle is 1
return Promise.resolve()
if not rule and toggle is -1
return Promise.resolve()
if rule and rule.profileName
if rule.profileName != profileName
key = OmegaPac.Profiles.nameAsKey(rule.profileName)

View File

@ -174,6 +174,18 @@ module.controller 'PopupCtrl', ($scope, $window, $q, omegaTarget,
omegaTarget.addCondition(conditions, profileName).then ->
omegaTarget.state('lastProfileNameForCondition', profileName)
refresh()
$scope.addTempConditionForDomains = (domains, profileName) ->
conditions = []
promises = []
for own domain, enabled of domains when enabled
promises.push(omegaTarget.addTempRule(
domain.substring(2),
profileName, 1)
)
Promise.all(promises).then ->
omegaTarget.state('lastProfileNameForCondition', profileName)
refresh()
$scope.validateProfileName =
conflict: '!$value || !availableProfiles["+" + $value]'

View File

@ -153,6 +153,11 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
div.condition-controls
button.btn.btn-default(type='button' ng-click='returnToMenu()')
| {{'dialog_cancel' | tr}}
button.btn.btn-default(
type='button'
ng-click='addTempConditionForDomains(domainsForCondition, profileForDomains)'
ng-show='!!currentProfileCanAddRule')
| {{'Add temp condition'}}
button.btn.btn-primary(type='submit' ng-show='!!currentProfileCanAddRule') {{'popup_addCondition' | tr}}
button.btn.btn-default.pull-right(type='button' ng-show='!currentProfileCanAddRule'
ng-click='openOptions("#/general")') {{'popup_configureMonitorWebRequests' | tr}}