fix: remove usage of RegExp named capture group

Feature not supported by FireFox yet
This commit is contained in:
Maddison Hellstrom 2019-06-01 20:17:54 -07:00
parent 6b1ccc0288
commit 4e5064928d
1 changed files with 9 additions and 6 deletions

View File

@ -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)(?:\/(?<asin>\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)