This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
139 lines (139 loc) · 5.29 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
let x = async function () {
function captureNetworkRequest(e) {
let capture_newtwork_request = [];
let capture_resource = performance.getEntriesByType(`resource`);
for (let i = 0; i < capture_resource.length; i++) {
if (capture_resource[i].initiatorType == `xmlhttprequest` || capture_resource[i].initiatorType == `script`) {
if (!0) {
capture_newtwork_request.push(capture_resource[i].name);
}
}
};
return capture_newtwork_request;
};
function jsonp(uri) {
return new Promise(function (resolve, reject) {
uri = uri.slice(0, (uri.indexOf("callback") - 1));
let id = `_` + Math.round(10000 * Math.random());
let callbackName = `jsonp_callback_` + id;
let src = uri + `&callback=` + callbackName;
window[callbackName] = function (data) {
delete window[callbackName];
let ele = document.getElementById(id);
ele.parentNode.removeChild(ele);
resolve(data);
};
let script = document.createElement(`script`);
script.src = src;
script.id = id;
script.addEventListener(`error`, reject);
(document.getElementsByTagName(`head`)[0] || document.body || document.documentElement).appendChild(script)
})
};
function simulateClick(elem) {
var evt = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
var canceled = !elem.dispatchEvent(evt);
};
function click(x, y) {
var ev = document.createEvent("MouseEvent");
var el = document.elementFromPoint(x, y);
ev.initMouseEvent(
"click",
true,
true,
window, null,
x, y, 0, 0,
false, false, false, false,
0, null
);
el.dispatchEvent(ev);
}
function getElementCoords(element) {
let topOffset = element.getBoundingClientRect().top;
let leftOffset = element.getBoundingClientRect().left;
return {
topOffset,
leftOffset
};
}
function getWidthElement(element) {
let leftBorder = element.getBoundingClientRect().left;
let rightBorder = element.getBoundingClientRect().right;
return rightBorder - leftBorder;
}
function getHeightElement(element) {
let topBorder = element.getBoundingClientRect().top;
let bottomBorder = element.getBoundingClientRect().bottom;
return bottomBorder - topBorder;
}
function calculateClickZone(ElementCoords, WidthElement, HeightElement) {
let x = ElementCoords.leftOffset + (WidthElement / 2);
let y = ElementCoords.topOffset + (HeightElement / 2);
return {
x,
y
}
}
function verifyMapSize() {
let mapClass = document.querySelector("[data-qa='guess-map']").classList.value;
console.log(mapClass.includes("size-4") && mapClass.includes("active"));
if (mapClass.includes("size-4") && mapClass.includes("active")) {
return true;
}
return false;
}
await jsonp(captureNetworkRequest().filter(url => {
return url.includes(`GeoPhoto`)
})[0]).then(data => {
let coords;
if (data[1][5][0][1][0].slice(2, 4)) {
console.log(data)
console.log("🎮 GameMode Loaded: Search Coords");
coords = data[1][5][0][1][0].slice(2, 4);
} else {
console.log("🎮 GameMode Loaded: Search Country");
return console.warn("⚠️ This gamemode is under development");
// coords = data[1][0][5][0][1][0].slice(2, 4);
}
if (!coords) return console.error("Error when i try to search the coords", "I suggest you to contact the founder of the extension");
let lat = coords[0];
let lon = coords[1];
if (!verifyMapSize()) {
let stickyControl = document.querySelector(".guess-map__control--sticky");
simulateClick(stickyControl);
let zoomControl = document.querySelector(".guess-map__control--increase-size");
simulateClick(zoomControl);
}
let guessMap = document.querySelector(".guess-map__canvas");
setTimeout(() => {
let getMapCoords = calculateClickZone(getElementCoords(guessMap), getWidthElement(guessMap), getHeightElement(guessMap));
click(getMapCoords.x, getMapCoords.y)
window.LatLngFromExtension = {
lat,
lon
}
setTimeout(() => {
click(getMapCoords.x, getMapCoords.y)
setTimeout(() => {
document.querySelector("[data-qa='perform-guess']").click();
setTimeout(() => {
window.location.reload();
}, 250)
}, 100)
}, 500)
}, (verifyMapSize() ? 100 : 750))
})
};
/* L'extension marche enfin !!
* TODO:
* - Faire un système de configuration comprenant:
* - Choisir la precision
* - Choisir le temps
*
* - Optimisation
* - Ajout d'automatisme pour rejouer automatiquement
*/