diff --git a/english/language.js b/english/language.js index 808e5b5..9fa197d 100644 --- a/english/language.js +++ b/english/language.js @@ -13,18 +13,49 @@ zh_CN: "/en/" } + console.log("hheheeh"); var link = ""; var word = ""; var home = "Home"; + var edit_url = "https://github.com/rust-lang-cn" + var github_id = document.getElementById("git-repository-button"); + if (github_id != null && github_id.parentNode.href != undefined) { + edit_url = github_id.parentNode.href; + var repo_name = edit_url.split('/').pop(); + var url_repo_name = repo_name.slice(0, -3); + + if (url.indexOf(url_repo_name) > -1) { + var html_file = url.split(url_repo_name).pop(); + } else if (url.indexOf(":3000") > -1) { + var html_file = url.split(":3000").pop(); + } else { + var html_file = '/'; + } + + + if (html_file == '/') { + edit_url += '/tree/master/src' + } else { + var md_len = html_file.indexOf('.html'); + if (md_len > -1) { + var md_file = html_file.substring(0, md_len) + '.md'; + edit_url += '/blob/master/src' + md_file; + } + } + } + + var edit_node = ''; + if (url.indexOf(search.en) != -1 && url.indexOf(search.en) === (url.indexOf(host) + host.length)) { link = url.replace(search.en, replaceWith.en); word = "简体中文"; + edit_node = ""; } 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 = "首页"; + home = "首页"; } var home_node = ''; @@ -38,6 +69,6 @@ var insertNode = document.getElementsByClassName('right-buttons'); if (insertNode.length > 0) { var html = insertNode[0].innerHTML; - insertNode[0].innerHTML = home_node + html + lang_node; + insertNode[0].innerHTML = home_node + html + edit_node + lang_node; } })() diff --git a/language.js b/language.js index 808e5b5..9fa197d 100644 --- a/language.js +++ b/language.js @@ -13,18 +13,49 @@ zh_CN: "/en/" } + console.log("hheheeh"); var link = ""; var word = ""; var home = "Home"; + var edit_url = "https://github.com/rust-lang-cn" + var github_id = document.getElementById("git-repository-button"); + if (github_id != null && github_id.parentNode.href != undefined) { + edit_url = github_id.parentNode.href; + var repo_name = edit_url.split('/').pop(); + var url_repo_name = repo_name.slice(0, -3); + + if (url.indexOf(url_repo_name) > -1) { + var html_file = url.split(url_repo_name).pop(); + } else if (url.indexOf(":3000") > -1) { + var html_file = url.split(":3000").pop(); + } else { + var html_file = '/'; + } + + + if (html_file == '/') { + edit_url += '/tree/master/src' + } else { + var md_len = html_file.indexOf('.html'); + if (md_len > -1) { + var md_file = html_file.substring(0, md_len) + '.md'; + edit_url += '/blob/master/src' + md_file; + } + } + } + + var edit_node = ''; + if (url.indexOf(search.en) != -1 && url.indexOf(search.en) === (url.indexOf(host) + host.length)) { link = url.replace(search.en, replaceWith.en); word = "简体中文"; + edit_node = ""; } 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 = "首页"; + home = "首页"; } var home_node = ''; @@ -38,6 +69,6 @@ var insertNode = document.getElementsByClassName('right-buttons'); if (insertNode.length > 0) { var html = insertNode[0].innerHTML; - insertNode[0].innerHTML = home_node + html + lang_node; + insertNode[0].innerHTML = home_node + html + edit_node + lang_node; } })()