fix: remove usage of RegExp named capture group
Feature not supported by FireFox yet
This commit is contained in:
parent
6b1ccc0288
commit
4e5064928d
15
actions.js
15
actions.js
|
@ -98,25 +98,28 @@ actions.fakeSpot = (url = util.getCurrentLocation("href")) =>
|
||||||
actions.az = {}
|
actions.az = {}
|
||||||
actions.az.viewProduct = () => {
|
actions.az.viewProduct = () => {
|
||||||
const reHost = /^([-\w]+[.])*amazon.\w+$/
|
const reHost = /^([-\w]+[.])*amazon.\w+$/
|
||||||
const rePath = /^(?:.*\/)*(?:dp|gp\/product)(?:\/(?<asin>\w{10})).*/
|
const rePath = /^(?:.*\/)*(?:dp|gp\/product)(?:\/(\w{10})).*/
|
||||||
const elements = {}
|
const elements = {}
|
||||||
document.querySelectorAll("a[href]").forEach((a) => {
|
document.querySelectorAll("a[href]").forEach((a) => {
|
||||||
const u = new URL(a.href)
|
const u = new URL(a.href)
|
||||||
if (u.hash.length === 0 && reHost.test(u.hostname)) {
|
if (u.hash.length === 0 && reHost.test(u.hostname)) {
|
||||||
const rePathRes = rePath.exec(u.pathname)
|
const rePathRes = rePath.exec(u.pathname)
|
||||||
if (rePathRes === null) {
|
if (rePathRes === null || rePathRes.length !== 2) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!util.isElementInViewport(a)) {
|
if (!util.isElementInViewport(a)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (elements[rePathRes.groups.asin] !== undefined) {
|
|
||||||
if (!(elements[rePathRes.groups.asin].text.trim().length === 0
|
const asin = rePathRes[1]
|
||||||
&& a.text.trim().length > 0)) {
|
|
||||||
|
if (elements[asin] !== undefined) {
|
||||||
|
if (!(elements[asin].text.trim().length === 0 && a.text.trim().length > 0)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elements[rePathRes.groups.asin] = a
|
|
||||||
|
elements[asin] = a
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Hints.create(Object.values(elements), Hints.dispatchMouseClick)
|
Hints.create(Object.values(elements), Hints.dispatchMouseClick)
|
||||||
|
|
Loading…
Reference in New Issue