16,874
个编辑
LLWiki正在建设中,欢迎加入我们!
小 |
小 (// 使用Wikiplus小工具快速编辑) 标签:移动版网页编辑 移动版编辑 |
||
(未显示同一用户的4个中间版本) | |||
* @Description: 自用的工具函数
* @Author: [[User:Bhsd]]
*/
"use strict";
// jshint varstmt: true
/**
* @Function: 批量添加文件授权协议,只能处理不超过500个文件的分类
*/
mw.myCopyright = (cmtitle = mw.config.get( 'wgTitle' )) => {
▲ const api = new mw.Api();
▲ mw.timedQuery(api, { prop: 'categories', generator: 'categorymembers', gcmtitle: `Category:${cmtitle}`,
▲ gcmtype: 'file', gcmlimit: 'max', clcategories: cats.map(ele => `Category:${ele}`).join( '|' )
▲ }, '分类下无授权协议的文件').then(res => {
▲ res.query.pages.filter(ele => !ele.categories).forEach(ele => {
▲ api.postWithToken('csrf', {action: 'edit', pageid: ele.pageid, minor: 1, bot: 1,
▲ prependtext: '==授权协议==\n{{copyright}}\n', summary: '使用API批量添加授权协议',
▲ }).catch(reason => { console.error( `页面${ele.pageid}无法添加授权协议,错误原因:${reason}` ); });
}, () =>
▲ });
};
*/
mw.myJsSize = () => {
▲ mw.timedQuery(new mw.Api(), {prop: 'info', titles: titles.join( '|' )}, 'JS页面大小').then(data => {
▲ $table.toggleClass( 'jsTable jsTable2' );
▲ // 注意返回的结果可能顺序不同
▲ const lengths = Object.fromEntries( data.query.pages.map(ele => [ele.title, ele.length]) );
▲ $items.children( 'td:last-child' ).text(i => (lengths[ titles[i] ] / 1024).toFixed(1));
▲ }, () => { $('#myJsSize').off( 'click' ).one('click', mw.myJsSize); });
});▼
};
mw.hook( 'wikipage.content' ).add($content => {
const $btn
if ($btn.length === 0) { return; }
console.log('Hook: wikipage.content, 开始添加JS大小查询按钮');
/**▼
* @Function: 记录所有触发的Hook▼
*/▼
(() => {
const start = mw.now();▼
['postEdit', 'wikipage.content', 'wikipage.collapsibleContent', 'wikipage.categories', 'wikipage.diff',▼
'wikipage.editform', 'structuredChangeFilters.ui.initialized', 'codeEditor.configure', // MW原生Hook▼
'code.prettify', 'wikiplus.dialog', 'transclusion.preview' // 小工具Hook▼
].forEach(ele => {▼
▲
mw.hook( ele ).add(x => {▼
▲
console.log(`Hook: ${ele} after ${mw.now() - start} ms`);▼
▲
if (x) { console.info(x); }▼
'settings.dialog', 'to.bottom' // 小工具Hook
});▼
});
}) ();
|