diff --git a/actions.js b/actions.js index c9e88f5..b04e76b 100644 --- a/actions.js +++ b/actions.js @@ -98,25 +98,28 @@ actions.fakeSpot = (url = util.getCurrentLocation("href")) => actions.az = {} actions.az.viewProduct = () => { const reHost = /^([-\w]+[.])*amazon.\w+$/ - const rePath = /^(?:.*\/)*(?:dp|gp\/product)(?:\/(?\w{10})).*/ + const rePath = /^(?:.*\/)*(?:dp|gp\/product)(?:\/(\w{10})).*/ const elements = {} document.querySelectorAll("a[href]").forEach((a) => { const u = new URL(a.href) if (u.hash.length === 0 && reHost.test(u.hostname)) { const rePathRes = rePath.exec(u.pathname) - if (rePathRes === null) { + if (rePathRes === null || rePathRes.length !== 2) { return } if (!util.isElementInViewport(a)) { return } - if (elements[rePathRes.groups.asin] !== undefined) { - if (!(elements[rePathRes.groups.asin].text.trim().length === 0 - && a.text.trim().length > 0)) { + + const asin = rePathRes[1] + + if (elements[asin] !== undefined) { + if (!(elements[asin].text.trim().length === 0 && a.text.trim().length > 0)) { return } } - elements[rePathRes.groups.asin] = a + + elements[asin] = a } }) Hints.create(Object.values(elements), Hints.dispatchMouseClick)