add save rule button
This commit is contained in:
@@ -144,7 +144,7 @@ export const checkRules = (rules) => {
|
|||||||
export const saveRule = async (newRule) => {
|
export const saveRule = async (newRule) => {
|
||||||
const rules = await getRulesWithDefault();
|
const rules = await getRulesWithDefault();
|
||||||
const rule = rules.find((item) => isMatch(newRule.pattern, item.pattern));
|
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 });
|
Object.assign(rule, { ...newRule, pattern: rule.pattern });
|
||||||
} else {
|
} else {
|
||||||
rules.unshift(newRule);
|
rules.unshift(newRule);
|
||||||
|
|||||||
@@ -80,14 +80,13 @@ export default function Popup({ setShowPopup, translator: tran }) {
|
|||||||
|
|
||||||
const handleSaveRule = async () => {
|
const handleSaveRule = async () => {
|
||||||
try {
|
try {
|
||||||
let pattern = window.location.host;
|
let host = window.location.host;
|
||||||
if (isExt) {
|
if (isExt) {
|
||||||
const tab = await getTabInfo();
|
const tab = await getTabInfo();
|
||||||
const url = new URL(tab.url);
|
const url = new URL(tab.url);
|
||||||
pattern = url.host;
|
host = url.host;
|
||||||
}
|
}
|
||||||
|
saveRule({ ...rule, pattern: host });
|
||||||
saveRule({ ...rule, pattern });
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[save rule]", err);
|
console.log("[save rule]", err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user