-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiki.coords.js
executable file
·67 lines (65 loc) · 2.18 KB
/
wiki.coords.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
javascript: (() => {
const coordRegex = /([^\d]*\d*)\.(\d{4})/g;
const msg = "May need to update the \"type:\" value.\nUpdate the \"earth_region:\" value with ISO-2 code.\nSome common types:\nadm1st adm2nd adm3rd airport city edu event forest isle landmark mountain railwaystation river waterbody";
const coordsElem = document.querySelector("#action-menu > div:nth-child(1) > div > div");
let websiteElem = document.querySelector('div.rogA2c.ITvuef div.Io6YTe.fontBodyMedium.kR99db.fdkmkc');
let typeElem = document.querySelector("button.DkEaL");
let coords = "";
let iso2 = "US-";
let geotype = "landmark";
let finalLat = "";
let finalLng = "";
let websiteTxt = "";
if (websiteElem !== null) {
websiteTxt = websiteElem.innerText;
let lastTwoChars = websiteTxt.match(/.{2}$/)[0];
lastTwoChars = lastTwoChars.toUpperCase();
iso2 = lastTwoChars;
}
if (coordsElem === undefined) {
coords = "ADD_COORDS";
} else {
coords = coordsElem.innerText;
let lat = coords.split(",")[0].replaceAll(/\s/g, "");
let lng = coords.split(",")[1].replaceAll(/\s/g, "");
finalLat = lat.match(coordRegex);
finalLng = lng.match(coordRegex);
}
if (typeElem !== null) {
geotype = typeElem.textContent.toLowerCase();
switch (true) {
case /school/i.test(geotype):
geotype = "edu";
break;
case /university/i.test(geotype):
geotype = "edu";
break;
case /college/i.test(geotype):
geotype = "edu";
break;
case /mountain/i.test(geotype):
geotype = "mountain";
break;
case /lake/i.test(geotype):
geotype = "waterbody";
break;
case /ocean/i.test(geotype):
geotype = "waterbody";
break;
case /pond/i.test(geotype):
geotype = "waterbody";
break;
case /forest/i.test(geotype):
geotype = "forest";
break;
case /festival/i.test(geotype):
geotype = "event";
break;
default:
geotype = "landmark";
}
} else {
geotype = "landmark";
}
prompt(msg, "{{coord|" + finalLat + "|" + finalLng + "|type:" + geotype + "_globe:earth_region:" + iso2 + "|display=title}}")
})();