Fix unwanted matches with positions regex

This commit is contained in:
BoBobby 2021-01-18 00:37:32 +01:00
parent f499170e78
commit c2c6cd4fe9

View File

@ -57,20 +57,21 @@ const copyTextToClipboard = (text, status) => {
} }
const getPositionArray = chaine => { const getPositionArray = chaine => {
const rule = /[-]{0,1}[0-9]{1,2}/g const rule = /[-]?[0-9]{1,2}/g
return chaine.match(rule) return chaine.match(rule)
} }
if (!window.location.href.includes('dofus-map')) { if (!window.location.href.includes('dofus-map')) {
(() => { (() => {
const match = /[\[]{0,1}(\s)*(-){0,1}([0-9]+)[\s]*,[\s]*(-){0,1}([0-9]+)[\s]*[\]]{0,1}/g // const match = /(?<!rgb)[\[]?(\s)*(-)?([0-9]+)[\s]*,[\s]*(-)?([0-9]+)[\s]*[\]]?/g
const match = /(?<!\(.*)[\[]?(\s)*(-)?([0-9]+)[\s]*,[\s]*(-)?([0-9]+)[\s]*[\]]?(?!\))/g
document.body.innerHTML = document.body.innerHTML.replace(match, "<goto data-x=\"$2$3\" data-y=\"$4$5\">$1[$2$3,$4$5]</goto>"); document.body.innerHTML = document.body.innerHTML.replace(match, "<goto data-x=\"$2$3\" data-y=\"$4$5\">$1[$2$3,$4$5]</goto>");
const allGotos = document.getElementsByTagName('goto'); const allGotos = document.getElementsByTagName('goto');
for (let i = 0; i < allGotos.length; i++) { for (let i = 0; i < allGotos.length; i++) {
allGotos[i].addEventListener('click', event => { allGotos[i].addEventListener('click', event => {
if (event.srcElement.getAttribute('data-x') !== null && event.srcElement.getAttribute('data-y') !== null && !isNaN(event.srcElement.getAttribute('data-x').replace('-', '')) && !isNaN(event.srcElement.getAttribute('data-y').replace('-', ''))) { if (event.target.getAttribute('data-x') !== null && event.target.getAttribute('data-y') !== null && !isNaN(event.target.getAttribute('data-x').replace('-', '')) && !isNaN(event.target.getAttribute('data-y').replace('-', ''))) {
copyTextToClipboard(travelCommand + event.srcElement.getAttribute('data-x') + ',' + event.srcElement.getAttribute('data-y')) copyTextToClipboard(travelCommand + event.target.getAttribute('data-x') + ',' + event.target.getAttribute('data-y'))
} else { } else {
displayPopup('Cette coordonnée n\'est pas compatible :(', 'error') displayPopup('Cette coordonnée n\'est pas compatible :(', 'error')
} }
@ -78,8 +79,8 @@ if (!window.location.href.includes('dofus-map')) {
}) })
allGotos[i].addEventListener('contextmenu', event => { allGotos[i].addEventListener('contextmenu', event => {
event.preventDefault() event.preventDefault()
if (event.srcElement.getAttribute('data-x') !== null && event.srcElement.getAttribute('data-y') !== null && !isNaN(event.srcElement.getAttribute('data-x').replace('-', '')) && !isNaN(event.srcElement.getAttribute('data-y').replace('-', ''))) { if (event.target.getAttribute('data-x') !== null && event.target.getAttribute('data-y') !== null && !isNaN(event.target.getAttribute('data-x').replace('-', '')) && !isNaN(event.target.getAttribute('data-y').replace('-', ''))) {
copyTextToClipboard((parameters.has('noob') ? '/p ' : '') + '[' + event.srcElement.getAttribute('data-x') + ',' + event.srcElement.getAttribute('data-y') + ']') copyTextToClipboard((parameters.has('noob') ? '/p ' : '') + '[' + event.target.getAttribute('data-x') + ',' + event.target.getAttribute('data-y') + ']')
} else { } else {
displayPopup('Cette coordonnée n\'est pas compatible :(', 'error') displayPopup('Cette coordonnée n\'est pas compatible :(', 'error')
} }