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 -> chrome.runtime.onStartup.addListener ->
globalThis.isBrowserRestart = true 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) -> upgradeMigrateFn = (details) ->
if details.reason is 'update' if details.reason is 'update'
manifest = chrome.runtime.getManifest() manifest = chrome.runtime.getManifest()

View File

@ -5,8 +5,9 @@ window.UglifyJS_NoUnsafeEval = true
globalThis.zeroDetectModeCB = null globalThis.zeroDetectModeCB = null
globalThis.startupCheck = undefined globalThis.startupCheck = undefined
createContextMenu = -> initContextMenu = ->
chrome.contextMenus?.create({ chrome.contextMenus.removeAll()
chrome.contextMenus.create({
id: 'enableQuickSwitch' id: 'enableQuickSwitch'
title: chrome.i18n.getMessage('contextMenu_enableQuickSwitch') title: chrome.i18n.getMessage('contextMenu_enableQuickSwitch')
type: 'checkbox' type: 'checkbox'
@ -14,26 +15,15 @@ createContextMenu = ->
contexts: ["action"] contexts: ["action"]
}) })
chrome.contextMenus?.create({ chrome.contextMenus.create({
id: 'reportIssue' id: 'reportIssue'
title: chrome.i18n.getMessage('popup_reportIssues') title: chrome.i18n.getMessage('popup_reportIssues')
contexts: ["action"] contexts: ["action"]
}) })
initContextMenu()
chrome.runtime.onInstalled.addListener( -> chrome.contextMenus.onClicked.addListener((info, tab) ->
# 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) ->
switch info.menuItemId switch info.menuItemId
when 'reportIssue' when 'reportIssue'
OmegaDebug.reportIssue() OmegaDebug.reportIssue()

View File

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

View File

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

View File

@ -810,9 +810,13 @@ class Options
# Add a temp rule. # Add a temp rule.
# @param {String} domain The domain for the temp rule. # @param {String} domain The domain for the temp rule.
# @param {String} profileName The profile to apply for the domain. # @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. # @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) @log.method('Options#addTempRule', this, arguments)
return Promise.resolve() if not @_currentProfileName return Promise.resolve() if not @_currentProfileName
profile = OmegaPac.Profiles.byName(profileName, @_options) profile = OmegaPac.Profiles.byName(profileName, @_options)
@ -824,8 +828,14 @@ class Options
@_tempProfile.color = currentProfile.color @_tempProfile.color = currentProfile.color
@_tempProfile.defaultProfileName = currentProfile.name @_tempProfile.defaultProfileName = currentProfile.name
changed = 0 changed = 0 # 0: nothing change, 1 add or modified, -1 delete
rule = @_tempProfileRules[domain] 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 and rule.profileName
if rule.profileName != profileName if rule.profileName != profileName
key = OmegaPac.Profiles.nameAsKey(rule.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.addCondition(conditions, profileName).then ->
omegaTarget.state('lastProfileNameForCondition', profileName) omegaTarget.state('lastProfileNameForCondition', profileName)
refresh() 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 = $scope.validateProfileName =
conflict: '!$value || !availableProfiles["+" + $value]' conflict: '!$value || !availableProfiles["+" + $value]'

View File

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