2021-01-15 21:51:04 +01:00
// ==UserScript==
2021-01-18 00:38:52 +01:00
// @name Travel picker - Autopilot quest helpers tool
2021-01-15 21:51:04 +01:00
// @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-22 22:53:47 +01:00
// @version 1.2.4
2021-01-22 18:48:37 +01:00
// @author BoBobby
2021-01-17 22:12:57 +01:00
// @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
2021-01-15 21:51:04 +01:00
// ==/UserScript==
2021-01-22 18:48:37 +01:00
const _settings = {
travelCommand : '/travel ' ,
popupTextStyle : 'color: white; font-size: 1.3em' ,
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;' ,
textareaStyle : 'position: fixed; top: 0; left: 0; width: 2em; height: 2em; padding: 0; border: none; outline: none; boxShadow: none; background: transparent;' ,
colors : {
success : {
background : '#5FE026' ,
border : '#46A31D'
} ,
error : {
background : '#C70039' ,
border : '#992144'
}
}
}
2021-01-16 00:46:06 +01:00
const parameters = new URLSearchParams ( window . location . search )
2021-01-22 18:48:37 +01:00
const displayPopup = ( prmText , prmStatus ) => {
2021-01-16 00:13:03 +01:00
let popupDiv = document . createElement ( 'div' )
let popupText = document . createElement ( 'p' )
2021-01-22 18:48:37 +01:00
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
2021-01-16 00:13:03 +01:00
} else {
2021-01-22 18:48:37 +01:00
popupDiv . style . borderColor = _settings . colors . error . border
popupDiv . style . backgroundColor = _settings . colors . error . background
2021-01-16 00:13:03 +01:00
}
2021-01-15 21:51:04 +01:00
2021-01-22 18:48:37 +01:00
popupText . textContent = prmText
2021-01-16 00:13:03 +01:00
popupDiv . appendChild ( popupText )
document . body . appendChild ( popupDiv )
window . setTimeout ( _ => {
popupDiv . style . opacity = 0
2021-01-15 21:51:04 +01:00
window . setTimeout ( _ => {
2021-01-16 00:13:03 +01:00
popupDiv . parentNode . removeChild ( popupDiv )
} , 3000 )
} , 50 )
}
2021-01-15 21:51:04 +01:00
2021-01-22 22:53:21 +01:00
const copyTextToClipboard = ( prmText , prmStatus ) => {
2021-01-16 00:13:03 +01:00
let textArea = document . createElement ( "textarea" ) ;
2021-01-15 21:51:04 +01:00
2021-01-22 18:48:37 +01:00
textArea . setAttribute ( 'style' , _settings . textareaStyle )
2021-01-15 21:51:04 +01:00
2021-01-22 22:53:21 +01:00
textArea . value = prmText ;
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
document . body . appendChild ( textArea ) ;
textArea . focus ( ) ;
textArea . select ( ) ;
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
try {
let successful = document . execCommand ( 'copy' ) ;
let msg = successful ? 'successful' : 'unsuccessful' ;
2021-01-22 22:53:21 +01:00
if ( successful ) displayPopup ( prmText + ' a bien été copié !' , prmStatus ? prmStatus : 'success' )
else displayPopup ( msg , prmStatus ? prmStatus : 'error' )
2021-01-16 00:13:03 +01:00
} catch ( err ) { }
document . body . removeChild ( textArea ) ;
}
2021-01-15 21:51:04 +01:00
2021-01-22 22:53:21 +01:00
const getPositionArray = prmString => {
2021-01-18 00:37:32 +01:00
const rule = /[-]?[0-9]{1,2}/g
2021-01-22 22:53:21 +01:00
return prmString . match ( rule )
2021-01-16 00:13:03 +01:00
}
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
if ( ! window . location . href . includes ( 'dofus-map' ) ) {
( ( ) => {
2021-01-18 00:37:32 +01:00
const match = /(?<!\(.*)[\[]?(\s)*(-)?([0-9]+)[\s]*,[\s]*(-)?([0-9]+)[\s]*[\]]?(?!\))/g
2021-01-16 00:13:03 +01:00
document . body . innerHTML = document . body . innerHTML . replace ( match , "<goto data-x=\"$2$3\" data-y=\"$4$5\">$1[$2$3,$4$5]</goto>" ) ;
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
const allGotos = document . getElementsByTagName ( 'goto' ) ;
for ( let i = 0 ; i < allGotos . length ; i ++ ) {
allGotos [ i ] . addEventListener ( 'click' , event => {
2021-01-18 00:37:32 +01:00
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 ( '-' , '' ) ) ) {
2021-01-22 18:48:37 +01:00
copyTextToClipboard ( _settings . travelCommand + event . target . getAttribute ( 'data-x' ) + ',' + event . target . getAttribute ( 'data-y' ) )
2021-01-16 00:13:03 +01:00
} else {
displayPopup ( 'Cette coordonnée n\'est pas compatible :(' , 'error' )
}
} )
allGotos [ i ] . addEventListener ( 'contextmenu' , event => {
event . preventDefault ( )
2021-01-18 00:37:32 +01:00
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 ( '-' , '' ) ) ) {
2021-01-22 18:48:37 +01:00
/ * *
* 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
* /
2021-01-18 00:37:32 +01:00
copyTextToClipboard ( ( parameters . has ( 'noob' ) ? '/p ' : '' ) + '[' + event . target . getAttribute ( 'data-x' ) + ',' + event . target . getAttribute ( 'data-y' ) + ']' )
2021-01-16 00:13:03 +01:00
} else {
displayPopup ( 'Cette coordonnée n\'est pas compatible :(' , 'error' )
}
} )
}
} ) ( )
2021-01-17 01:48:27 +01:00
} else if ( window . location . href . includes ( 'hunt' ) ) {
console . log ( 'Dofus-Map Hunt detected' )
2021-01-16 00:13:03 +01:00
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 ) {
2021-01-16 00:46:06 +01:00
if ( parameters . has ( 'noob' ) ) {
2021-01-22 18:48:37 +01:00
/ * *
* 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
* /
2021-01-17 01:48:27 +01:00
copyTextToClipboard ( '/p [' + position [ 0 ] + ',' + position [ 1 ] + ']' )
2021-01-16 00:46:06 +01:00
} else {
2021-01-22 18:48:37 +01:00
copyTextToClipboard ( _settings . travelCommand + position [ 0 ] + ',' + position [ 1 ] )
2021-01-16 00:46:06 +01:00
}
2021-01-16 00:13:03 +01:00
}
2021-01-15 22:19:05 +01:00
}
2021-01-15 22:22:32 +01:00
} )
2021-01-16 00:13:03 +01:00
} )
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
observer . observe ( result , {
childList : true
} )
2021-01-17 01:48:27 +01:00
} else {
console . log ( 'Dofus-Map detected' )
const result = document . getElementById ( 'mapCoordinates' ) ;
const mapElement = document . getElementById ( 'mapContainer' )
2021-01-17 22:06:50 +01:00
mapElement . addEventListener ( 'mousedown' , mousedownEvent => {
2021-01-22 18:48:37 +01:00
/ * *
* Détecte si on a déplacé la map pour éviter de copier des positions non souhaitées
* /
2021-01-17 22:06:50 +01:00
let moved = false
mapElement . addEventListener ( 'mousemove' , moveEvent => moved = true )
mapElement . addEventListener ( 'mouseup' , mouseupEvent => {
const position = getPositionArray ( result . innerHTML )
2021-01-17 22:11:31 +01:00
2021-01-17 22:06:50 +01:00
if ( position && position . length === 2 && ! moved ) {
if ( parameters . has ( 'noob' ) ) {
2021-01-22 18:48:37 +01:00
/ * *
* 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
* /
2021-01-17 22:06:50 +01:00
copyTextToClipboard ( '/p [' + position [ 0 ] + ',' + position [ 1 ] + ']' )
} else {
2021-01-22 18:48:37 +01:00
copyTextToClipboard ( _settings . travelCommand + position [ 0 ] + ',' + position [ 1 ] )
2021-01-17 22:06:50 +01:00
}
2021-01-17 01:48:27 +01:00
}
2021-01-17 22:06:50 +01:00
} )
2021-01-17 01:48:27 +01:00
} )
2021-01-16 00:13:03 +01:00
}