Add dofus-map hunter feature
This commit is contained in:
parent
9ac7bde94d
commit
1ad5d25abd
156
dofusTravel.js
156
dofusTravel.js
@ -6,78 +6,100 @@
|
|||||||
// @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/*
|
||||||
// @grant none
|
// @version 1.3
|
||||||
// @version 1.2
|
|
||||||
// @author Mazoyer Alexis
|
// @author Mazoyer Alexis
|
||||||
// @description Permet de rendre cliquable toutes les positions [x,y] indiquées sur le site dofuspourlesnoobs
|
// @description Permet de rendre cliquable toutes les positions [x,y] indiquées sur le site dofuspourlesnoobs
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
(() => {
|
const travelCommand = '/travel '
|
||||||
const displayPopup = (text, status) => {
|
const displayPopup = (text, status) => {
|
||||||
let popupDiv = document.createElement('div')
|
let popupDiv = document.createElement('div')
|
||||||
let popupText = document.createElement('p')
|
let popupText = document.createElement('p')
|
||||||
popupText.setAttribute('style', 'color: white; font-size: 1.3em')
|
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')
|
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')
|
||||||
if (!status || status === 'success') {
|
if (!status || status === 'success') {
|
||||||
popupDiv.style.borderColor = '#46A31D'
|
popupDiv.style.borderColor = '#46A31D'
|
||||||
popupDiv.style.backgroundColor = '#5FE026'
|
popupDiv.style.backgroundColor = '#5FE026'
|
||||||
} else {
|
} else {
|
||||||
popupDiv.style.borderColor = '#992144'
|
popupDiv.style.borderColor = '#992144'
|
||||||
popupDiv.style.backgroundColor = '#C70039'
|
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('[' + event.srcElement.getAttribute('data-x') + ',' + event.srcElement.getAttribute('data-y') + ']')
|
||||||
|
} else {
|
||||||
|
displayPopup('Cette coordonnée n\'est pas compatible :(', 'error')
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
popupText.textContent = text
|
})()
|
||||||
popupDiv.appendChild(popupText)
|
} else {
|
||||||
document.body.appendChild(popupDiv)
|
const result = document.getElementById('secondLine')
|
||||||
window.setTimeout(_ => {
|
let observer = new MutationObserver(mutations => {
|
||||||
popupDiv.style.opacity = 0
|
mutations.forEach(mutation => {
|
||||||
window.setTimeout(_ => {
|
if (mutation.addedNodes.length) {
|
||||||
popupDiv.parentNode.removeChild(popupDiv)
|
const position = getPositionArray(result.innerHTML.replace( /(<([^>]+)>)/ig, '').replace(';', ',').replace(/\s/g, ''))
|
||||||
}, 3000)
|
if(position && position.length === 2) {
|
||||||
}, 50)
|
copyTextToClipboard(travelCommand + position[0] + ',' + position[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
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 travelCommand = '/travel '
|
|
||||||
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('[' + event.srcElement.getAttribute('data-x') + ',' + event.srcElement.getAttribute('data-y') + ']')
|
|
||||||
} else {
|
|
||||||
displayPopup('Cette coordonnée n\'est pas compatible :(', 'error')
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
|
||||||
})()
|
observer.observe(result, {
|
||||||
|
childList: true
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user