131 lines
6.0 KiB
JavaScript
131 lines
6.0 KiB
JavaScript
// ==UserScript==
|
|
// @name Travel picker - dofuspourlesnoobs.com
|
|
// @match https://www.dofuspourlesnoobs.com/*
|
|
// @match https://www.dofus.com/*
|
|
// @match https://dofus.jeuxonline.info/*
|
|
// @match https://www.gamosaurus.com/jeux/dofus/*
|
|
// @match https://dofus-map.com/*
|
|
// @match https://dofus-portals.fr/*
|
|
// @version 1.2
|
|
// @author Mazoyer Alexis
|
|
// @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==
|
|
const travelCommand = '/travel '
|
|
const parameters = new URLSearchParams(window.location.search)
|
|
const displayPopup = (text, status) => {
|
|
let popupDiv = document.createElement('div')
|
|
let popupText = document.createElement('p')
|
|
popupText.setAttribute('style', 'color: white; font-size: 1.3em')
|
|
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;')
|
|
if (!status || status === 'success') {
|
|
popupDiv.style.borderColor = '#46A31D'
|
|
popupDiv.style.backgroundColor = '#5FE026'
|
|
} else {
|
|
popupDiv.style.borderColor = '#992144'
|
|
popupDiv.style.backgroundColor = '#C70039'
|
|
}
|
|
|
|
popupText.textContent = text
|
|
popupDiv.appendChild(popupText)
|
|
document.body.appendChild(popupDiv)
|
|
window.setTimeout(_ => {
|
|
popupDiv.style.opacity = 0
|
|
window.setTimeout(_ => {
|
|
popupDiv.parentNode.removeChild(popupDiv)
|
|
}, 3000)
|
|
}, 50)
|
|
}
|
|
|
|
const copyTextToClipboard = (text, status) => {
|
|
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.value = text;
|
|
|
|
document.body.appendChild(textArea);
|
|
textArea.focus();
|
|
textArea.select();
|
|
|
|
try {
|
|
let successful = document.execCommand('copy');
|
|
let msg = successful ? 'successful' : 'unsuccessful';
|
|
if (successful) displayPopup(text + ' a bien été copié !', 'success')
|
|
else displayPopup(msg, 'error')
|
|
} catch (err) {}
|
|
document.body.removeChild(textArea);
|
|
}
|
|
|
|
const getPositionArray = chaine => {
|
|
const rule = /[-]{0,1}[0-9]{1,2}/g
|
|
return chaine.match(rule)
|
|
}
|
|
|
|
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
|
|
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');
|
|
for (let i = 0; i < allGotos.length; i++) {
|
|
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('-', ''))) {
|
|
copyTextToClipboard(travelCommand + event.srcElement.getAttribute('data-x') + ',' + event.srcElement.getAttribute('data-y'))
|
|
} else {
|
|
displayPopup('Cette coordonnée n\'est pas compatible :(', 'error')
|
|
}
|
|
|
|
})
|
|
allGotos[i].addEventListener('contextmenu', event => {
|
|
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('-', ''))) {
|
|
copyTextToClipboard((parameters.has('noob') ? '/p ' : '') + '[' + event.srcElement.getAttribute('data-x') + ',' + event.srcElement.getAttribute('data-y') + ']')
|
|
} else {
|
|
displayPopup('Cette coordonnée n\'est pas compatible :(', 'error')
|
|
}
|
|
})
|
|
}
|
|
|
|
})()
|
|
} else if (window.location.href.includes('hunt')) {
|
|
console.log('Dofus-Map Hunt detected')
|
|
const result = document.getElementById('secondLine')
|
|
let observer = new MutationObserver(mutations => {
|
|
mutations.forEach(mutation => {
|
|
if (mutation.addedNodes.length) {
|
|
const position = getPositionArray(result.innerHTML.replace( /(<([^>]+)>)/ig, '').replace(';', ',').replace(/\s/g, ''))
|
|
if(position && position.length === 2) {
|
|
if (parameters.has('noob')) {
|
|
copyTextToClipboard('/p [' + position[0] + ',' + position[1] + ']')
|
|
} else {
|
|
copyTextToClipboard(travelCommand + position[0] + ',' + position[1])
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
observer.observe(result, {
|
|
childList: true
|
|
})
|
|
} else {
|
|
console.log('Dofus-Map detected')
|
|
const result = document.getElementById('mapCoordinates');
|
|
const mapElement = document.getElementById('mapContainer')
|
|
|
|
mapElement.addEventListener('mousedown', mousedownEvent => {
|
|
let moved = false
|
|
mapElement.addEventListener('mousemove', moveEvent => moved = true)
|
|
mapElement.addEventListener('mouseup', mouseupEvent => {
|
|
const position = getPositionArray(result.innerHTML)
|
|
|
|
if (position && position.length === 2 && !moved) {
|
|
if (parameters.has('noob')) {
|
|
copyTextToClipboard('/p [' + position[0] + ',' + position[1] + ']')
|
|
} else {
|
|
copyTextToClipboard(travelCommand + position[0] + ',' + position[1])
|
|
}
|
|
}
|
|
})
|
|
})
|
|
} |