2021-05-10 00:14:03 +08:00
|
|
|
(function () {
|
|
|
|
var url = window.location.href;
|
|
|
|
var host = window.location.host;
|
2021-05-10 13:48:08 +08:00
|
|
|
var home_url = window.location.protocol + '//' + window.location.host;
|
2021-05-10 00:14:03 +08:00
|
|
|
|
|
|
|
var search = {
|
|
|
|
en: "/en/",
|
|
|
|
zh_CN: "/zh-CN/"
|
|
|
|
}
|
|
|
|
|
|
|
|
var replaceWith = {
|
|
|
|
en: "/zh-CN/",
|
|
|
|
zh_CN: "/en/"
|
|
|
|
}
|
|
|
|
|
|
|
|
var link = "";
|
|
|
|
var word = "";
|
2021-05-10 13:48:08 +08:00
|
|
|
var home = "Home";
|
2021-05-12 18:19:10 +08:00
|
|
|
var lang = "zh-CN";
|
|
|
|
var changeLang = "切换到英语";
|
2021-05-10 20:54:09 +08:00
|
|
|
|
2021-05-10 00:14:03 +08:00
|
|
|
if (url.indexOf(search.en) != -1 && url.indexOf(search.en) === (url.indexOf(host) + host.length)) {
|
|
|
|
link = url.replace(search.en, replaceWith.en);
|
|
|
|
word = "简体中文";
|
2021-05-12 18:19:10 +08:00
|
|
|
lang = "en";
|
|
|
|
changeLang = "Switch to Chinese"
|
2021-05-10 00:14:03 +08:00
|
|
|
} else if (url.indexOf(search.zh_CN) != -1 && url.indexOf(search.zh_CN) === (url.indexOf(host) + host.length)) {
|
|
|
|
link = url.replace(search.zh_CN, replaceWith.zh_CN);
|
|
|
|
word = "English";
|
2021-05-10 20:54:09 +08:00
|
|
|
home = "首页";
|
2021-05-10 00:14:03 +08:00
|
|
|
}
|
|
|
|
|
2021-05-12 18:19:10 +08:00
|
|
|
var edit_id = document.getElementById("git-edit-button");
|
|
|
|
if (edit_id != null && edit_id.parentNode != null) {
|
|
|
|
edit_id.parentNode.target = "_blank";
|
|
|
|
if (lang != "en") {
|
2022-02-02 16:32:35 +08:00
|
|
|
edit_id.parentNode.title = "报告错误或改进本页翻译";
|
2021-05-12 18:19:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-10 13:48:08 +08:00
|
|
|
var home_node = '';
|
|
|
|
if (window.location.protocol == 'http:' || window.location.protocol == 'https:') {
|
|
|
|
home_node = '<a href="' + home_url + '" title="' + home + '" aria-label="' + home + '"><i id="go-back-homepage" class="fa fa-home"></i></a>';
|
|
|
|
}
|
|
|
|
var lang_node = '';
|
|
|
|
if (link != '') {
|
2021-05-12 18:19:10 +08:00
|
|
|
lang_node = '<a href="' + link + '" title="' + changeLang + '" aria-label="' + changeLang + '"><i id="change-language-button" class="fa fa-language"> ' + word + '</i></a>';
|
2021-05-10 13:48:08 +08:00
|
|
|
}
|
2021-05-10 00:14:03 +08:00
|
|
|
var insertNode = document.getElementsByClassName('right-buttons');
|
2021-05-10 13:48:08 +08:00
|
|
|
if (insertNode.length > 0) {
|
2021-05-10 00:14:03 +08:00
|
|
|
var html = insertNode[0].innerHTML;
|
2021-05-12 18:19:10 +08:00
|
|
|
insertNode[0].innerHTML = home_node + html + lang_node;
|
2021-05-10 00:14:03 +08:00
|
|
|
}
|
|
|
|
})()
|