2021-01-15 21:51:04 +01:00
|
|
|
// ==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/*
|
2021-01-15 22:08:50 +01:00
|
|
|
// @match https://dofus-portals.fr/*
|
2021-01-15 21:51:04 +01:00
|
|
|
// @grant none
|
2021-01-15 22:21:19 +01:00
|
|
|
// @version 1.2
|
2021-01-15 21:51:04 +01:00
|
|
|
// @author Mazoyer Alexis
|
|
|
|
// @description Permet de rendre cliquable toutes les positions [x,y] indiquées sur le site dofuspourlesnoobs
|
|
|
|
// ==/UserScript==
|
|
|
|
(() => {
|
|
|
|
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')
|
|
|
|
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 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')
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
2021-01-15 22:21:19 +01:00
|
|
|
allGotos[i].addEventListener('contextmenu', event => {
|
2021-01-15 22:19:05 +01:00
|
|
|
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')
|
|
|
|
}
|
|
|
|
})]
|
2021-01-15 21:51:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
})()
|