add save rule button

This commit is contained in:
Gabe Yuan
2023-09-10 13:44:34 +08:00
parent e7a5e5dce1
commit 08c9d78d2a
2 changed files with 4 additions and 5 deletions

View File

@@ -144,7 +144,7 @@ export const checkRules = (rules) => {
export const saveRule = async (newRule) => {
const rules = await getRulesWithDefault();
const rule = rules.find((item) => isMatch(newRule.pattern, item.pattern));
if (rule) {
if (rule && rule.pattern !== GLOBAL_KEY) {
Object.assign(rule, { ...newRule, pattern: rule.pattern });
} else {
rules.unshift(newRule);

View File

@@ -80,14 +80,13 @@ export default function Popup({ setShowPopup, translator: tran }) {
const handleSaveRule = async () => {
try {
let pattern = window.location.host;
let host = window.location.host;
if (isExt) {
const tab = await getTabInfo();
const url = new URL(tab.url);
pattern = url.host;
host = url.host;
}
saveRule({ ...rule, pattern });
saveRule({ ...rule, pattern: host });
} catch (err) {
console.log("[save rule]", err);
}