跳转到内容

User:PhiLiP/jstool/iProject.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/*

==左侧姊妹项目框体==
*/
// 修改自[[es:MediaWiki:Monobook.js]],维护者:[[User:PhiLiP]]
function iProject2() {
	var elements = new Array();
	var els = document.getElementsByTagName("div");
	var elsLen = els.length;
	for (var i = 0, j = 0; i < elsLen; i++) {
		if(els[i].className) {
			if (/.*?interProject.*?/.exec(els[i].className)) {
				var element = els[i].getElementsByTagName("a");
				var a = new Array();
				for(var k = 0; k < element.length; k++){
					var wiktionary = /.*\.wiktionary\.org.*/.exec(element[k].href);
					var wikibooks = /.*\.wikibooks\.org.*/.exec(element[k].href);
					var wikiquote = /.*\.wikiquote\.org.*/.exec(element[k].href);
					var commons = /.*commons\.wikimedia\.org.*/.exec(element[k].href);
					var wikinews = /.*\.wikinews\.org.*/.exec(element[k].href);
					var wikisource = /.*\.wikisource\.org.*/.exec(element[k].href);
					var species = /.*species\.wikimedia\.org.*/.exec(element[k].href);
					if(wiktionary) {
						a[j] = document.createElement("a");
						a[j].href = wiktionary;
						a[j].innerHTML = wgULS('维基词典','維基詞典');
					}
					else if(wikibooks) {
						a[j] = document.createElement("a");
						a[j].href = wikibooks;
						a[j].innerHTML = wgULS('维基教科书','維基教科書');
					}
					else if(wikiquote) {
						a[j] = document.createElement("a");
						a[j].href = wikiquote;
						a[j].innerHTML = wgULS('维基语录','維基語錄');
					}
					else if(commons) {
						a[j] = document.createElement("a");
						a[j].href = commons;
						a[j].innerHTML = wgULS('维基共享资源','維基共享資源');
					}
					else if(wikinews) {
						a[j] = document.createElement("a");
						a[j].href = wikinews;
						a[j].innerHTML = wgULS('维基新闻','維基新聞');
					}
					else if(wikisource) {
						a[j] = document.createElement("a");
						a[j].href = wikisource;
						a[j].innerHTML = wgULS('维基文库','維基文庫');
					}
					else if(species) {
						a[j] = document.createElement("a");
						a[j].href = species;
						a[j].innerHTML = wgULS('维基物种','維基物種');
					}
					if(a[j]) {
						elements[j] = document.createElement("li");
						elements[j].appendChild(a[j]);
						j++;
					}
				}
			}
		}
	}
	if (elements.length) {
		var box = document.createElement("div");
		box.setAttribute("class","portlet");
		box.id = 'p-ip';
		var title = document.createElement("h5");
		title.innerHTML = wgULS('姊妹项目','姊妹計畫');
		box.appendChild(title);
		var body = document.createElement("div");
		body.setAttribute("class","pBody");
		var list_ul = document.createElement("ul");
		for (var i = 0; i< elements.length; i++) {
			list_ul.appendChild(elements[i]);
		}
		body.appendChild(list_ul);
		box.appendChild(body);
		var tb_box = document.getElementById('p-tb');
		var parent = tb_box.parentNode;
		if(parent.lastChild == tb_box) {
			parent.appendChild(box);
		}
		else {
			parent.insertBefore(box, tb_box.nextSibling);
		}
	}
}
$(iProject2);