..
Viewing
tl.js
90 lines (82 loc) • 2.1 KB
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 | // Google Translate (Only English and Japanese)
function googleTranslateElementInit() {
new google.translate.TranslateElement(
{
pageLanguage: "en",
includedLanguages: "ja",
},
"google_translate_element"
);
}
function restoreLang() {
localStorage.setItem("lang", "en");
$('#tl_ja').hide();
$('#tl_en').show();
$('body').addClass('en');
$('body').removeClass('ja');
var translateContainers = $('iframe');
if (translateContainers.length === 0) {
// nothing
} else {
translateContainers.each(function (index, element) {
if (element.contentWindow.document.getElementById(":1.close")) {
element.contentWindow.document.getElementById(":1.close").click();
}
});
}
}
function translateJapanese() {
localStorage.setItem("lang", "ja");
$('#tl_en').hide();
$('#tl_ja').show();
$('body').addClass('ja');
$('body').removeClass('en');
var selectEl = document.querySelector("select.goog-te-combo");
if (!selectEl) {
setTimeout(function () {
translateJapanese();
}, 10);
} else if (!selectEl.options || selectEl.options.length === 0) {
setTimeout(function () {
translateJapanese();
}, 10);
} else {
selectEl.value = 'ja';
selectEl.dispatchEvent(new Event("change"));
// setTimeout(function () {
// save();
// }, 6969);
}
}
// init
var currentLang = localStorage.getItem("lang");
if (!currentLang) {
currentLang = "en";
localStorage.setItem("lang", "en");
}
if (currentLang === "ja") {
$('#tl_en').hide();
$('#tl_ja').show();
$('body').addClass('ja');
$('body').removeClass('en');
// setTimeout(function () {
// save();
// }, 6969);
} else {
$('#tl_ja').hide();
$('#tl_en').show();
$('body').addClass('en');
$('body').removeClass('ja');
restoreLang();
}
// let entirePage;
function save() {
// only body
const entirePage = document.getElementById('wrap').innerHTML;
const path = window.location.pathname;
const storedPage = window.sessionStorage.getItem(path);
if (storedPage === null || storedPage !== entirePage) {
console.log('Saving page to DB');
window.sessionStorage.setItem(path, entirePage);
}
}
|
|