User:Alexsh/monobook.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer / Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
- 此腳本缺少說明文檔。您可以協助創建。
- 相關-{zh-hans:链接; zh-hant:連接}-:根頁面 • 根頁面的子頁面 • -{zh-hans:链入; zh-hant:連入}- • -{zh-hans:重定向; zh-hant:重新導向}- • 您的對應頁面
本JavaScript腳本會在User:Alexsh使用Monobook外觀時,在每次Alexsh載入頁面時執行。
/*所有用戶在加載任何頁面時,這裡的JavaScript都會加載
=== 辅助处理 ===
<pre>*/
// 兼容性修正
if (window.showModalDialog && document.compatMode && document.compatMode == "CSS1Compat")
{
var oldWidth;
var docEl = document.documentElement;
function fixIEScroll()
{
if (!oldWidth || docEl.clientWidth > oldWidth){
doFixIEScroll();
}else{
setTimeout(doFixIEScroll, 1);
}
oldWidth = docEl.clientWidth;
}
function doFixIEScroll() {
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
}
document.attachEvent("onreadystatechange", fixIEScroll);
attachEvent("onresize", fixIEScroll);
}
// 移動元素
function elementMoveto(node, refNode, pos){//默认位置为refNode前
if(node && refNode){
var parent=refNode.parentNode;
if (pos && pos=='after') {refNode=refNode.nextSibling;}
try {
parent.insertBefore(node, refNode);
} catch (DOMException) {};
}
}
//导入模板
function importScript( page ) {
var url = /^https?:\/\//.test(page) ? page
: wgScriptPath + '/index.php?title=' + encodeURI( page.replace( ' ', '_' ) )
+ '&action=raw&ctype=text/javascript&dontcountme=s';
var scriptElem = document.createElement( 'script' );
scriptElem.setAttribute( 'src' , url );
scriptElem.setAttribute( 'type' , 'text/javascript' );
document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
}
function importStylesheet( page ) {
var sheet = /^https?:\/\//.test(page) ? page
: wgScriptPath + '/index.php?title=' + encodeURI( page.replace( ' ', '_' ) )
+ '&action=raw&ctype=text/css';
var styleElem = document.createElement( 'style' );
styleElem.setAttribute( 'type' , 'text/css' );
styleElem.appendChild( document.createTextNode( '@import "' + sheet +'";' ) );
document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
}
/* 测试元素中是否含有指定的样式 **************************************
*
* Description: 使用正则式与缓存来提高性能
* Maintainers: User:fdcn @zh.wikipedia
* [[en:User:Mike Dillon]], [[en:User:R. Koot]], [[en:User:SG]] @en.wikipedia
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
//设置中文语言页
var htmlE=document.documentElement;
htmlE.setAttribute("lang",wgUserLanguage);
htmlE.setAttribute("xml:lang",wgUserLanguage);
//返回繁簡字串
function wgULS(cn,tw,hk,sg){
//保證每一語言有值
zh=cn||tw||hk||sg;
cn=cn||sg;
sg=sg||cn;
tw=tw||hk;
hk=hk||tw;
switch(wgUserLanguage){
case "zh": return zh;
case "zh-cn": return cn;
case "zh-tw": return tw;
case "zh-hk": return hk;
case "zh-sg": return sg;
default: return "";
}
}
/*</pre>
=== 工具提示與快捷鍵 ===
<pre>*/
ta = {};
ta['ca-article'] = ['a',wgULS('浏览条目正文','流覽條目正文')];
ta['ca-nomove'] = ['',wgULS('你不能移动这个页面','你不能移動這個頁面')];
ta['n-Featured_articles']=['',wgULS('查看中文维基百科的特色条目','查看中文維基百科的特色條目')];
ta['n-Featured_content']=['',wgULS('查看中文维基百科的特色内容','查看中文維基百科的特色內容')];
ta['n-commonsupload'] = ['',wgULS('把自由版权图片上传到维基共享资源','把自由版權圖片上傳到維基共享資源')];
ta['n-contact'] = ['',wgULS('如何联络维基百科','如何聯絡維基百科')];
ta['n-villagepump'] = ['',wgULS('参与维基百科社群的讨论','參與維基百科社群的討論')];
ta['n-Information_desk'] = ['',wgULS('解答任何与维基百科无关的问题的地方','解答任何與維基百科無關的問題的地方')];
ta['n-conversion'] = ['',wgULS('提出繁简体转换请求','提出繁簡體轉換請求')];
ta['n-allpages'] = ['',wgULS('浏览所有页面的清单','流覽所有頁面的清單')];
ta['ca-nstab-wp'] = ['a',wgULS('查看维基计划页面','查看維基計畫頁面')];
/*</pre>
=== 特色條目優良與條目鏈接顯示===
<pre>*/
$(function()
{
if ( document.getElementById( "p-lang" ) ) {
var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) ) {
InterwikiLinks[i].className += " FA"
InterwikiLinks[i].title = wgULS("此条目为特色条目。","此條目為特色條目。");
}
if ( document.getElementById( InterwikiLinks[i].className + "-ga" ) ) {
InterwikiLinks[i].className += " GA"
InterwikiLinks[i].title = wgULS("此条目为优良条目。","此條目為優良條目。");
}
}
}
});
/*</pre>
=== 調整編輯工具欄===
mwEditButtons , mwCustomEditButtons 为预设按钮集合
<pre>*/
if (mwCustomEditButtons)
{
function addEditButton(imageFile, tagOpen, sampleText, tagClose, speedTip, imageId){
mwCustomEditButtons.push({
"imageId": imageId,
"imageFile": "http://upload.wikimedia.org/wikipedia/" + imageFile,
"tagOpen": tagOpen,
"sampleText": sampleText,
"tagClose": tagClose,
"speedTip": speedTip
});
}
var __temp;
addEditButton('commons/f/f3/Internal_link_icon.png','[[','链接标题',']]','内部链接','btnInterLink');
addEditButton("commons/9/93/Button_sub_link.png", wgULS("[[条目#","[[條目#"), wgULS("章节|文本","章節|文本"), "]]", wgULS("内部段落链接","內部段落連結"),'btnInterHashLink' );
addEditButton("commons/b/b0/Button_category02.png", "[[:Category:", wgULS("分类名","分類名"), "]]", wgULS("分类链接","分類連接"),'btnCategoryLink');
addEditButton('commons/9/9d/Media_icon.png','[[Media:','Example.ogg',']]','媒体文件链接','btnMediaLink');
addEditButton('commons/7/73/External_link_icon.png','[','http://www.example.com 链接标题',']','外部链接(加前缀 http://)','btnExtraLink');
addEditButton("commons/9/97/Template_button.png", "{{", "模板名", "}}", wgULS("应用模板","應用模板"),'btnTemplateLink');
addEditButton("commons/b/b4/Button_category03.png", "[[Category:", wgULS("分类名","分類名"), "]]", wgULS("分类","分類"),'btnCategory');
addEditButton("commons/4/47/Button_redir.png", "#REDIRECT [[", wgULS("目标条目名","目標條目名"), "]]", "重定向",'btnRedirect');
addEditButton('commons/f/f0/Image_icon.png','[[Image:','Example.jpg',']]','嵌入图像','btnImage');
addEditButton("commons/1/1c/Button_advanced_image.png",
"<imagemap>\n",
"Image:圖像名 | 100px | 描述\nrect 0 0 50 50 [[鏈接]]\ncircle 50 50 20 [[鏈接B]]\ndesc bottom-left\n",
"</imagemap>",
wgULS("高级画像", "高级画像"),
'btnAdvImage'
);
__temp="\nImage:PictureFileName.jpg|"+wgULS("图片题注","圖片題注");
addEditButton("commons/9/9e/Btn_toolbar_gallery.png","<gallery>",__temp+__temp,"\n</gallery>",wgULS("画廊", "畫廊"),'btnGallery' );
addEditButton('commons/5/5b/Math_icon.png','\<math\>','插入数学公式','\</math\>','插入数学公式(LaTeX)','btnMath');
addEditButton('commons/8/82/Nowiki_icon.png','\<nowiki\>','插入非格式文本','\</nowiki\>','插入非格式文本','btnNowiki');
addEditButton('commons/6/6d/Button_sig.png','','~~~','','签名(无日期)','btnSigOnly');
addEditButton('commons/c/c7/Signature_icon.png','','—~~~~','','签名','btnSignature');
addEditButton('commons/e/e9/Button_headline2.png','\n== ','标题文字',' ==\n','2级标题文字','btnHeadline2');
addEditButton("commons/3/3a/Button_headline3.png", "=== ", wgULS("标题文本","標題文本"), " ===", wgULS("三级子标题","三級子標題"),'btnHeadline3' );
addEditButton('commons/a/a4/H-line_icon.png','\n----\n','','',wgULS('水平线','水平線'),'btnHr' );
addEditButton("commons/1/13/Button_enter.png", "<br />", "", "", wgULS("换行","換行"),'btnBr' );
addEditButton('commons/6/6f/Bold_icon.png','\'\'\'','粗体','\'\'\'','粗体','btnBold');
addEditButton('commons/d/d7/Italic_icon.png','\'\'','斜体','\'\'','斜体','btnItalic');
__temp=wgULS("下划线","下劃線");
addEditButton('commons/f/fd/Button_underline.png','<span style="text-decoration: underline;">',__temp,'</span>',__temp,'btnUnderline');
__temp=wgULS("删除线","刪除線");
addEditButton("commons/c/c9/Button_strike.png", "<del>",__temp, "</del>",__temp,'btnStrike');
__temp=wgULS("左对齐","左對齊");
addEditButton("commons/e/ea/Button_align_left.png", '<div style="text-align: left;">\n',__temp, "\n</div>",__temp,'btnAlignLeft');
addEditButton("commons/5/5f/Button_center.png", '<div style="text-align: center;">\n', "居中", "\n</div>", "居中",'btnAlignCenter');
__temp=wgULS("右对齐","右對齊");
addEditButton("commons/a/a5/Button_align_right.png", '<div style="text-align: right;">\n',__temp, "\n</div>",__temp,'btnAlignRight');
__temp=wgULS("上标","上標");
addEditButton("commons/6/6a/Button_sup_letter.png", "<sup>",__temp, "</sup>", __temp,'btnSup');
__temp=wgULS("下标","下標");
addEditButton("commons/a/aa/Button_sub_letter.png", "<sub>",__temp, "</sub>",__temp,'btnSub');
addEditButton("commons/5/56/Button_big.png", '<span style="font-size:larger;">', "放大", "</span>", "放大",'btnBig');
__temp=wgULS("缩小","縮小");
addEditButton("commons/5/58/Button_small.png", '<span style="font-size:smaller;">',__temp, "</span>",__temp,'btnSmall');
addEditButton("commons/8/8e/Button_shifting.png", ":", "", "", wgULS("缩进","縮進"),'btnShift' );
addEditButton("commons/8/88/Btn_toolbar_enum.png", "#", "", "", wgULS("数字列表","數字列表"),'btnEnum' );
addEditButton("commons/1/11/Btn_toolbar_liste.png", "*", "", "", wgULS("符号列表","符號列表"),'btnList' );
addEditButton("commons/1/1e/Button_font_color.png", '<span style="color: ColorName;">', "彩色文本", "</span>", "彩色文本",'btnColor');
addEditButton("commons/f/fd/Button_blockquote.png", '{\{quote|\n', "引文", "\n}\}", wgULS("块引用","塊引用"),'btnQuote' );
addEditButton("commons/2/23/Button_code.png", "<code>", wgULS("代码","代碼"), "</code>", wgULS("代码文本","代碼文本"),'btnCode' );
addEditButton("commons/d/d3/Button_definition_list.png", "\n; ", wgULS("释义","釋義") , " : ", wgULS("定义文本","定義文本"),'btnDefine' );
addEditButton("commons/3/34/Button_hide_comment.png", "<!-- ", wgULS("隐藏文字","隱藏文字"), " -->", wgULS("注释或隐藏文字","注釋或隱藏文字"),'btnComment' );
addEditButton("commons/0/04/Button_array.png",'\n{| border="1" \n|- \n| 第一部分 || 第二部分 \n|- \n| 第三部分 || 第四部分',"","\n|}\n", "插入表格",'btnTable');
__temp=wgULS("参考","參考");
addEditButton("commons/c/c4/Button_ref.png", "<ref>", __temp, "</ref>", __temp, 'btnRef' );
__temp=wgULS("同项参考","同項參考");
addEditButton("commons/c/cf/Button_ref_adv.png", '<ref name="">', __temp, '</ref>', __temp, 'btnRef2' );
addEditButton("commons/f/fe/Button_refs.png", '\n==参考文献==\n<div class="references-small">\n<references />\n</div>', '', '', wgULS("参考文献区","參考文獻區"), 'btnReferences' );
delete __temp;
addOnloadHook(function(){
mwEditButtons=[];
});
}
// 調整工具
var edittoolButtons=[];
hookEvent("load",function(){
var wpEditToolbar=document.getElementById("toolbar");
if(wpEditToolbar){
//移動下拉選單
var dropdownListEditTools=document.getElementById("dropdownListEditTools");
if(wpEditToolbar&&dropdownListEditTools){
wpEditToolbar.appendChild(dropdownListEditTools);
}
//dropdownListEditTools.style.display="inline";
//移動符號表
var editspecialchars=document.getElementById("editpage-specialchars");
elementMoveto(editspecialchars , wpEditToolbar , 'after' );
var btns = wpEditToolbar.getElementsByTagName("img");
for(var i=0,btn;btn=btns[i];i++){
edittoolButtons.push(btn);
if(btn.id){edittoolButtons[btn.id]=btn;}
}
// ref2 SigOnly 按鈕變小
edittoolButtons.btnRef2.width = 12;
edittoolButtons.btnSigOnly.width = 11;
}
});
/*</pre>
=== 增加特殊符號的下拉選單 ===
<pre>*/
/* add menu for selecting subsets of secial characters */
/***** must match MediaWiki:Edittools *****/
/* select subsection of special characters */
function chooseCharSubset(s) {
var l = document.getElementById('editpage-specialchars').getElementsByTagName('p');
for (var i = 0; i < l.length ; i++) {
l[i].style.display = i == s ? 'inline' : 'none';
l[i].style.visibility = i == s ? 'visible' : 'hidden';
}
}
$(function(){
var edittools = document.getElementById('editpage-specialchars');
if (edittools) {
var name;
var menu=document.createElement("select");
menu.style.display="inline";
var lines = edittools.getElementsByTagName('p');
for (var i = 0,p; p=lines[i] ; i++) {
if(p.title){name=p.title;}
else {name = p.id;}
menu.options[menu.options.length]=new Option(name);
}
menu.onchange=function(){chooseCharSubset(this.selectedIndex);};
edittools.insertBefore(menu,edittools.firstChild);
chooseCharSubset(0);
}
});
/*</pre>
=== 編輯首段 ===
<pre>*/
var wgIsEdit0=true;//设置开关,对不需要编辑首段的页面,还可在页面中加{{Noedit0}}模板
if (wgIsArticle) {
addOnloadHook(function(){
if(!wgIsEdit0||(document.getElementById&&document.getElementById('no-edit-0'))){return;}
var caEdit=document.getElementById&&document.getElementById('ca-edit');
if (!caEdit){return;}
var caEdit0 = document.createElement('LI');
var id = caEdit0.id = 'ca-edit-0';
ta[id] = ['0', wgULS('编辑首段','編輯首段')];
caEdit0.className = caEdit.className;
caEdit.className = 'istalk';
var link = document.createElement('A');
link.href = caEdit.firstChild.href + '§ion=0';
link.appendChild(document.createTextNode('0'));
caEdit0.appendChild(link);
caEdit.parentNode.insertBefore(caEdit0,caEdit.nextSibling);
//单独进行提示和快捷键处理
updateTooltipAccessKeys([caEdit0]);
akeytt(id);
});
}
/*</pre>
=== 增加折疊功能 ===
<pre>*/
/** 折疊 div table *****************************
*
* Description: 实现div.NavFrame和table.collapsible的可折叠性。
* Maintainers: User:fdcn
*/
var collapseText=wgULS('隐藏▲','隱藏▲');
var expandText=wgULS('显示▼','顯示▼');
var autoCollapse = 2;//文章少于 autoCollapse 个折叠块时,不自动折叠
function createSpan(defaultText){
var span = document.createElement('span');
span.appendChild( document.createTextNode(defaultText));
return span;
}
$(function(){
function toggleState(item){
var nstate=1-item.state;
if(item.text[0]){
item.text[item.state].style.display = 'inline';
item.text[nstate].style.display='none';
}
item.state=nstate;
item.action(item);
}
function createToggleButton(head,frame,toggle){
var textS,textH;
var button=getElementsByClassName(head,"span","NavToggle")[0];
if(button){
textS=getElementsByClassName(button,"span","NavToggleShow")[0]
textH=getElementsByClassName(button,"span","NavToggleHide")[0];
}else {
button=createSpan("");
textS=createSpan(expandText); textH=createSpan(collapseText);
button.appendChild(textS); button.appendChild(textH);
button.className = "NavToggle";
button.style.width = "3.8em";
}
if(textS){textS.style.display='none';}
var item={'state':0, 'text':[textS,textH],'frame':frame,'action':toggle}
button.onclick=function(){toggleState(item);}
head.insertBefore( button, head.childNodes[0] );
return item;
}
// 折疊div
function toggleNavigationBar(item)
{
var cls=item.state?'none':'block';
for (
var NavChild = item.frame.firstChild;
NavChild != null;
NavChild = NavChild.nextSibling
){
if (NavChild.className == 'NavPic' || NavChild.className == 'NavContent') {
NavChild.style.display = cls;
}
}
}
// 折疊表格
function collapseTable( item )
{
var rows = item.frame.getElementsByTagName( "tr" );
var rowsLen=rows.length;
if (item.state ) {
for ( var i = 1; i < rowsLen; i++ ) {
rows[i].style.display = "none";
}
} else {
for ( var i = 1; i < rowsLen; i++ ) {
rows[i].style.display = rows[0].style.display;
}
}
}
//init
var item,items=[];
var NavFrames=getElementsByClassName(document,"div","NavFrame");
for(var i=0,NavFrame;NavFrame = NavFrames[i];i++) {
var heads=getElementsByClassName(NavFrame,"div","NavHead");
for(var ih=0,head; head = heads[ih]; ih++ ) {
if (head.parentNode != NavFrame) {continue;}
items.push(createToggleButton(head,NavFrame,toggleNavigationBar));
break;
}
}
var tables = getElementsByClassName(document,"table","collapsible");
for ( var i = 0,table; table= tables[i]; i++ ) {
var head = table.getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
items.push(createToggleButton(head,table,collapseTable));
}
var count=items.length;
for ( var i = 0; i<count; i++ ) {
item=items[i];
if ( hasClass( item.frame, "collapsed" ) || ( count >= autoCollapse && hasClass( item.frame, "autocollapse" ) ) ) {
toggleState(item);
}
}
});
//修正折疊後定位變化
hookEvent("load",function(){if(location.hash){location.href=location.hash;}});
/*</pre>
=== 頁面首字大寫修正 ===
<pre>*/
/** "Technical restrictions" title fix *****************************************
*
* Description:
* Maintainers: [[:en:User:Interiot]], [[:en:User:Mets501]]
*/
// For pages that have something like Template:Lowercase, replace the title, but only if it is cut-and-pasteable as a valid wikilink.
// (for instance [[iPod]]'s title is updated. <nowiki>But [[C#]] is not an equivalent wikilink, so [[C Sharp]] doesn't have its main title changed)</nowiki>
//
// The function looks for a banner like this: <nowiki>
// <div id="RealTitleBanner"> <!-- div that gets hidden -->
// <span id="RealTitle">title</span>
// </div>
// </nowiki>An element with id=DisableRealTitle disables the function.
var disableRealTitle = 0; // users can disable this by making this true from their monobook.js
if (wgIsArticle) { // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
addOnloadHook(function(){
try {
var realTitleBanner = document.getElementById("RealTitleBanner");
if (realTitleBanner && !document.getElementById("DisableRealTitle") && !disableRealTitle) {
var realTitle = document.getElementById("RealTitle");
if (realTitle) {
var realTitleHTML = realTitle.innerHTML;
realTitleText = pickUpText(realTitle);
var isPasteable = 0;
//var containsHTML = /</.test(realTitleHTML); // contains ANY HTML
var containsTooMuchHTML = /</.test( realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "") ); // contains HTML that will be ignored when cut-n-pasted as a wikilink
// calculate whether the title is pasteable
var verifyTitle = realTitleText.replace(/^ +/, ""); // trim left spaces
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
// if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
if (wgNamespaceNumber != 0) {
if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
} else {
realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
}
}
// verify whether wgTitle matches
verifyTitle = verifyTitle.replace(/^ +/, "").replace(/ +$/, ""); // trim left and right spaces
verifyTitle = verifyTitle.replace(/_/g, " "); // underscores to spaces
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
isPasteable = (verifyTitle == wgTitle);
var h1 = document.getElementsByTagName("h1")[0];
if (h1 && isPasteable) {
h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
if (!containsTooMuchHTML)
realTitleBanner.style.display = "none";
}
document.title = realTitleText + " - Wikipedia, the free encyclopedia";
}
}
} catch (e) {
/* Something went wrong. */
}
});
}
// similar to innerHTML, but only returns the text portions of the insides, excludes HTML
function pickUpText(aParentElement) {
var str = "";
function pickUpTextInternal(aElement) {
var child = aElement.firstChild;
while (child) {
if (child.nodeType == 1) // ELEMENT_NODE
pickUpTextInternal(child);
else if (child.nodeType == 3) // TEXT_NODE
str += child.nodeValue;
child = child.nextSibling;
}
}
pickUpTextInternal(aParentElement);
return str;
}
/*</pre>
=== 取消修訂編輯摘要修正 ===
<pre>*/
//fix edit summary prompt for undo
//this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the
//edit summary unchanged
//this was added by [[:en:User:Deskana]], code by [[:en:User:Tra]]
$(function () {
if (document.location.search.indexOf("undo=") != -1
&& document.getElementsByName('wpAutoSummary')[0])
{
document.getElementsByName('wpAutoSummary')[0].value='';
}
})