mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-01-23 07:20:20 +08:00
Add language.js
This commit is contained in:
parent
9344fcaf19
commit
53b811b041
@ -6,5 +6,5 @@ language = "zh-CN"
|
||||
|
||||
[output.html]
|
||||
additional-css = ["ferris.css", "theme/2018-edition.css"]
|
||||
additional-js = ["ferris.js"]
|
||||
additional-js = ["ferris.js", "language.js"]
|
||||
git-repository-url = "https://github.com/rust-lang-cn/book-cn"
|
||||
|
33
language.js
Normal file
33
language.js
Normal file
@ -0,0 +1,33 @@
|
||||
(function () {
|
||||
var url = window.location.href;
|
||||
var host = window.location.host;
|
||||
|
||||
var search = {
|
||||
en: "/en/",
|
||||
zh_CN: "/zh-CN/"
|
||||
}
|
||||
|
||||
var replaceWith = {
|
||||
en: "/zh-CN/",
|
||||
zh_CN: "/en/"
|
||||
}
|
||||
|
||||
|
||||
var link = "";
|
||||
var word = "";
|
||||
|
||||
if (url.indexOf(search.en) != -1 && url.indexOf(search.en) === (url.indexOf(host) + host.length)) {
|
||||
link = url.replace(search.en, replaceWith.en);
|
||||
word = "简体中文";
|
||||
} 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";
|
||||
}
|
||||
|
||||
var node = '<a href="' + link + '"><i id="print-button" class="fa fa-language"> ' + word + '</i></a>';
|
||||
var insertNode = document.getElementsByClassName('right-buttons');
|
||||
if (insertNode.length > 0 && link != "") {
|
||||
var html = insertNode[0].innerHTML;
|
||||
insertNode[0].innerHTML = html + node;
|
||||
}
|
||||
})()
|
Loading…
Reference in New Issue
Block a user