From c175be96ffc7d8476894618adbd32b2ee0b52991 Mon Sep 17 00:00:00 2001 From: "proxy.zeroomega" Date: Sun, 15 Sep 2024 23:03:12 +0800 Subject: [PATCH] 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 --- .../src/coffee/background.coffee | 10 +++++++++ .../src/coffee/background_preload.coffee | 22 +++++-------------- .../src/coffee/omega_target_web.coffee | 4 ++-- .../src/module/inspect.coffee | 9 ++++---- omega-target/src/options.coffee | 14 ++++++++++-- omega-web/src/coffee/popup.coffee | 12 ++++++++++ omega-web/src/popup.jade | 5 +++++ 7 files changed, 51 insertions(+), 25 deletions(-) diff --git a/omega-target-chromium-extension/src/coffee/background.coffee b/omega-target-chromium-extension/src/coffee/background.coffee index db21023..1e37c6d 100644 --- a/omega-target-chromium-extension/src/coffee/background.coffee +++ b/omega-target-chromium-extension/src/coffee/background.coffee @@ -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() diff --git a/omega-target-chromium-extension/src/coffee/background_preload.coffee b/omega-target-chromium-extension/src/coffee/background_preload.coffee index 5ffe53b..0019d09 100644 --- a/omega-target-chromium-extension/src/coffee/background_preload.coffee +++ b/omega-target-chromium-extension/src/coffee/background_preload.coffee @@ -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() diff --git a/omega-target-chromium-extension/src/coffee/omega_target_web.coffee b/omega-target-chromium-extension/src/coffee/omega_target_web.coffee index cb64e24..445d13a 100644 --- a/omega-target-chromium-extension/src/coffee/omega_target_web.coffee +++ b/omega-target-chromium-extension/src/coffee/omega_target_web.coffee @@ -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) -> diff --git a/omega-target-chromium-extension/src/module/inspect.coffee b/omega-target-chromium-extension/src/module/inspect.coffee index 91da11b..0112c3d 100644 --- a/omega-target-chromium-extension/src/module/inspect.coffee +++ b/omega-target-chromium-extension/src/module/inspect.coffee @@ -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' diff --git a/omega-target/src/options.coffee b/omega-target/src/options.coffee index 6b24165..c654f9c 100644 --- a/omega-target/src/options.coffee +++ b/omega-target/src/options.coffee @@ -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) diff --git a/omega-web/src/coffee/popup.coffee b/omega-web/src/coffee/popup.coffee index c9810ca..76acd2a 100644 --- a/omega-web/src/coffee/popup.coffee +++ b/omega-web/src/coffee/popup.coffee @@ -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]' diff --git a/omega-web/src/popup.jade b/omega-web/src/popup.jade index 9557995..1f991a1 100644 --- a/omega-web/src/popup.jade +++ b/omega-web/src/popup.jade @@ -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}}