-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(function () { | ||
var url = window.location.href; | ||
var host = window.location.host; | ||
var home_url = window.location.protocol + '//' + window.location.host; | ||
|
||
var search = { | ||
en: "/en/", | ||
zh_CN: "/zh-CN/" | ||
} | ||
|
||
var replaceWith = { | ||
en: "/zh-CN/", | ||
zh_CN: "/en/" | ||
} | ||
|
||
var link = ""; | ||
var word = ""; | ||
var home = "Home"; | ||
var lang = "zh-CN"; | ||
var changeLang = "切换到英语"; | ||
|
||
if (url.indexOf(search.en) != -1 && url.indexOf(search.en) === (url.indexOf(host) + host.length)) { | ||
link = url.replace(search.en, replaceWith.en); | ||
word = "简体中文"; | ||
lang = "en"; | ||
changeLang = "Switch to Chinese" | ||
} 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"; | ||
home = "首页"; | ||
} | ||
|
||
var edit_id = document.getElementById("git-edit-button"); | ||
if (edit_id != null && edit_id.parentNode != null) { | ||
edit_id.parentNode.target = "_blank"; | ||
if (lang != "en") { | ||
edit_id.parentNode.title = "报告错误或改进本页翻译"; | ||
} | ||
} | ||
|
||
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 != '') { | ||
lang_node = '<a href="' + link + '" title="' + changeLang + '" aria-label="' + changeLang + '"><i id="change-language-button" class="fa fa-language"> ' + word + '</i></a>'; | ||
} | ||
var insertNode = document.getElementsByClassName('right-buttons'); | ||
if (insertNode.length > 0) { | ||
var html = insertNode[0].innerHTML; | ||
insertNode[0].innerHTML = home_node + html + lang_node; | ||
} | ||
})() |