MediaWiki:Common.js:修订间差异

来自魏启大陆
跳转到导航 跳转到搜索
Hineven留言 | 贡献
无编辑摘要
Hineven留言 | 贡献
无编辑摘要
第15行: 第15行:
/* 以下代码用于模板折叠文字 -- Hineven */
/* 以下代码用于模板折叠文字 -- Hineven */


add_load_event = function(func) {
var oldonload = window.onload;
if(typeof window.onload != 'function') {
window.onload = func;
} else { 
window.onload = function() {
oldonload();
func();
}
}
}
random_string = function(str_length) {
random_string = function(str_length) {
var str = "",
var str = "",
第78行: 第67行:
}
}
add_load_event(collapse_preprocess);
collapse_preprocess();

2018年4月18日 (三) 10:34的版本

/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */


	var elist=document.getElementsByClassName("page-tags");
	for(var i = 0; i < elist.length; i++) {
		var str = elist[i].innerHTML;
		str=str.replace("番外","<strong style=\"background-color:#92fda3;\">番外</strong>");
		str=str.replace("长故事","<strong style=\"background-color:#ff8080;\">长故事</strong>");
		str=str.replace("故事集","<strong style=\"background-color:#df6eef;\">故事集</strong>");
		str=str.replace("故事","<strong style=\"background-color:#66b9f1;\">故事</strong>");
		str=str.replace("设定","<strong style=\"background-color:#ffff7b;\">设定</strong>");
		elist[i].innerHTML = str;
	}

/* 以下代码用于模板折叠文字 -- Hineven */

			random_string = function(str_length) {
				var str = "",
					arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
					'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
					'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
				for (var i = 0; i < str_length; i++) {
					pos = Math.round(Math.random()*(arr.length - 1));
					str += arr[pos];
				}
				return str;
			}
			collapse_click = function(id) { // 大力爆改css
				var ptitle = document.getElementById(id);
				if(id.match("disp") == null) {
					ptitle.attributes.getNamedItem("style").value = "display:none";
					document.getElementById(id+"-disp").attributes.getNamedItem("style").value = "display:visible";
					document.getElementById(id.replace("-title", "-content")).attributes.getNamedItem("style").value = "display:visible";
				} else {
					ptitle.attributes.getNamedItem("style").value = "display:none";
					document.getElementById(id.replace("-disp", "").replace("-title", "-content")).attributes.getNamedItem("style").value = "display:none";
					document.getElementById(id.replace("-disp", "")).attributes.getNamedItem("style").value = "display:visible";
				}
			}
						collapse_preprocess = function() {
				var col_arr = document.getElementsByClassName("collapse-box");
				for(var i = 0; i<col_arr.length; i++) {
					var hashcode = random_string(16);
					// console.log(col_arr[i].childNodes);
					for(var j = 0; j<col_arr[i].childNodes.length; j++) {
						if(col_arr[i].childNodes[j].className == "collapse-box-title") {
							var ap_id = document.createAttribute("id");
							ap_id.value = "col-title-"+hashcode;
							col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
							ap_id = document.createAttribute("onclick");
							ap_id.value = "collapse_click(this.id)";
							col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
						} else if(col_arr[i].childNodes[j].className == "collapse-display-title") {
							var ap_id = document.createAttribute("id");
							ap_id.value = "col-title-"+hashcode+"-disp";
							col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
							ap_id = document.createAttribute("onclick");
							ap_id.value = "collapse_click(this.id)";
							col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
						} else if(col_arr[i].childNodes[j].className == "collapse-box-content") {
							var ap_id = document.createAttribute("id");
							ap_id.value = "col-content-"+hashcode;
							col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
						}
					}
				}
			}
			
			collapse_preprocess();