LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-site-shared.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 标签:移动版网页编辑 移动版编辑 |
||
第3行: | 第3行: | ||
/** |
/** |
||
* @Description: 这里是桌面版和手机版通用的全局JS |
* @Description: 这里是桌面版和手机版通用的全局JS |
||
* @Functions: 1. 除[[Special:前缀索引]]外移除页面名称最后的"/" |
|||
* 2. [[MediaWiki:Edittools]]可定制的快速插入工具 |
|||
* 3. 嵌入外部站点时通知并建议跳转 |
|||
* 4. 防止错误创建其他用户的用户页 |
|||
* 5. 正确显示[[特殊:前缀索引/LLWiki:首页/当年今日/]] |
|||
* 6. 分类栏正确显示小写标题 |
|||
* @Author: 如无特殊说明,均为[[User:Bhsd]] |
* @Author: 如无特殊说明,均为[[User:Bhsd]] |
||
*/ |
*/ |
||
第29行: | 第35行: | ||
*/ |
*/ |
||
if (['edit', 'submit'].includes( action ) && mw.config.get( 'wgIsProbablyEditable' )) { |
if (['edit', 'submit'].includes( action ) && mw.config.get( 'wgIsProbablyEditable' )) { |
||
$(' |
$('#editform').on('click', 'span.mw-charinsert-item', function() { |
||
const $this = $(this); |
const $this = $(this); |
||
$('#wpTextbox1').textSelection( 'encapsulateSelection', { |
$('#wpTextbox1').textSelection( 'encapsulateSelection', { |
||
第40行: | 第46行: | ||
/** |
/** |
||
* @Function: 嵌入外部站点时进行提示 |
* @Function: 嵌入外部站点时进行提示 |
||
* @Dependencies: |
* @Dependencies: oojs-ui-windows, ext.gadget.site-lib |
||
* @Source: [[moegirl:mediawiki:common.js]] |
* @Source: [[moegirl:mediawiki:common.js]] |
||
* @EditedBy: [[User:Bhsd]] |
* @EditedBy: [[User:Bhsd]] |
||
第63行: | 第69行: | ||
/** |
/** |
||
* @Function: 点击其他用户主页面的红链不会进入创建页面 |
* @Function: 点击其他用户主页面的红链不会进入创建页面 |
||
* @Dependencies: |
* @Dependencies: mediawiki.Title |
||
*/ |
*/ |
||
mw.hook( 'wikipage.content' ).add(function($content) { // 必须立即解决,否则手机版会生成drawer |
mw.hook( 'wikipage.content' ).add(function($content) { // 必须立即解决,否则手机版会生成drawer |
||
第82行: | 第88行: | ||
*/ |
*/ |
||
if (pagename.startsWith( 'LLWiki:首页/当年今日/' ) && action == 'view') { |
if (pagename.startsWith( 'LLWiki:首页/当年今日/' ) && action == 'view') { |
||
// 非管理员不需要关心未创建的页面 |
|||
var downloaded = false; |
|||
var downloaded = mw.config.get( 'wgArticleId' ) === 0 && !mw.config.get( 'wgUserGroups' ).includes( 'sysop' ); |
|||
mw.hook( 'wikipage.content' ).add(function($content) { |
mw.hook( 'wikipage.content' ).add(function($content) { |
||
const $output = $content.children( '.mw-parser-output' ).addClass( 'mainpage-flex' ); |
const $output = $content.children( '.mw-parser-output' ).addClass( 'mainpage-flex' ); |
||
// 避免不必要的下载。注意:contains选择器里不能有多余的空格。 |
// 避免不必要的下载。注意:contains选择器里不能有多余的空格。 |
||
if ($output.find( 'style:contains(mainpage)' ).length || downloaded) { return; } |
if ($output.find( 'style:contains(mainpage)' ).length || downloaded) { return; } |
||
console.log('Hook: wikipage.content, 开始下载主页样式表'); |
|||
mw.loader.load( '//cdn.jsdelivr.net/gh/bhsd-harry/LLWiki@1.2/widget/mainpage.min.css', 'text/css' ); |
mw.loader.load( '//cdn.jsdelivr.net/gh/bhsd-harry/LLWiki@1.2/widget/mainpage.min.css', 'text/css' ); |
||
downloaded = true; |
downloaded = true; |
||
第97行: | 第105行: | ||
mw.hook( 'wikipage.categories' ).add(function($content) { |
mw.hook( 'wikipage.categories' ).add(function($content) { |
||
console.log('Hook: wikipage.categories, 开始替换小写分类'); |
console.log('Hook: wikipage.categories, 开始替换小写分类'); |
||
$content.find( |
$content.find( "a:contains(Μ's)" ).text(function(i, text) { return text.replace(/^Μ's/, "μ's"); }); |
||
$content.find( 'a:contains( |
$content.find( 'a:contains(Lily white)' ).text(function(i, text) { |
||
return text.replace(/^Lily white/, 'lily white'); |
|||
}); |
|||
}); |
}); |
||
//</nowiki> |
//</nowiki> |
2021年2月23日 (二) 10:14的版本
//<nowiki> // 由ResourceLoader直接调用,不可使用ES6语法 /** * @Description: 这里是桌面版和手机版通用的全局JS * @Functions: 1. 除[[Special:前缀索引]]外移除页面名称最后的"/" * 2. [[MediaWiki:Edittools]]可定制的快速插入工具 * 3. 嵌入外部站点时通知并建议跳转 * 4. 防止错误创建其他用户的用户页 * 5. 正确显示[[特殊:前缀索引/LLWiki:首页/当年今日/]] * 6. 分类栏正确显示小写标题 * @Author: 如无特殊说明,均为[[User:Bhsd]] */ "use strict"; /* global OO, wgULS */ const pagename = mw.config.get( 'wgPageName' ), action = mw.config.get( 'wgAction' ); /** * @Function: 除[[Special:前缀索引]]外去掉地址栏最后的"/" * @Dependencies: mediawiki.Uri * @Author: [[wikipedia:User:Majavah]] * @EditedBy: [[User:Bhsd]] */ if (pagename.endsWith( '/' ) && mw.config.get( 'wgCanonicalSpecialPageName' ) != 'Prefixindex') { const uri = new mw.Uri(); uri.query.title = pagename.slice(0, -1); uri.path = '/zh'; // 原本title可能不在query参数里,而是在path里 location.replace( uri.toString() ); } /** * @Function: 更复杂的快速插入 * @Source: [[mw:Extension:CharInsert]] * @Dependencies: jquery.textSelection(已由CharInsert扩展加载) */ if (['edit', 'submit'].includes( action ) && mw.config.get( 'wgIsProbablyEditable' )) { $('#editform').on('click', 'span.mw-charinsert-item', function() { const $this = $(this); $('#wpTextbox1').textSelection( 'encapsulateSelection', { pre: $this.data( 'mw-charinsert-start' ) || $this.data( 'start' ), // undefined也没关系 post: $this.data( 'mw-charinsert-end' ) || $this.data( 'end' ) } ); }); } /** * @Function: 嵌入外部站点时进行提示 * @Dependencies: oojs-ui-windows, ext.gadget.site-lib * @Source: [[moegirl:mediawiki:common.js]] * @EditedBy: [[User:Bhsd]] */ if (top !== window || location.host != 'llwiki.org') { // 不一定是嵌入 mw.messages.set( $.extend( wgULS({ 'gadget-ss-title': '<p>LLWiki提醒您</p><p>您正在非LLWiki域名访问</p>', 'gadget-ss-label': '<p>请注意不要在此域名下输入您的用户名或密码,以策安全!</p>' + '<p>LLWiki的域名为 <a href="#" onclick="return false;">llwiki.org</a></p>' }, { 'gadget-ss-title': '<p>LLWiki提醒您</p><p>您正在非LLWiki域名訪問</p>', 'gadget-ss-label': '<p>請注意不要在此域名下輸入您的用戶名或密碼,以策安全!</p>' + '<p>LLWiki的域名為 <a href="#" onclick="return false;">llwiki.org</a></p>' }), {'gadget-ss-jump': '前往LLWiki', 'gadget-ss-continue': '我知道了'}) ); // 不需要繁简转换的文字 const dialog = new OO.ui.MessageDialog(); mw.dialog(dialog, [ {label: mw.msg('gadget-ss-continue'), flags: ['primary', 'destructive']}, {label: mw.msg('gadget-ss-jump'), flags: ['primary', 'progressive'], target: '_blank', // 必须打开新标签页 href: top === window ? 'https://llwiki.org' : location.href} ], mw.msg('gadget-ss-label'), mw.msg('gadget-ss-title')); } /** * @Function: 点击其他用户主页面的红链不会进入创建页面 * @Dependencies: mediawiki.Title */ mw.hook( 'wikipage.content' ).add(function($content) { // 必须立即解决,否则手机版会生成drawer console.log('Hook: wikipage.content, 开始处理其他用户主页面的红链'); $content.find( '.new' ).attr('href', function(i, val) { const query = mw.util.getParamValue('title', val); if (!query) { return; } // 特殊页面 const title = new mw.Title( query ), name = title.getMainText(); // 借助mediawiki.Title规范用户名格式 // 不处理非用户空间或用户子页面 if (title.namespace != 2 || name.includes( '/' ) || name == mw.config.get('wgUserName')) { return; } return title.getUrl(); }); }); /** * @Function: 正确显示[[特殊:前缀索引/LLWiki:首页/当年今日/]] */ if (pagename.startsWith( 'LLWiki:首页/当年今日/' ) && action == 'view') { // 非管理员不需要关心未创建的页面 var downloaded = mw.config.get( 'wgArticleId' ) === 0 && !mw.config.get( 'wgUserGroups' ).includes( 'sysop' ); mw.hook( 'wikipage.content' ).add(function($content) { const $output = $content.children( '.mw-parser-output' ).addClass( 'mainpage-flex' ); // 避免不必要的下载。注意:contains选择器里不能有多余的空格。 if ($output.find( 'style:contains(mainpage)' ).length || downloaded) { return; } console.log('Hook: wikipage.content, 开始下载主页样式表'); mw.loader.load( '//cdn.jsdelivr.net/gh/bhsd-harry/LLWiki@1.2/widget/mainpage.min.css', 'text/css' ); downloaded = true; }); } /** * @Function: 分类栏显示小写标题 */ mw.hook( 'wikipage.categories' ).add(function($content) { console.log('Hook: wikipage.categories, 开始替换小写分类'); $content.find( "a:contains(Μ's)" ).text(function(i, text) { return text.replace(/^Μ's/, "μ's"); }); $content.find( 'a:contains(Lily white)' ).text(function(i, text) { return text.replace(/^Lily white/, 'lily white'); }); }); //</nowiki> // [[category:桌面版小工具]] [[category:手机版小工具]] [[category:作为模块的小工具]] [[category:系统工具]] [[category:不可关闭的小工具]] // {{DEFAULTSORT:site-shared.js}}