Allow wildcards in the URL list
This commit is contained in:
parent
bb85f59ef2
commit
6104cd7f55
|
@ -89,7 +89,7 @@
|
||||||
"message": "URL list to disable translation"
|
"message": "URL list to disable translation"
|
||||||
},
|
},
|
||||||
"disableUrlListCaptionLabel": {
|
"disableUrlListCaptionLabel": {
|
||||||
"message": "If the URL matches the list, translation on the web page is disabled. Please enter as a regular expression."
|
"message": "If the page URL matches the list, translation on the web page is disabled. The list allows \"*\" wildcards."
|
||||||
},
|
},
|
||||||
|
|
||||||
"toolbarLabel": {
|
"toolbarLabel": {
|
||||||
|
|
|
@ -106,8 +106,7 @@ export default class TranslateContainer extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
disableExtensionByUrlList = () => {
|
disableExtensionByUrlList = () => {
|
||||||
const disableUrlList = getSettings("disableUrlList");
|
const disableUrls = getSettings("disableUrlList").split("\n");
|
||||||
const disableUrls = disableUrlList.split("\n");
|
|
||||||
let pageUrl;
|
let pageUrl;
|
||||||
try {
|
try {
|
||||||
pageUrl = top.location.href;
|
pageUrl = top.location.href;
|
||||||
|
@ -115,10 +114,15 @@ export default class TranslateContainer extends Component {
|
||||||
pageUrl = document.referrer;
|
pageUrl = document.referrer;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isMatched = disableUrls.some(urlReg => {
|
const matchesPageUrl = urlPattern => {
|
||||||
if (urlReg.trim() === "") return false;
|
const pattern = urlPattern
|
||||||
return RegExp("^" + urlReg.trim()).test(pageUrl);
|
.trim()
|
||||||
});
|
.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, match => (match === "*" ? ".*" : "\\" + match));
|
||||||
|
if (pattern === "") return false;
|
||||||
|
return RegExp("^" + pattern + "$").test(pageUrl);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isMatched = disableUrls.some(matchesPageUrl);
|
||||||
if (isMatched) this.props.removeElement();
|
if (isMatched) this.props.removeElement();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue