Clean code, add comments and remove useless regex
This commit is contained in:
parent
5e2ea9ee2a
commit
835101e9d9
@ -6,26 +6,42 @@
|
|||||||
// @match https://www.gamosaurus.com/jeux/dofus/*
|
// @match https://www.gamosaurus.com/jeux/dofus/*
|
||||||
// @match https://dofus-map.com/*
|
// @match https://dofus-map.com/*
|
||||||
// @match https://dofus-portals.fr/*
|
// @match https://dofus-portals.fr/*
|
||||||
// @version 1.2.2
|
// @version 1.2.3
|
||||||
// @author Mazoyer Alexis
|
// @author BoBobby
|
||||||
// @description Permet de rendre cliquable toutes les positions [x,y] indiquées sur les sites dofuspourlesnoobs/dofus.jeuxonline.com/gamosaurus et dofus-map. Copie automatiquement /travel x,y lors des chasses sur dofus-map.com/hunt
|
// @description Permet de rendre cliquable toutes les positions [x,y] indiquées sur les sites dofuspourlesnoobs/dofus.jeuxonline.com/gamosaurus et dofus-map. Copie automatiquement /travel x,y lors des chasses sur dofus-map.com/hunt
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
const travelCommand = '/travel '
|
const _settings = {
|
||||||
const parameters = new URLSearchParams(window.location.search)
|
travelCommand: '/travel ',
|
||||||
const displayPopup = (text, status) => {
|
popupTextStyle: 'color: white; font-size: 1.3em',
|
||||||
let popupDiv = document.createElement('div')
|
popupDivStyle: 'display: inline-block; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); border-radius: 5px; background-color: #5FE026; border: solid 1px #46A31D; padding: 5px 15px; transition: opacity 1s ease-in-out; transition-delay: 1s; z-index: 9999999;',
|
||||||
let popupText = document.createElement('p')
|
textareaStyle: 'position: fixed; top: 0; left: 0; width: 2em; height: 2em; padding: 0; border: none; outline: none; boxShadow: none; background: transparent;',
|
||||||
popupText.setAttribute('style', 'color: white; font-size: 1.3em')
|
colors: {
|
||||||
popupDiv.setAttribute('style', 'display: inline-block; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); border-radius: 5px; background-color: #5FE026; border: solid 1px #46A31D; padding: 5px 15px; transition: opacity 1s ease-in-out; transition-delay: 1s; z-index: 9999999;')
|
success: {
|
||||||
if (!status || status === 'success') {
|
background: '#5FE026',
|
||||||
popupDiv.style.borderColor = '#46A31D'
|
border: '#46A31D'
|
||||||
popupDiv.style.backgroundColor = '#5FE026'
|
},
|
||||||
} else {
|
error: {
|
||||||
popupDiv.style.borderColor = '#992144'
|
background: '#C70039',
|
||||||
popupDiv.style.backgroundColor = '#C70039'
|
border: '#992144'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
popupText.textContent = text
|
}
|
||||||
|
const parameters = new URLSearchParams(window.location.search)
|
||||||
|
const displayPopup = (prmText, prmStatus) => {
|
||||||
|
let popupDiv = document.createElement('div')
|
||||||
|
let popupText = document.createElement('p')
|
||||||
|
popupText.setAttribute('style', _settings.popupTextStyle)
|
||||||
|
popupDiv.setAttribute('style', _settings.popupDivStyle)
|
||||||
|
if (!prmStatus || prmStatus === 'success') {
|
||||||
|
popupDiv.style.borderColor = _settings.colors.success.border
|
||||||
|
popupDiv.style.backgroundColor = _settings.colors.success.background
|
||||||
|
} else {
|
||||||
|
popupDiv.style.borderColor = _settings.colors.error.border
|
||||||
|
popupDiv.style.backgroundColor = _settings.colors.error.background
|
||||||
|
}
|
||||||
|
|
||||||
|
popupText.textContent = prmText
|
||||||
popupDiv.appendChild(popupText)
|
popupDiv.appendChild(popupText)
|
||||||
document.body.appendChild(popupDiv)
|
document.body.appendChild(popupDiv)
|
||||||
window.setTimeout(_ => {
|
window.setTimeout(_ => {
|
||||||
@ -39,7 +55,7 @@ const displayPopup = (text, status) => {
|
|||||||
const copyTextToClipboard = (text, status) => {
|
const copyTextToClipboard = (text, status) => {
|
||||||
let textArea = document.createElement("textarea");
|
let textArea = document.createElement("textarea");
|
||||||
|
|
||||||
textArea.setAttribute('style', 'position: fixed; top: 0; left: 0; width: 2em; height: 2em; padding: 0; border: none; outline: none; boxShadow: none; background: transparent;')
|
textArea.setAttribute('style', _settings.textareaStyle)
|
||||||
|
|
||||||
textArea.value = text;
|
textArea.value = text;
|
||||||
|
|
||||||
@ -50,8 +66,8 @@ const copyTextToClipboard = (text, status) => {
|
|||||||
try {
|
try {
|
||||||
let successful = document.execCommand('copy');
|
let successful = document.execCommand('copy');
|
||||||
let msg = successful ? 'successful' : 'unsuccessful';
|
let msg = successful ? 'successful' : 'unsuccessful';
|
||||||
if (successful) displayPopup(text + ' a bien été copié !', 'success')
|
if (successful) displayPopup(text + ' a bien été copié !', status ? status : 'success')
|
||||||
else displayPopup(msg, 'error')
|
else displayPopup(msg, status ? status : 'error')
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
document.body.removeChild(textArea);
|
document.body.removeChild(textArea);
|
||||||
}
|
}
|
||||||
@ -63,7 +79,6 @@ const getPositionArray = chaine => {
|
|||||||
|
|
||||||
if (!window.location.href.includes('dofus-map')) {
|
if (!window.location.href.includes('dofus-map')) {
|
||||||
(() => {
|
(() => {
|
||||||
// const match = /(?<!rgb)[\[]?(\s)*(-)?([0-9]+)[\s]*,[\s]*(-)?([0-9]+)[\s]*[\]]?/g
|
|
||||||
const match = /(?<!\(.*)[\[]?(\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>");
|
||||||
|
|
||||||
@ -71,7 +86,7 @@ if (!window.location.href.includes('dofus-map')) {
|
|||||||
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.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('-', ''))) {
|
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.target.getAttribute('data-x') + ',' + event.target.getAttribute('data-y'))
|
copyTextToClipboard(_settings.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')
|
||||||
}
|
}
|
||||||
@ -80,6 +95,9 @@ if (!window.location.href.includes('dofus-map')) {
|
|||||||
allGotos[i].addEventListener('contextmenu', event => {
|
allGotos[i].addEventListener('contextmenu', event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
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('-', ''))) {
|
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('-', ''))) {
|
||||||
|
/**
|
||||||
|
* Ajouter ?noob à la fin de l'url pour que le message copié soit simplement la position [x,y] au lieu de la commande /travel x,y, pour les noobs qui n'ont pas l'autopilot
|
||||||
|
*/
|
||||||
copyTextToClipboard((parameters.has('noob') ? '/p ' : '') + '[' + event.target.getAttribute('data-x') + ',' + event.target.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')
|
||||||
@ -97,9 +115,12 @@ if (!window.location.href.includes('dofus-map')) {
|
|||||||
const position = getPositionArray(result.innerHTML.replace( /(<([^>]+)>)/ig, '').replace(';', ',').replace(/\s/g, ''))
|
const position = getPositionArray(result.innerHTML.replace( /(<([^>]+)>)/ig, '').replace(';', ',').replace(/\s/g, ''))
|
||||||
if(position && position.length === 2) {
|
if(position && position.length === 2) {
|
||||||
if (parameters.has('noob')) {
|
if (parameters.has('noob')) {
|
||||||
|
/**
|
||||||
|
* Ajouter ?noob à la fin de l'url pour que le message copié soit simplement la position [x,y] au lieu de la commande /travel x,y, pour les noobs qui n'ont pas l'autopilot
|
||||||
|
*/
|
||||||
copyTextToClipboard('/p [' + position[0] + ',' + position[1] + ']')
|
copyTextToClipboard('/p [' + position[0] + ',' + position[1] + ']')
|
||||||
} else {
|
} else {
|
||||||
copyTextToClipboard(travelCommand + position[0] + ',' + position[1])
|
copyTextToClipboard(_settings.travelCommand + position[0] + ',' + position[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,6 +136,9 @@ if (!window.location.href.includes('dofus-map')) {
|
|||||||
const mapElement = document.getElementById('mapContainer')
|
const mapElement = document.getElementById('mapContainer')
|
||||||
|
|
||||||
mapElement.addEventListener('mousedown', mousedownEvent => {
|
mapElement.addEventListener('mousedown', mousedownEvent => {
|
||||||
|
/**
|
||||||
|
* Détecte si on a déplacé la map pour éviter de copier des positions non souhaitées
|
||||||
|
*/
|
||||||
let moved = false
|
let moved = false
|
||||||
mapElement.addEventListener('mousemove', moveEvent => moved = true)
|
mapElement.addEventListener('mousemove', moveEvent => moved = true)
|
||||||
mapElement.addEventListener('mouseup', mouseupEvent => {
|
mapElement.addEventListener('mouseup', mouseupEvent => {
|
||||||
@ -122,9 +146,12 @@ if (!window.location.href.includes('dofus-map')) {
|
|||||||
|
|
||||||
if (position && position.length === 2 && !moved) {
|
if (position && position.length === 2 && !moved) {
|
||||||
if (parameters.has('noob')) {
|
if (parameters.has('noob')) {
|
||||||
|
/**
|
||||||
|
* Ajouter ?noob à la fin de l'url pour que le message copié soit simplement la position [x,y] au lieu de la commande /travel x,y, pour les noobs qui n'ont pas l'autopilot
|
||||||
|
*/
|
||||||
copyTextToClipboard('/p [' + position[0] + ',' + position[1] + ']')
|
copyTextToClipboard('/p [' + position[0] + ',' + position[1] + ']')
|
||||||
} else {
|
} else {
|
||||||
copyTextToClipboard(travelCommand + position[0] + ',' + position[1])
|
copyTextToClipboard(_settings.travelCommand + position[0] + ',' + position[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user