-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
161 lines (156 loc) · 4.95 KB
/
main.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//Available languages
const languages = ["de", "en", "es", "fr", "it", "ja", "pt", "ru", "zh"];
//Initialize mermaid - graphs in markdown
mermaid.initialize({ startOnLoad: false });
//docsify settings
window.$docsify = {
name: 'BitcoinMythBusters',
repo: 'rene78/BitcoinMythBusters',
// loadNavbar: true,
disqus: 'btcmythbusters',
search: {
maxAge: 86400000, // Expiration time, the default one day
paths: [
'/de/',
'/es/',
'/fr/',
'/it/',
'/ja/',
'/pt/',
'/ru/',
'/zh/',
'/' // => /README.md
],
// Search Localization
placeholder: {
'/de/': 'Suchen...',
'/es/': 'Buscar...',
'/fr/': 'Rechercher...',
'/it/': 'Cerca...',
'/ja/': '検索...',
'/pt/': 'Buscar...',
'/ru/': 'Поиск...',
'/zh/': '搜索...',
'/': 'Search...'
},
noData: {
'/de/': 'Keine Resultate',
'/es/': 'No hay resultados',
'/fr/': 'Aucun résultat',
'/it/': 'Nessun risultato',
'/ja/': '結果なし',
'/pt/': 'Sem resultados',
'/ru/': 'Нет результатов',
'/zh/': '没有结果',
'/': 'No Results'
}
},
markdown: {
renderer: {
code: function (code, lang) {
if (lang === "mermaid") {
return (
'<div class="mermaid">' + mermaid.render(lang, code) + "</div>"
);
}
return this.origin.code.apply(this, arguments);
}
}
},
plugins: [
EditOnGithubPlugin.create("https://github.com/rene78/BitcoinMythBusters/blob/main/", null, "Edit on GitHub")
],
copyCode: {
// copyCode Localization
buttonText: {
'/de/': 'Klicken Sie zum Kopieren',
'/es/': 'Haga clic para copiar',
'/fr/': 'Cliquez pour copier',
'/it/': 'Clicca per copiare',
'/ja/': 'クリックしてコピー',
'/pt/': 'Clique para copiar',
'/ru/': 'Скопировать в буфер обмена',
'/zh/': '点击复制',
'/': 'Copy to clipboard'
},
errorText: {
'/de/': 'Fehler',
'/es/': 'Error',
'/fr/': 'Erreur',
'/it/': 'Errore',
'/ja/': 'エラー',
'/pt/': 'Erro',
'/ru/': 'ошибка',
'/zh/': '错误',
'/': 'Error'
},
successText: {
'/de/': 'Kopiert',
'/es/': 'Copiado',
'/fr/': 'Copié',
'/it/': 'Copiato',
'/ja/': 'からコピーしました。',
'/pt/': 'Copiado',
'/ru/': 'Скопировано',
'/zh/': '复制',
'/': 'Copied'
}
}
}
//Before page load check if a route is saved in localStorage.
//If yes navigate to it.
//If no: Check if one of the user's favourite browser languages is available on page.
//If no favourite language available on page: Load English version (default).
document.onreadystatechange = () => {
currLangIndex = document.getElementById("lang-selection");
//First check, if a route is saved in localstorage
let route = localStorage.getItem("route");
// console.log("Route on load: " + route);
//If yes, route to URL
if (route) {
window.location.hash = route; //relative to domain
//Update language selector
const lang = route.slice(2, 4); //Gonna be "?i" for default, i.e. English route.
// console.log(lang);
currLangIndex.selectedIndex = 1; //set selectedIndex to the default "English" first. Gonna be overwritten if lang != "?i"
for (let i = 0; i < languages.length; i++) {
if (languages[i] === lang) {
currLangIndex.selectedIndex = i;
break;
}
}
}
//Else check the preferred browser languages and see, if we have a translation for it
else {
// console.log(navigator.languages);
//Go through all preferred languages defined in the browser and take the first match. If no match - English will be loaded.
for (let i = 0; i < navigator.languages.length; i++) {
const navigatorLanguage = navigator.languages[i].slice(0, 2); //Just keep the first 2 letters (e.g. en-US --> en)
// console.log(navigatorLanguage);
if (navigatorLanguage === "en") {
currLangIndex.selectedIndex = 1; //set selectedIndex to "English" in lanugage selector
break; //Stop code execution, if default language is selected in browser
}
if (languages.indexOf(navigatorLanguage) !== -1) {
currLangIndex.selectedIndex = languages.indexOf(navigatorLanguage);//update selectedIndex in language selector
window.location.hash = "/" + navigatorLanguage + "/";
break;
}
}
}
}
//Save route to localStorage whenever the user clicks somewhere
document.addEventListener('click', (e) => {
setTimeout(() => {//setTimeout needed because the hash change is slower than the click event.
let hash = window.location.hash;
// console.log("Current Route: " + hash);
localStorage.setItem("route", hash);
}, 500)
});
//Scroll down to help when clicking on "Help"
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}