-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.js
88 lines (77 loc) · 2.34 KB
/
common.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
const this_page_nav_link = document.querySelector(".nav-link.active");
if (this_page_nav_link)
{
this_page_nav_link.onclick = event => event.preventDefault();
}
// Localisation
function getDictPromise()
{
return fetch("https://browse.wf/warframe-public-export-plus/dict." + (localStorage.getItem("lang") ?? "en") + ".json").then(res => res.json());
}
function getOSDictPromise()
{
return fetch("https://oracle.browse.wf/dicts/" + (localStorage.getItem("lang") ?? "en") + ".json?2").then(res => res.json());
}
function setLanguage(code)
{
setLanguageIndicator(code);
localStorage.setItem("lang", code);
const promises = [ getDictPromise() ];
if (window.osdict)
{
promises.push(getOSDictPromise());
}
Promise.all(promises).then(([ dict, osdict ]) =>
{
window.dict = dict;
window.osdict = osdict;
if ("onLanguageUpdate" in window)
{
onLanguageUpdate();
}
});
}
function setLanguageIndicator(code)
{
document.querySelectorAll(".dropdown-item[data-lang]").forEach(elm => elm.classList.remove("active"));
const item = document.querySelector(".dropdown-item[data-lang=" + code + "]");
item.classList.add("active");
document.getElementById("lang-dropdown").textContent = item.textContent;
}
if (localStorage.getItem("lang"))
{
setLanguageIndicator(localStorage.getItem("lang"));
}
function toTitleCase(str)
{
return str.replace(/[^\s\-]+/g, word => word.charAt(0).toUpperCase() + word.substr(1).toLowerCase());
}
// Images
function setImageSource(img, icon)
{
if (ExportImages[icon]?.forumName)
{
img.src = "https://media.invisioncic.com/Mwarframe/pages_media/" + ExportImages[icon].forumName + ".png";
}
else if (ExportImages[icon]?.contentHash)
{
img.src = "https://content.warframe.com/PublicExport" + icon + "!" + ExportImages[icon].contentHash;
}
else
{
img.src = "https://browse.wf" + icon;
}
}
// Text icons
function resolveTextIcons(text)
{
return text.replaceAll(/<[^>]+>/g, (match) => {
const name = match.split("<").join("").split(">").join("");
if (ExportTextIcons[name]?.DIT_AUTO)
{
return "<img alt='<" + name + ">' style='height:1em;position:relative;bottom:2px' src='https://browse.wf" + ExportTextIcons[name].DIT_AUTO + "' />";
}
//console.warn("Failed to resolve text icon:", name);
return "<" + name + ">";
});
}