User:Super1/Friendlist.js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/*'''本页可以任意复制,可直接通过设置常数修改功能'''
'''''注:此monobook.js在[[Mozilla Firefox]]下调试,还未使用[[Internet Explorer]]测试过'''''*/
/*<pre><nowiki>*/
/*
Version 20060212 稳定版
Browser Only for Firefox 1.5.0.1+
*/
//常数设置
const IS_USE_PLUS = true; //总开关
const IS_DEL_LANGCHANGE = true; //是否删除语言转换标签
const IS_ADD_ADDSECTION = true; //是否在讨论前添加"+"
const IS_ADD_PURGE = true; //是否添加刷新标签
const IS_CHANGE_PREFERENCES = true; //是否将”参数设置“移至工具栏
const IS_CHANGE_UPDATE = true; //是否将”上传文件“移至顶栏
const IS_CHANGE_PRINT = true; //是否将“可打印版本”移至标签
const IS_CHANGE_SPECIAL = true; //是否将“特殊页面”移至“导航”
const IS_MOVE_SEARCH = true; //是否将“搜索”栏上移
const USE_FRIENDLIST = true; //是否启用好友列表
const FRIEND_LIST_URL = "/w/index.php?title=User:究极人类/好友&action=raw";
const FRIEND_SHOW = false; //默认是否显示好友列表
const HOW_CHANGE_OL = 2; //如何删减其他语言(0不进行,1删除指定的,2只保留指定的)
const OTHER_LANGUAGE_TYPE = "en|ja|ru|eo|simple"; //根据上面对其他语言的操作列表,使用“|”分割
const IS_AUTO_ADD_WELCOME = true; //是否启用自动添加欢迎信息
const WELCOME = '{{subst:User:究极人类/Welcome}}'; //欢迎信息(其他人可以使用'{{subst:Welcome}}')
const WELCOMEIP = '{{subst:Welcomeip}}--~~~~'; //欢迎IP
const IS_REPLACE_CATEGORY = true; //是否将分类前偶尔出现的“Category”替换为“页面分类”
//变量信息
var strFirendList, objFriendList;
//删除标签
function dellilink(tabs, li){
if (li && tabs) tabs.removeChild(li);
return;
}
//添加标签(载自阿福的monobook.js)
function addlilink(tabs, url, name, id){
var na = document.createElement('a');
na.href = url;
na.id = id;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.appendChild(na);
tabs.appendChild(li);
return li;
}
//插入标签
function insertlilink(tabs, url, name, id, nextobj){
if (!tabs) return;
if (!nextobj){
addlilink(tabs, url, name, id);
return;
}
var na = document.createElement('a');
na.href = url;
na.id = id;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.appendChild(na);
tabs.insertBefore(li, nextobj);
return li;
}
//移动标签
function movelilink(tabs, theobj, newtabs, id, nextobj){
if (!(tabs && theobj && newtabs)) return;
var y = theobj;
if (y.children) y = y.children[0];
else y = y.childNodes[0];
var xname = y.text;
y = y.href;
dellilink(tabs, theobj);
if (!nextobj) y = addlilink(newtabs, y, xname, id);
else y = insertlilink(newtabs, y, xname, id, nextobj);
return y;
}
//删除语言转换标签
function delLangchange(){
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
var i = 0;
var x = document.getElementById('ca-varlang-' + i);
while (x) {
dellilink(tabs, x);
i++;
x = document.getElementById('ca-varlang-' + i);
}
return;
}
//在讨论前添加"+"标签
function addAddsection(){
var x = document.getElementById('ca-addsection');
if (x) return;
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
x = document.getElementById('ca-talk');
var y = document.getElementById('ca-talk');
if (!(y || x)) return;
if (y.children) y = y.children[0];
else y = y.childNodes[0];
insertlilink(tabs, y.href + "§ion=new", '+', 'ca-addsection', x);
return;
}
//添加清缓存标签(翻译自阿福的monobook.js)
function addPurge(){
ta['ca-purge'] = ['g', '清空这个页面的缓存'];
if(!document.getElementById) return;
var x = document.getElementById('ca-history');
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(!x) x = document.getElementById('ca-article');
if(x.children) x = x.children[0];
else x = x.childNodes[0];
addlilink(tabs, x.href.replace(/=history/, "=purge"), '刷新', 'ca-purge');
return;
}
//将”参数设置“移至工具栏
function changePreferences(){
var tabs = document.getElementById('p-personal').getElementsByTagName('ul')[0];
var x = document.getElementById('pt-preferences');
var ntabs = document.getElementById('p-tb').getElementsByTagName('ul')[0];
movelilink(tabs, x, ntabs, 'pt-preferences', false);
return;
}
//从“工具”栏移出
function changeSome(){
var tabs = document.getElementById('p-tb').getElementsByTagName('ul')[0];
var x;
var ntabs;
var y;
//将”上传文件“移至顶栏
if (IS_CHANGE_UPDATE){
x = document.getElementById('t-upload');
ntabs = document.getElementById('p-personal').getElementsByTagName('ul')[0];
y = document.getElementById('pt-watchlist');
movelilink(tabs, x, ntabs, 't-upload', y);
}
//是否将“可打印版本”移至标签
try{
if (IS_CHANGE_PRINT){
x = document.getElementById('t-print');
ntabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
x = movelilink(tabs, x, ntabs, 't-print', false);
x = x.getElementsByTagName('a')[0];
x.target = "_blank";
}}catch(e) {}
//是否将“特殊页面”移至“导航”
if (IS_CHANGE_SPECIAL){
x = document.getElementById('t-specialpages');
ntabs = document.getElementById('p-navigation').getElementsByTagName('ul')[0];
y = document.getElementById('n-randompage');
movelilink(tabs, x, ntabs, 't-specialpages', y);
}
return;
}
//把“搜索”栏向上移
function moveSearch(){
var theparent = document.getElementById('column-one');
var x = document.getElementById('p-search');
var thenext = document.getElementById('p-help');
x.id = 'p-search-old';
var y = x.cloneNode(true);
y.id = 'p-search';
theparent.insertBefore(y, thenext);
theparent.removeChild(x);
return;
}
//添加好友列表
function addFriendlist(){
var listDiv = document.createElement('div');
var theparent = document.getElementById('column-one');
var thenext = document.getElementById('p-help');
listDiv.className = 'portlet';
listDiv.id = 'p-friendlist';
theparent.insertBefore(listDiv, thenext);
var childOfList = document.createElement('h5');
listDiv.appendChild(childOfList);
childOfList2 = document.createElement('a');
childOfList2.id = "isshow-friendlist";
childOfList2.appendChild(document.createTextNode('+'));
childOfList2.href = "javascript:showFriendList();";
childOfList.appendChild(childOfList2);
childOfList.appendChild(document.createTextNode(' 好友列表['));
childOfList2 = document.createElement('a');
childOfList2.href = FRIEND_LIST_URL.replace("&action=raw", "&action=edit");
childOfList2.appendChild(document.createTextNode('编辑'));
childOfList.appendChild(childOfList2);
childOfList.appendChild(document.createTextNode(']'));
childOfList = document.createElement('div');
childOfList.className = 'pBody';
listDiv.appendChild(childOfList);
var childOfList2 = document.createElement('ul');
childOfList.appendChild(childOfList2);
var tmpObj = document.createTextNode('正在获取好友列表...');
childOfList2.appendChild(tmpObj);
var xmlHTTP;
try{xmlHTTP=new ActiveXObject('Msxml2.XMLHTTP') } catch(e) {xmlHTTP=new XMLHttpRequest()}
xmlHTTP.open("GET", FRIEND_LIST_URL + "&ctype=text/" + Math.random(), false);
xmlHTTP.setRequestHeader("If-Modified-Since", "");
xmlHTTP.setRequestHeader("If-None-Match", "");
xmlHTTP.setRequestHeader("Cache-Control", "no-cache");
xmlHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHTTP.send("");
strFirendList = xmlHTTP.responseText;
objFriendList = childOfList2;
if (FRIEND_SHOW) showFriendList();
childOfList2.removeChild(tmpObj);
xmlHTTP = null;
return;
}
//显示好友列表
function showFriendList(){
var stringArray = strFirendList.split('\n');
var stringArray2;
var strName, strShow;
var na, li;
for (var i = 2; i < stringArray.length; i++){
stringArray2 = stringArray[i].split(' ');
strName = stringArray2[0];
strShow = stringArray2[1];
if (!strShow) strShow = strName;
li = addlilink(objFriendList, '/wiki/User:' + strName, strShow, 'user-' + strName);
li.appendChild(document.createTextNode('('));
na = document.createElement('a');
na.href = '/wiki/User_talk:' + strName;
na.appendChild(document.createTextNode('Talk'));
li.appendChild(na);
na = document.createElement('a');
na.href = '/w/index.php?title=User_talk:' + strName + '&action=edit§ion=new';
li.appendChild(document.createTextNode(' '));
na.appendChild(document.createTextNode('+'));
li.appendChild(na);
li.appendChild(document.createTextNode(')'));
}
var childs = document.getElementById('isshow-friendlist');
childs.href = "javascript:hideFriendList();";
var childs2;
if (childs.children) childs2 = childs.children[0];
else childs2 = childs.childNodes[0];
dellilink(childs, childs2);
childs.appendChild(document.createTextNode("-"));
}
//隐藏好友列表
function hideFriendList(){
var childs;
if (objFriendList.children) childs = objFriendList.children;
else childs = objFriendList.childNodes;
for (var i = 0; i < childs.length; i++){
dellilink(objFriendList, childs[i]); i--;
}
childs = document.getElementById('isshow-friendlist');
childs.href = "javascript:showFriendList();";
var childs2;
if (childs.children) childs2 = childs.children[0];
else childs2 = childs.childNodes[0];
dellilink(childs, childs2);
childs.appendChild(document.createTextNode("+"));
}
//在搜索栏添加“编辑”(未调试完成,已禁用)
function addEdit(){
var btnEdit = document.createElement('input');
btnEdit.type = 'button';
btnEdit.name = 'goEdit';
btnEdit.id = 'goEdit';
btnEdit.className = 'searchButton';
btnEdit.value = '编辑';
var x = document.getElementById('searchform');
x.appendChild(document.createTextNode(' '));
x.appendChild(btnEdit);
return;
}
//删减语言栏
function delSomeOfOtherLanguage(){
var tabs = document.getElementById('p-lang');
if (!tabs) return;
tabs = tabs.getElementsByTagName('ul')[0];
var delLang = OTHER_LANGUAGE_TYPE.split("|");
var childs;
if (tabs.children) childs = tabs.children;
else childs = tabs.childNodes;
var i, j;
if (HOW_CHANGE_OL == 0) return;
else if (HOW_CHANGE_OL == 1){
for (i = 0; i < childs.length; i++){
for (j = 0; j < delLang.length; j++){
if (childs[i].className == 'interwiki-' + delLang[j]){
dellilink(tabs, childs[i]); i--;
}
}
}
} else {
var IsHas;
for (i = 0; i < childs.length; i++){
IsHas = false;
for (j = 0; j < delLang.length; j++){
if (childs[i].className == 'interwiki-' + delLang[j]) {
IsHas = true;
break;
}
}
if (!IsHas){dellilink(tabs, childs[i]); i--;}
}
}
}
//自动添加欢迎信息
function addWelcome(){
var x = document.getElementById('ca-nstab-user');
var xname = document.title;
if ((!x) || (xname.indexOf('/') >= 0)) return;
x = document.getElementById('ca-talk');
if (!(x.className == 'selected new')) return;
var txt = document.editform.wpTextbox1;
if (xname.indexOf('.') >= 0) txt.value = WELCOMEIP;
else txt.value = WELCOME;
txt = document.editform.wpSummary;
txt.value = "Welcome";
x = document.getElementById('wpMinoredit');
if (x) x.checked = "checked";
return;
}
//将分类前偶尔出现的“Category”替换为“页面分类”
function replaceCategory(){
var objCategory = document.getElementById('catlinks');
if (!objCategory) return;
objCategory = objCategory.getElementsByTagName('a')[0];
var objChild;
if (objCategory.children) objChild = objCategory.children[0];
else objChild = objCategory.childNodes[0];
dellilink(objCategory, objChild);
objCategory.appendChild(document.createTextNode("页面分类"));
return;
}
//载入函数
function MyMain(){
if (!IS_USE_PLUS) return;
if (IS_DEL_LANGCHANGE) delLangchange();
if (IS_ADD_ADDSECTION) addAddsection();
if (IS_ADD_PURGE) addPurge();
if (IS_CHANGE_PREFERENCES) changePreferences();
try{changeSome();}catch(e){}
if (IS_MOVE_SEARCH) moveSearch();
if (USE_FRIENDLIST) addFriendlist();
//addEdit();
delSomeOfOtherLanguage();
if (IS_AUTO_ADD_WELCOME) addWelcome();
if (IS_REPLACE_CATEGORY) replaceCategory();
}
//载入(修改自阿福的monobook.js)
if (window.addEventListener) window.addEventListener("load",MyMain,false);
else if (window.attachEvent) window.attachEvent("onload",MyMain);
else{
window._old_ABCD_onload = window.onload;
window.onload = function(){
window._old_ABCD_onload();
MyMain();
}
}
/*</nowiki></pre>*/