diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 3296803..d4efb55 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -89,7 +89,7 @@ "message": "URL list to disable translation" }, "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": { diff --git a/src/content/components/TranslateContainer.js b/src/content/components/TranslateContainer.js index 822374f..2f4d307 100644 --- a/src/content/components/TranslateContainer.js +++ b/src/content/components/TranslateContainer.js @@ -106,8 +106,7 @@ export default class TranslateContainer extends Component { }; disableExtensionByUrlList = () => { - const disableUrlList = getSettings("disableUrlList"); - const disableUrls = disableUrlList.split("\n"); + const disableUrls = getSettings("disableUrlList").split("\n"); let pageUrl; try { pageUrl = top.location.href; @@ -115,10 +114,15 @@ export default class TranslateContainer extends Component { pageUrl = document.referrer; } - const isMatched = disableUrls.some(urlReg => { - if (urlReg.trim() === "") return false; - return RegExp("^" + urlReg.trim()).test(pageUrl); - }); + const matchesPageUrl = urlPattern => { + const pattern = urlPattern + .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(); };