From aea9506ff31769ce0a358ba7828e430bdbd76973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ChangJin=20Wei=20=28=E9=AD=8F=E6=98=8C=E8=BF=9B=29?= Date: Thu, 25 Jun 2026 18:02:22 +0800 Subject: [PATCH] Append popup-added conditions to the end of switch rules Add an optional addToBottom parameter to addCondition and pass it from popup condition entry points so rules added from the popup are appended instead of prepended. Preserve the existing default behavior for other callers. --- .../src/coffee/omega_target_web.coffee | 4 ++-- .../src/js/omega_target_popup.js | 8 ++++++-- omega-target/src/options.coffee | 5 +++-- omega-web/src/coffee/popup.coffee | 4 ++-- omega-web/src/popup/network/js/url.js | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) 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 4e5ca6d86..eb58202ea 100644 --- a/omega-target-chromium-extension/src/coffee/omega_target_web.coffee +++ b/omega-target-chromium-extension/src/coffee/omega_target_web.coffee @@ -140,8 +140,8 @@ angular.module('omegaTarget', []).factory 'omegaTarget', ($q) -> callBackgroundNoReply('applyProfile', name) addTempRule: (domain, profileName, toggle) -> callBackground('addTempRule', domain, profileName, toggle) - addCondition: (condition, profileName) -> - callBackground('addCondition', condition, profileName) + addCondition: (condition, profileName, addToBottom) -> + callBackground('addCondition', condition, profileName, addToBottom) addProfile: (profile) -> callBackground('addProfile', profile).then omegaTarget.refresh setDefaultProfile: (profileName, defaultProfileName) -> diff --git a/omega-target-chromium-extension/src/js/omega_target_popup.js b/omega-target-chromium-extension/src/js/omega_target_popup.js index c95786132..a36c712eb 100644 --- a/omega-target-chromium-extension/src/js/omega_target_popup.js +++ b/omega-target-chromium-extension/src/js/omega_target_popup.js @@ -71,8 +71,12 @@ OmegaTargetPopup = { callBackgroundNoReply('setDefaultProfile', [profileName, defaultProfileName], cb); }, - addCondition: function(condition, profileName, cb){ - callBackground('addCondition', [condition, profileName], cb) + addCondition: function(condition, profileName, addToBottom, cb){ + if (typeof addToBottom == 'function') { + cb = addToBottom; + addToBottom = null; + } + callBackground('addCondition', [condition, profileName, addToBottom], cb) }, getTempRules: function(cb){ callBackground('getTempRules', [], cb); diff --git a/omega-target/src/options.coffee b/omega-target/src/options.coffee index 82a5a09d4..313a22cf0 100644 --- a/omega-target/src/options.coffee +++ b/omega-target/src/options.coffee @@ -998,9 +998,10 @@ class Options # Add a condition to the current active switch profile. # @param {Object.} cond The condition to add # @param {string>} profileName The name of the result profile of the rule. + # @param {boolean=} addToBottom Whether to append the rule to the end. # @returns {Promise} A promise which is fulfilled when the condition is saved. ### - addCondition: (condition, profileName) -> + addCondition: (condition, profileName, addToBottom) -> @log.method('Options#addCondition', this, arguments) return Promise.resolve() if not @_currentProfileName profile = OmegaPac.Profiles.byName(@_currentProfileName, @_options) @@ -1022,7 +1023,7 @@ class Options break - if @_options['-addConditionsToBottom'] + if addToBottom ? @_options['-addConditionsToBottom'] profile.rules.push({ condition: cond profileName: profileName diff --git a/omega-web/src/coffee/popup.coffee b/omega-web/src/coffee/popup.coffee index a5f127a62..ac6922c5e 100644 --- a/omega-web/src/coffee/popup.coffee +++ b/omega-web/src/coffee/popup.coffee @@ -163,7 +163,7 @@ module.controller 'PopupCtrl', ($scope, $window, $q, omegaTarget, refresh() $scope.addCondition = (condition, profileName) -> - omegaTarget.addCondition(condition, profileName).then -> + omegaTarget.addCondition(condition, profileName, true).then -> omegaTarget.state('lastProfileNameForCondition', profileName) refresh() @@ -174,7 +174,7 @@ module.controller 'PopupCtrl', ($scope, $window, $q, omegaTarget, conditionType: 'HostWildcardCondition' pattern: domain }) - omegaTarget.addCondition(conditions, profileName).then -> + omegaTarget.addCondition(conditions, profileName, true).then -> omegaTarget.state('lastProfileNameForCondition', profileName) refresh() diff --git a/omega-web/src/popup/network/js/url.js b/omega-web/src/popup/network/js/url.js index 827a11155..c5d39704a 100644 --- a/omega-web/src/popup/network/js/url.js +++ b/omega-web/src/popup/network/js/url.js @@ -316,7 +316,7 @@ export const initUrlCellDetail = async (cell) => { OmegaTargetPopup.addCondition([{ conditionType: 'HostWildcardCondition', pattern - }], profileName, ()=>{ + }], profileName, true, ()=>{ OmegaTargetPopup.setState('lastProfileNameForCondition', profileName, ()=>{ Toastify({ text: "Add condition success",