打开主菜单
首页
随机
最近更改
特殊页面
沙盒
互助客栈
方针与指引
帮助
页面信息
链入页面
相关更改
设置
关于LLWiki
免责声明
LLWiki
搜索
用户菜单
3.145.67.216
讨论
监视列表
贡献
登录
LLWiki正在建设中,欢迎
加入我们
!
查看“User:Bhsd/tool.js”的源代码
←
User:Bhsd/tool.js
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您没有权限编辑此JavaScript页面,因为此页面包含另一位用户的个人设置。
您可以查看和复制此页面的源代码。
// 由[[Special:Mypage/common.js]]调用,可以使用ES6语法 // 生成JS文件大小 "use strict"; /*global mw, $*/ $('.fa-play').click(function() { const audio = $(this).toggleClass('fa-play fa-pause').prev().children( 'audio' )[0]; audio[audio.paused ? 'play' : 'pause'](); }); let audio; const menu = mw.menu([ {text: '音量上调', icon: 'volume-up', data: 0, click: () => { audio.volume += 0.1; if (audio.volume == 0.1) { menu.findItemFromData( 1 ).setDisabled( false ); menu.findItemFromData( 1 ).$label.find( 'i' ).toggleClass( 'fa-volume-down fa-volume-mute' ); } if (audio.volume == 1) { menu.findItemFromData( 0 ).setDisabled( true ); } }}, {text: '音量下调', icon: 'volume-down', data: 1, click: () => { audio.volume -= 0.1; menu.findItemFromData( 0 ).setDisabled( false ); if (audio.volume === 0) { menu.findItemFromData( 1 ).setDisabled( true ); menu.findItemFromData( 1 ).$label.find( 'i' ).toggleClass( 'fa-volume-down fa-volume-mute' ); } }}, {text: '下载', icon: 'download', data: 2} ], {id: 'listen-menu'}), $download = $('<a>'); menu.$element.appendTo( document.body ); menu.findItemFromData( 2 ).$label.wrap( $download ); menu.on('toggle', visible => { if (visible) { menu.unselectItem(); } }); $('.fa-ellipsis-v').click(function() { const $this = $(this), $audio = $this.parent().find( 'audio' ), src = $audio.children( 'source' ).attr( 'src' ), parts = src.split( '/' ); audio = $audio[0]; menu.setFloatableContainer( $this ); $download.attr({href: src, download: parts[ parts.length - 1 ]}); if (audio.volume == 1) { menu.findItemFromData( 0 ).setDisabled( true ); } }); mw.myCopyright = function(cmtitle = mw.config.get('wgTitle')) { mw.loader.using( 'mediawiki.api' ).then(() => { const api = new mw.Api(); console.log('API request: 查询分类下无授权协议的文件'); const timerStart = mw.now(); api.get({action: 'query', prop: 'categories', clcategories: 'Category:原作者保留权利的文件', formatversion: 2, generator: 'categorymembers', gcmtitle: `Category:${cmtitle}`, gcmtype: 'file', gcmlimit: 'max' }).then(res => { console.log(`End API request: 已获得分类下无授权协议的文件,用时 ${mw.now() - timerStart} ms`); 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}`); }); }); }, reason => { mw.notify(`无法获得对应文件。错误原因:${reason}`, {type: 'error'}); }); }); }; mw.myJsSize = function(table) { const items = table.find( 'td:first-child' ), titles = items.children( 'a' ).toArray().map(ele => ele.title); 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`); table.find( 'th:last-child' ).show(); const lengths = Object.fromEntries( data.query.pages.map(ele => [ele.title, ele.length]) ); items.parent().append(i => $('<td>', {class: 'video-link', text: (lengths[ titles[i] ] / 1024).toFixed(1)}).css('text-align', 'right')); }, reason => { mw.notify(`无法获得JS页面大小。错误原因:${reason}`, {type: 'error'}); $('#myJsSize').off( 'click' ).one('click', function() { mw.myJsSize( $(this).parent().next() ); }); }); }); }; (function() { $('#myJsSize').one('click', function() { mw.myJsSize( $(this).parent().next() ); }); 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); } }); }); }) ();
本页使用的模板:
Template:Copyright
(
查看源代码
)(受保护)
Template:Fc
(
查看源代码
)
Template:FileCategory
(
查看源代码
)
返回
User:Bhsd/tool.js
。