LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-mainpage-edit.js”的版本间差异
跳转到导航
跳转到搜索
小 |
|||
第1行: | 第1行: | ||
"use strict"; |
"use strict"; |
||
/* global OO */ |
/* global OO, wgULS */ |
||
mw.loader.using( ['mediawiki.api', 'oojs-ui-windows', 'ext.gadget.site-lib'] ).then(() => { |
|||
if (mw.config.get( 'wgPageName' ).startsWith( 'LLWiki:首页/当年今日/' ) && mw.config.get( 'wgAction' ) == 'view') { |
|||
mw.messages.set( wgULS({ |
|||
'gadget-ma-summary': '使用Mainpage小工具快速编辑', 'gadget-ma-niji': '虹学', |
|||
'gadget-ma-prompt': '请输入新的行号(从1开始计数)顺序,以空格分隔。未包括的行将被删除,不存在的空行将被创建。' |
|||
⚫ | |||
'gadget-ma-summary': '使用Mainpage小工具快速編輯', 'gadget-ma-niji': '虹學', |
|||
'gadget-ma-prompt': '請輸入新的行號(從1開始計數)順序,以空格分隔。未包括的行將被刪除,不存在的空行將被創建。' |
|||
⚫ | |||
let items = []; |
let items = []; |
||
const $menu = mw.menu([ {text: "µ's", data: {color: '#e4007f', name: 'muse'}}, |
const $menu = mw.menu([ {text: "µ's", data: {color: '#e4007f', name: 'muse'}}, |
||
{text: 'Aqours', data: {color: '#32aaff'}}, {text: 'Saint Snow', data: {color: '#cb3935'}}, |
{text: 'Aqours', data: {color: '#32aaff'}}, {text: 'Saint Snow', data: {color: '#cb3935'}}, |
||
{text: ' |
{text: mw.msg( 'gadget-ma-niji' ), data: {color: '#f39800', name: 'nijigaku'}}, |
||
{text: 'Liella!', data: {color: '#a5469c', name: 'liella'}}, |
{text: 'Liella!', data: {color: '#a5469c', name: 'liella'}}, |
||
{text: 'SIF', data: {color: '#77d2af'}}, {text: 'AS', data: {color: '#ff91af'}} |
{text: 'SIF', data: {color: '#77d2af'}}, {text: 'AS', data: {color: '#ff91af'}} |
||
第11行: | 第18行: | ||
dict = {ll: 'muse', llss: 'aqours', llspst: 'liella'}, |
dict = {ll: 'muse', llss: 'aqours', llspst: 'liella'}, |
||
getName = (ele) => $(ele).data( 'name' ) || ele.textContent.toLowerCase(), |
getName = (ele) => $(ele).data( 'name' ) || ele.textContent.toLowerCase(), |
||
findSelected = (name) => [...$menu.children()].find(ele => getName( ele ) == (dict[name] || name)) |
findSelected = (name) => [...$menu.children()].find(ele => getName( ele ) == (dict[name] || name)), |
||
writeText = () => '{{#widget:首页}}\n{|\n' + items.filter(ele => ele[0]) |
|||
⚫ | |||
.map(ele => '{{首页/标签|' + ele[0] + '}}' + (ele[2] ? ele[2].getValue() : ele[1] || '') + '\n') + '|}', |
|||
.mainpage-flex td:first-child { position: relative; } |
|||
id = mw.config.get( 'wgArticleId' ), |
|||
⚫ | |||
pagename = mw.config.get( 'wgPageName' ), |
|||
.skin-minerva .mainpage-flex td:last-child { width: calc(${ $('#mw-content-text').width() - 36 }px - 3.2em); } |
|||
isMobile = mw.config.get( 'skin' ) == 'minerva', |
|||
.skin-minerva #content { position: relative; z-index: 1; }` |
|||
⚫ | |||
⚫ | |||
api = new mw.Api(), |
|||
btns = [ new OO.ui.ButtonWidget({label: '保存', flags: ['primary', 'progressive']}).on('click', () => { |
|||
btns[0].setDisabled( true ); |
|||
mw.safeEdit(api, null, {title: pagename, text: writeText(), summary: mw.msg('gadget-ma-summary')}).then(() => { |
|||
location.reload(); |
|||
}, reason => { if (reason != 'editConflict') { btns[0].setDisabled( false ); } }); |
|||
}) ]; |
|||
if (id === 0) { |
|||
$('.noarticletext').toggleClass( 'noarticletext mw-parser-output mainpage-flex' ) |
|||
.html( $('<table>', {html: '<tbody>'}) ); |
|||
} |
|||
⚫ | |||
$menu.on('click', 'a', function() { |
$menu.on('click', 'a', function() { |
||
$menu.prev( '.mainpage-tag' ).css('background-color', $(this).data( 'color' )); |
$menu.prev( '.mainpage-tag' ).css('background-color', $(this).data( 'color' )); |
||
items[ $menu.closest( 'tr' ).index() ][0] = getName( this ); |
items[ $menu.closest( 'tr' ).index() ][0] = getName( this ); |
||
}).css('z-index', 2); |
}).css('z-index', 2); |
||
⚫ | |||
⚫ | |||
$menu.appendTo( this ); |
|||
⚫ | |||
$menu.setSelected( findSelected( items[ $(this).parent().index() ][0].toLowerCase() ) ).open(); |
|||
}).on('dblclick', 'td:last-child', function() { |
|||
const $this = $(this), |
|||
item = items[ $this.parent().index() ]; |
|||
⚫ | |||
⚫ | |||
$this.html( item[2].$element ); |
|||
⚫ | |||
$this.html( input.$element ); |
|||
⚫ | |||
}); |
}); |
||
⚫ | |||
} |
|||
⚫ | |||
.map(ele => [ele[1].trim(), ele[2].trim()]) : []; |
|||
}); |
|||
$('<div>', {html: btns.map(ele => ele.$element)}).appendTo( '.mainpage-flex' ).css('text-align', 'center'); |
|||
}); |
2021年2月21日 (日) 23:01的版本
"use strict"; /* global OO, wgULS */ mw.loader.using( ['mediawiki.api', 'oojs-ui-windows', 'ext.gadget.site-lib'] ).then(() => { mw.messages.set( wgULS({ 'gadget-ma-summary': '使用Mainpage小工具快速编辑', 'gadget-ma-niji': '虹学', 'gadget-ma-prompt': '请输入新的行号(从1开始计数)顺序,以空格分隔。未包括的行将被删除,不存在的空行将被创建。' }, { 'gadget-ma-summary': '使用Mainpage小工具快速編輯', 'gadget-ma-niji': '虹學', 'gadget-ma-prompt': '請輸入新的行號(從1開始計數)順序,以空格分隔。未包括的行將被刪除,不存在的空行將被創建。' }) ); let items = []; const $menu = mw.menu([ {text: "µ's", data: {color: '#e4007f', name: 'muse'}}, {text: 'Aqours', data: {color: '#32aaff'}}, {text: 'Saint Snow', data: {color: '#cb3935'}}, {text: mw.msg( 'gadget-ma-niji' ), data: {color: '#f39800', name: 'nijigaku'}}, {text: 'Liella!', data: {color: '#a5469c', name: 'liella'}}, {text: 'SIF', data: {color: '#77d2af'}}, {text: 'AS', data: {color: '#ff91af'}} ], {}, 1), dict = {ll: 'muse', llss: 'aqours', llspst: 'liella'}, getName = (ele) => $(ele).data( 'name' ) || ele.textContent.toLowerCase(), findSelected = (name) => [...$menu.children()].find(ele => getName( ele ) == (dict[name] || name)), writeText = () => '{{#widget:首页}}\n{|\n' + items.filter(ele => ele[0]) .map(ele => '{{首页/标签|' + ele[0] + '}}' + (ele[2] ? ele[2].getValue() : ele[1] || '') + '\n') + '|}', id = mw.config.get( 'wgArticleId' ), pagename = mw.config.get( 'wgPageName' ), isMobile = mw.config.get( 'skin' ) == 'minerva', width = $('#mw-content-text').width() * (isMobile ? 1 : 0.32) - (isMobile ? 68 : 36), api = new mw.Api(), btns = [ new OO.ui.ButtonWidget({label: '保存', flags: ['primary', 'progressive']}).on('click', () => { btns[0].setDisabled( true ); mw.safeEdit(api, null, {title: pagename, text: writeText(), summary: mw.msg('gadget-ma-summary')}).then(() => { location.reload(); }, reason => { if (reason != 'editConflict') { btns[0].setDisabled( false ); } }); }) ]; if (id === 0) { $('.noarticletext').toggleClass( 'noarticletext mw-parser-output mainpage-flex' ) .html( $('<table>', {html: '<tbody>'}) ); } mw.loader.addStyleTag( '.mainpage-flex td:last-child { width: calc(' + width + 'px - 1.2em); }' ); $menu.on('click', 'a', function() { $menu.prev( '.mainpage-tag' ).css('background-color', $(this).data( 'color' )); items[ $menu.closest( 'tr' ).index() ][0] = getName( this ); }).css('z-index', 2); $('.mw-parser-output table').on('dblclick', 'td:first-child', function() { $menu.appendTo( this ); $menu.setSelected( findSelected( items[ $(this).parent().index() ][0].toLowerCase() ) ).open(); }).on('dblclick', 'td:last-child', function() { const $this = $(this), item = items[ $this.parent().index() ]; item[2] = new OO.ui.MultilineTextInputWidget({autosize: true, value: item[1]}); $this.html( item[2].$element ); }); (id ? mw.standardQuery( api ) : Promise.resolve()).then(data => { items = data ? [...data.query.pages[0].revisions[0].content.matchAll( /首[页頁]\/[标標][签籤]\|(.+?)}}(.+?)\n/g )] .map(ele => [ele[1].trim(), ele[2].trim()]) : []; }); $('<div>', {html: btns.map(ele => ele.$element)}).appendTo( '.mainpage-flex' ).css('text-align', 'center'); });