User:Dantou0922/vector.js

var enClassName = "interlanguage-link interwiki-en"; var zhClassName = "interlanguage-link interwiki-zh"; var languageListId= "p-lang"; var uselessZhString = " – Chinese"; var uselessEnString = " – 英文"; var flag = 1; var pageLanguage = document.documentElement.lang; console.log("Page language is "+pageLanguage); var a = document.createElement('a');

if (pageLanguage =="en") {	try { var languagelink =document.getElementById(languageListId).getElementsByClassName("body")[0].getElementsByTagName("ul")[0].getElementsByClassName(zhClassName)[0].getElementsByTagName("a")[0].href; var languagetitle = document.getElementById(languageListId).getElementsByClassName("body")[0].getElementsByTagName("ul")[0].getElementsByClassName(zhClassName)[0].getElementsByTagName("a")[0].title; }		catch(err){ console.log("=====error info====="); flag =0; console.log(err); console.log("=====error info====="); }	if (flag ===1){ var linkText = document.createTextNode(" / "+languagetitle.replace(uselessZhString, "")); a.appendChild(linkText); a.href = languagelink; }	else {		var nolinkText = document.createTextNode(" / "+"no Chinese"); a.appendChild(nolinkText); } } else if (pageLanguage =="zh") {	try { var languagelink =document.getElementById(languageListId).getElementsByClassName("body")[0].getElementsByTagName("ul")[0].getElementsByClassName(enClassName)[0].getElementsByTagName("a")[0].href; var languagetitle = document.getElementById(languageListId).getElementsByClassName("body")[0].getElementsByTagName("ul")[0].getElementsByClassName(enClassName)[0].getElementsByTagName("a")[0].title; }	catch(err){ console.log("=====error info====="); flag =0; console.log(err); console.log("=====error info====="); }	if (flag ===1){ var linkText = document.createTextNode(" / "+languagetitle.replace(uselessEnString, "")); a.appendChild(linkText); a.href = languagelink; }	else {		var nolinkText = document.createTextNode(" / "+"no English"); a.appendChild(nolinkText); } } document.getElementById("firstHeading").appendChild(a);