LLWiki正在建设中,欢迎加入我们!
“User:Bhsd/tool.js”的版本间差异
跳转到导航
跳转到搜索
小 |
|||
第3行: | 第3行: | ||
"use strict"; |
"use strict"; |
||
mw.myTools = function(table) { |
mw.myTools = function(table) { |
||
table.find( 'th' ).first().after( '<th>大小</th>' ); |
table.find( 'th' ).first().after( '<th>大小(KB)</th>' ); |
||
const items = table.find( 'td:first-child' ), |
const items = table.find( 'td:first-child' ), |
||
titles = items.children( 'a' ).map(function() { return this.title; }).toArray(); |
titles = items.children( 'a' ).map(function() { return this.title; }).toArray(); |
||
第13行: | 第13行: | ||
console.log( `End API request: 已获得JS页面大小,用时 ${mw.now() - timerStart} ms` ); |
console.log( `End API request: 已获得JS页面大小,用时 ${mw.now() - timerStart} ms` ); |
||
const lengths = Object.fromEntries( data.query.pages.map(ele => [ele.title, ele.length]) ); |
const lengths = Object.fromEntries( data.query.pages.map(ele => [ele.title, ele.length]) ); |
||
items.after(i => { return $('<td>'). |
items.after(i => { return $('<td>').addClass( 'video-link' ).css('text-align', 'right') |
||
.text( (lengths[ titles[i] ] / 1024).toFixed(1) ); }); |
|||
}); |
}); |
||
}); |
}); |
2020年11月20日 (五) 07:15的版本
// 由[[Special:Mypage/common.js]]调用,可以使用ES6语法 // 生成JS文件大小 "use strict"; mw.myTools = function(table) { table.find( 'th' ).first().after( '<th>大小(KB)</th>' ); const items = table.find( 'td:first-child' ), titles = items.children( 'a' ).map(function() { return this.title; }).toArray(); mw.loader.using( 'mediawiki.api' ).then(() => { console.log( 'API request: 查询JS页面大小' ); const timerStart = mw.now(); new mw.Api().get({ action:'query', prop:'info', titles:titles.join( '|' ), formatversion:2 }) .then(data => { console.log( `End API request: 已获得JS页面大小,用时 ${mw.now() - timerStart} ms` ); const lengths = Object.fromEntries( data.query.pages.map(ele => [ele.title, ele.length]) ); items.after(i => { return $('<td>').addClass( 'video-link' ).css('text-align', 'right') .text( (lengths[ titles[i] ] / 1024).toFixed(1) ); }); }); }); };