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-17 01:48:27 +01:00
// @version 1.2
2021-01-15 21:51:04 +01:00
// @author Mazoyer Alexis
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-16 00:13:03 +01:00
const travelCommand = '/travel '
2021-01-16 00:46:06 +01:00
const parameters = new URLSearchParams ( window . location . search )
2021-01-16 00:13:03 +01:00
const displayPopup = ( text , status ) => {
let popupDiv = document . createElement ( 'div' )
let popupText = document . createElement ( 'p' )
popupText . setAttribute ( 'style' , 'color: white; font-size: 1.3em' )
2021-01-17 01:48:27 +01:00
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;' )
2021-01-16 00:13:03 +01:00
if ( ! status || status === 'success' ) {
popupDiv . style . borderColor = '#46A31D'
popupDiv . style . backgroundColor = '#5FE026'
} else {
popupDiv . style . borderColor = '#992144'
popupDiv . style . backgroundColor = '#C70039'
}
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
popupText . textContent = text
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-16 00:13:03 +01:00
const copyTextToClipboard = ( text , status ) => {
let textArea = document . createElement ( "textarea" ) ;
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
textArea . setAttribute ( 'style' , 'position: fixed; top: 0; left: 0; width: 2em; height: 2em; padding: 0; border: none; outline: none; boxShadow: none; background: transparent;' )
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
textArea . value = text ;
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' ;
if ( successful ) displayPopup ( text + ' a bien été copié !' , 'success' )
else displayPopup ( msg , 'error' )
} catch ( err ) { }
document . body . removeChild ( textArea ) ;
}
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
const getPositionArray = chaine => {
const rule = /[-]{0,1}[0-9]{1,2}/g
return chaine . match ( rule )
}
2021-01-15 21:51:04 +01:00
2021-01-16 00:13:03 +01:00
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>" ) ;
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 => {
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 ( '-' , '' ) ) ) {
2021-01-17 01:48:27 +01:00
copyTextToClipboard ( ( parameters . has ( 'noob' ) ? '/p ' : '' ) + '[' + event . srcElement . getAttribute ( 'data-x' ) + ',' + event . srcElement . 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-17 01:48:27 +01:00
copyTextToClipboard ( '/p [' + position [ 0 ] + ',' + position [ 1 ] + ']' )
2021-01-16 00:46:06 +01:00
} else {
2021-01-16 00:49:50 +01:00
copyTextToClipboard ( 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 => {
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' ) ) {
copyTextToClipboard ( '/p [' + position [ 0 ] + ',' + position [ 1 ] + ']' )
} else {
copyTextToClipboard ( travelCommand + position [ 0 ] + ',' + position [ 1 ] )
}
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
}