diff --git a/dofusTravel.js b/dofusTravel.js
index 720f6c2..24cf5a7 100644
--- a/dofusTravel.js
+++ b/dofusTravel.js
@@ -6,78 +6,100 @@
// @match https://www.gamosaurus.com/jeux/dofus/*
// @match https://dofus-map.com/*
// @match https://dofus-portals.fr/*
-// @grant none
-// @version 1.2
+// @version 1.3
// @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'
+const travelCommand = '/travel '
+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 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, "$1[$2$3,$4$5]");
+
+ 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)
- 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, "$1[$2$3,$4$5]");
-
- 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')
+ })()
+} else {
+ 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) {
+ copyTextToClipboard(travelCommand + position[0] + ',' + position[1])
+ }
}
})
- }
+ })
-})()
\ No newline at end of file
+ observer.observe(result, {
+ childList: true
+ })
+}
\ No newline at end of file