LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Mobile.js”的版本间差异
跳转到导航
跳转到搜索
小 标签:移动版网页编辑 移动版编辑 |
(部分内容调整至gadget) 标签:移动版网页编辑 移动版编辑 |
||
第1行: | 第1行: | ||
/* 这里的任何JavaScript将为使用移动版网站的用户加载 */ |
/* 这里的任何JavaScript将为使用移动版网站的用户加载 */ |
||
//<nowiki> |
//<nowiki> |
||
// 经测试不可使用ES6语法 |
|||
const testVar = 1; |
|||
"use strict"; |
|||
(function($, mw) { |
|||
mw.hook( 'wikipage.content' ).add(function( $content ) { |
|||
const collapsibleContent = $content.find( '.mw-collapsible' ), |
|||
/* 引自[[moegirl:mediawiki:mobile.js]] */ |
|||
sortableContent = $content.find( 'table.sortable' ); |
|||
/* jquery.collapsible */ |
|||
// 折叠 |
|||
if ($content.find('.mw-collapsible').length) { |
|||
/* 引自[[moegirl:mediawiki:mobile.js]] */ |
|||
mw.loader.using('jquery.makeCollapsible').then(function() { |
|||
if (collapsibleContent.length) { |
|||
$('.mw-collapsible').makeCollapsible(); |
|||
mw.loader.using( 'jquery.makeCollapsible' ).then(function() { collapsibleContent.makeCollapsible(); }); |
|||
}); |
|||
} |
|||
// 表格排序 |
|||
if (sortableContent.length) { |
|||
mw.loader.using( 'jquery.tablesorter' ).then(function() { sortableContent.tablesorter(); }); |
|||
} |
|||
}); |
|||
$(function() { |
|||
/* jquery.tablesorter */ |
|||
// 快速编辑工具 |
|||
if ($content.find('table.sortable').length) { |
|||
if (['edit', 'submit'].includes( mw.config.get('wgAction') )) { |
|||
mw.loader.using('jquery.tablesorter').then(function() { |
|||
$( '.mw-editTools' ).insertBefore( '#wpTextbox1' ); |
|||
} |
|||
}); |
|||
} |
|||
if (mw.config.get( 'wgCanonicalSpecialPageName' ) == "Recentchanges") { |
|||
// 修改filter |
|||
mw.hook( 'structuredChangeFilters.ui.initialized' ).add(function() { |
|||
mw.loader.using( ['mediawiki.Uri', 'ext.gadget.site-lib'] ).then(function() { |
|||
const uri = new mw.Uri(), |
|||
invert = uri.query.invert || 0, |
|||
node = $( '.mw-rcfilters-ui-itemMenuOptionWidget-view-namespaces' ).first().clone() |
|||
.insertAfter( $( '.mw-rcfilters-ui-filterMenuSectionOptionWidget' ).first() ) |
|||
.attr('id', 'ooui-invert').removeClass( 'oo-ui-element-hidden' ) |
|||
.on('click', function() { window.location.href = uri.extend({ invert: 1 - invert }); }); |
|||
node.find( 'span.oo-ui-labelElement-label' ).text( wgULS("排除选项", "排除所選") ); |
|||
node.find( 'input' ).prop('checked', invert) |
|||
.next().toggleClass( 'oo-ui-icon-check', invert ); |
|||
}); |
|||
}); |
}); |
||
} |
|||
/* Mobile Navmenu by GFwiki */ |
|||
$.when( $.ready, mw.loader.using( 'ext.gadget.site-lib' ) ).then(function () { |
|||
$.when($.ready, mw.loader.using( 'ext.gadget.site-lib' )).then(function() { |
|||
if ( ['edit', 'submit'].includes( mw.config.get('wgAction') )) { $('.mw-editTools').insertBefore('#wpTextbox1'); } |
|||
const script = mw.config.get( 'wgScript' ), |
|||
pagename = mw.config.get( 'wgPageName' ), |
|||
// 页顶图标 |
|||
pageid = mw.config.get( 'wgArticleId' ), |
|||
nsid = mw.config.get( 'wgNamespaceNumber' ), |
|||
title = mw.config.get( 'wgTitle' ); |
|||
$('<div>').load(script + '/MediaWiki:MFSidebar #mw-content-text ul', function() { |
|||
isProtected = restrictionEdit.length + restrictionMove.length, |
|||
const nav = $(this).children(); |
|||
fullurl = '/zh?title=' + mw.config.get('wgPageName'), |
|||
if (pageid > 0) { |
|||
isMovable = (restrictionMove.length === 0 && mw.config.get( 'wgUserGroups' ).includes('user')) || |
|||
nav.append('<li><a href="' + script + '/Special:链入页面/' + pagename + '">' + |
|||
mw.config.get('wgUserGroups').includes(restrictionMove[0]); |
|||
'<i class="fa fa-quote-right"></i>' + |
|||
if (mw.config.get('wgAction') == 'view' && mw.config.get('wgIsArticle')) { |
|||
'<span>' + wgULS("链入页面", "連結至此的頁面") + '</span>' + |
|||
$( (isSysop ? '<li id="page-actions-protect" class="page-actions-menu__list-item"><a id="ca-protect" href="' + fullurl + '&action=protect" data-event-name="menu.protect" role="button" title="更改保护"><i class="fa fa-' + (isProtected? 'unlock' : 'lock') + '"></i></a></li><li id="page-actions-delete" class="page-actions-menu__list-item"><a id="ca-delete" href="' + fullurl + '&action=delete" data-event-name="menu.delete" role="button" title="删除"><i class="fa fa-cut"></i></a></li>' : '') + |
|||
'</a></li>' + |
|||
(isMovable ? '<li id="page-actions-move" class="page-actions-menu__list-item"><a id="ca-move" href="/zh/special:移动页面/' + mw.config.get('wgPageName') + '" data-event-name="menu.move" role="button" title="移动"><i class="fa fa-truck"></i></a></li>' : '') ).insertAfter('#language-selector'); |
|||
'<li><a href="' + script + '/Special:链出更改/' + pagename + '">' + |
|||
'<i class="fa fa-share-alt"></i>' + |
|||
'<span>' + wgULS("相关更改", "相關變更") + '</span>' + |
|||
'</a></li>' + |
|||
'<li><a href="' + script + '?title=Special:前缀索引&prefix=' + title + '/&namespace=' + nsid + '&stripprefix=1">' + |
|||
'<i class="fa fa-folder-open"></i>' + |
|||
'<span>' + wgULS("子页面", "子頁面") + '</span>' + |
|||
'</a></li>'); |
|||
} |
} |
||
console.log( 'setInterval: 等待移动版菜单加载完毕'); |
|||
const timerStart = mw.now(), |
|||
timer = setInterval(function() { |
|||
if ($('.menu ul').length === 0) { return; } |
|||
clearInterval(timer); |
|||
if (mw.config.get('wgCanonicalSpecialPageName') == "MobileDiff" && isUser && $('.revision-history-prev').length) { |
|||
mw.hook( 'mobile.menu' ).fire( $('.menu') ); |
|||
console.log('End setInterval: 移动版菜单加载完毕,用时 ' + (mw.now() - timerStart) + ' ms'); |
|||
if ( /\.\.\./.test(pagename) ) { return; } |
|||
$(".menu > ul").first().after(nav); |
|||
}, 200); |
|||
undoafter = $('.revision-history-prev a').attr('href').match(/\/(\d*)$/)[1]; |
|||
$('.mw-mf-diff-info__link-latest a:last-child').after('<a href="/zh?title=' + title + '&action=edit&undo=' + undo + '&undoafter=' + undoafter + '">(' + wgULS("撤销","復原") + ')</a>'); |
|||
} |
|||
if (mw.config.get('wgCanonicalSpecialPageName') == "History" && isUser) { |
|||
var list = $('.page-summary > a'), |
|||
oldid = []; |
|||
list.each(function() { |
|||
oldid.push( this.href.match(/[\/=](\d*)$/)[1] ); |
|||
}); |
|||
for(var i = 0; i < list.length - 1; i++) { |
|||
list.eq(i).append('<span style="font-size:0.9em">(<a href="/zh?title=' + title + '&action=edit&undo=' + oldid[i] + '&undoafter=' + oldid[i+1] + '">' + wgULS("撤销","復原") + '</a>)</span>'); |
|||
} |
|||
} |
|||
if (mw.config.get('wgCanonicalSpecialPageName') == "Recentchanges") { |
|||
var timerFilter = setInterval(function() { |
|||
if ($( '.mw-rcfilters-ui-itemMenuOptionWidget-view-namespaces' ).length) { |
|||
clearInterval(timerFilter); |
|||
const isReverted = /invert=1/.test(window.location.href); |
|||
var node = $( '.mw-rcfilters-ui-itemMenuOptionWidget-view-namespaces' ).first().clone().insertAfter( $( '.mw-rcfilters-ui-filterMenuSectionOptionWidget' ).first() ) |
|||
.attr('id','ooui-invert') |
|||
.removeClass('oo-ui-element-hidden') |
|||
.on('click',function() { |
|||
if (isReverted) { window.location.href = window.location.href + '&invert=0'; } |
|||
else { window.location.href = window.location.href + '&invert=1'; } |
|||
}), |
|||
inputbox = node.find( 'input' ); |
|||
inputbox[0].checked = isReverted; |
|||
if (isReverted) { inputbox.next().addClass('oo-ui-icon-check'); } |
|||
else { inputbox.next().removeClass('oo-ui-icon-check'); } |
|||
node.find( 'span.oo-ui-labelElement-label' ).text( wgULS("排除选项", "排除所選") ); |
|||
} |
|||
}, 100); |
|||
} |
|||
/* Mobile Navmenu by GFwiki */ |
|||
var menu = $('<div>'); |
|||
menu.load('/zh?title=MediaWiki:MFSidebar&variant=' + mw.config.get('wgUserLanguage') + ' #mw-content-text ul', function() { |
|||
var navlist = menu.children(); |
|||
if (mw.config.get('wgNamespaceNumber') >= 0) { |
|||
navlist.append('<li><a href="/zh/Special:链入页面/' + mw.config.get("wgPageName") + '"><i class="fa fa-quote-right"></i><span>' + wgULS("链入页面", "連結至此的頁面") + '</span></a></li><li><a href="/zh/Special:链出更改/' + mw.config.get("wgPageName") + '"><i class="fa fa-share-alt"></i><span>' + wgULS("相关更改", "相關變更") + '</span></a></li><li><a href="/zh?title=Special:前缀索引&prefix=' + mw.config.get("wgTitle") + '/&namespace=' + mw.config.get("wgNamespaceNumber") + '&stripprefix=1"><i class="fa fa-folder-open"></i><span>' + wgULS("子页面", "子頁面") + '</span>'); |
|||
} |
|||
var timer = setInterval(function() { |
|||
if ($('.menu ul').length) { |
|||
console.log("Mobile menu exists"); |
|||
clearInterval(timer); |
|||
navlist.insertAfter($(".menu > ul").first()); |
|||
} |
|||
}, 100); |
|||
}); |
|||
}); |
}); |
||
}); |
|||
})(jQuery, mediaWiki); |
|||
//</nowiki> |
//</nowiki> |
||
// [[category:作为模块的小工具]] [[category:不可关闭的小工具]] [[category:手机版小工具]] |
|||
// {{DEFAULTSORT:*}} |
2020年11月23日 (一) 07:26的版本
/* 这里的任何JavaScript将为使用移动版网站的用户加载 */ //<nowiki> // 经测试不可使用ES6语法 "use strict"; mw.hook( 'wikipage.content' ).add(function( $content ) { const collapsibleContent = $content.find( '.mw-collapsible' ), sortableContent = $content.find( 'table.sortable' ); // 折叠 /* 引自[[moegirl:mediawiki:mobile.js]] */ if (collapsibleContent.length) { mw.loader.using( 'jquery.makeCollapsible' ).then(function() { collapsibleContent.makeCollapsible(); }); } // 表格排序 if (sortableContent.length) { mw.loader.using( 'jquery.tablesorter' ).then(function() { sortableContent.tablesorter(); }); } }); $(function() { // 快速编辑工具 if (['edit', 'submit'].includes( mw.config.get('wgAction') )) { $( '.mw-editTools' ).insertBefore( '#wpTextbox1' ); } }); if (mw.config.get( 'wgCanonicalSpecialPageName' ) == "Recentchanges") { // 修改filter mw.hook( 'structuredChangeFilters.ui.initialized' ).add(function() { mw.loader.using( ['mediawiki.Uri', 'ext.gadget.site-lib'] ).then(function() { const uri = new mw.Uri(), invert = uri.query.invert || 0, node = $( '.mw-rcfilters-ui-itemMenuOptionWidget-view-namespaces' ).first().clone() .insertAfter( $( '.mw-rcfilters-ui-filterMenuSectionOptionWidget' ).first() ) .attr('id', 'ooui-invert').removeClass( 'oo-ui-element-hidden' ) .on('click', function() { window.location.href = uri.extend({ invert: 1 - invert }); }); node.find( 'span.oo-ui-labelElement-label' ).text( wgULS("排除选项", "排除所選") ); node.find( 'input' ).prop('checked', invert) .next().toggleClass( 'oo-ui-icon-check', invert ); }); }); } /* Mobile Navmenu by GFwiki */ $.when($.ready, mw.loader.using( 'ext.gadget.site-lib' )).then(function() { const script = mw.config.get( 'wgScript' ), pagename = mw.config.get( 'wgPageName' ), pageid = mw.config.get( 'wgArticleId' ), nsid = mw.config.get( 'wgNamespaceNumber' ), title = mw.config.get( 'wgTitle' ); $('<div>').load(script + '/MediaWiki:MFSidebar #mw-content-text ul', function() { const nav = $(this).children(); if (pageid > 0) { nav.append('<li><a href="' + script + '/Special:链入页面/' + pagename + '">' + '<i class="fa fa-quote-right"></i>' + '<span>' + wgULS("链入页面", "連結至此的頁面") + '</span>' + '</a></li>' + '<li><a href="' + script + '/Special:链出更改/' + pagename + '">' + '<i class="fa fa-share-alt"></i>' + '<span>' + wgULS("相关更改", "相關變更") + '</span>' + '</a></li>' + '<li><a href="' + script + '?title=Special:前缀索引&prefix=' + title + '/&namespace=' + nsid + '&stripprefix=1">' + '<i class="fa fa-folder-open"></i>' + '<span>' + wgULS("子页面", "子頁面") + '</span>' + '</a></li>'); } console.log( 'setInterval: 等待移动版菜单加载完毕'); const timerStart = mw.now(), timer = setInterval(function() { if ($('.menu ul').length === 0) { return; } clearInterval(timer); mw.hook( 'mobile.menu' ).fire( $('.menu') ); console.log('End setInterval: 移动版菜单加载完毕,用时 ' + (mw.now() - timerStart) + ' ms'); $(".menu > ul").first().after(nav); }, 200); }); }); //</nowiki> // [[category:作为模块的小工具]] [[category:不可关闭的小工具]] [[category:手机版小工具]] // {{DEFAULTSORT:*}}