LLWiki正在建设中,欢迎
加入我们
!
查看“User:Bhsd/tool.js”的源代码
←
User:Bhsd/tool.js
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您没有权限编辑此JavaScript页面,因为此页面包含另一位用户的个人设置。
您可以查看和复制此页面的源代码。
/* 生成JS文件大小 var api = new mw.Api(), table = $('table').first(), list = table.find('td:first-child a'); table.find('th').first().after( '<th>大小</th>' ); list.each(function() { var ele = $(this); var title = ele.attr('href').substring(4); api.get({ action:'query', formatversion:2, prop:'info', titles:title }).then(function(data) { var length = data.query.pages[0].length; ele.parent().after('<td>' + length + '</td>'); }); }); */ // 引自[[wikipedia:User:Kephir/gadgets/table-editor.js]] $(function() { if(!['edit', 'submit'].includes( mw.config.get('wgAction') ) || mw.config.get('wgPageContentModel') != 'wikitext') return; /* 表格列操作 */ var editBox = $('#wpTextbox1'); function getSelection(textarea) { var start = textarea.prop('selectionStart'), end = textarea.prop('selectionEnd'); return [textarea.val().substring(0, start), textarea.val().substring(start, end), textarea.val().substring(end) ]; } function readTable(table) { table = table.trim(); if( !/^[\s]*{\|[\s\S]*\n[\s]*\|}$/.test(table) ) { return false; } table = table.substring(2, table.length - 2); var tableProperty = table.match(/^([\s\S]*?)\n/)[1], tbody = table.substring( tableProperty.length ).trim(), tr = tbody.split('|-').filter(e => /[\|!]/.test(e)).map(e => e.trim()); trProperty = tr.map(e => { if( /^[\|!]/.test(e) ) { return ""; } return e.match(/^([\s\S]*?\n[\S]*?)[\|!]/)[1]; }), td = tr.map( (e, i) => [e.charAt(trProperty[i].length), ...e.substring( trProperty[i].length + 1 ).split(/(\|\||\n[\s]*\||!!|\n[\s]*!)/)] ); return {tableProperty: tableProperty, trProperty: trProperty, td: td}; } function parseTable(table) { var result = "{|" + table.tableProperty.trim() + "\n", td = table.td; table.trProperty.forEach(function(e, i) { if(i || e.trim()) { result += "|-" + e.trim() + "\n"; } for(var j = 0; j < td[i].length / 2; j++) { result += td[i][j * 2].slice(-1) + td[i][j * 2 + 1].trim() + "\n"; } }); return result + "|}"; } function parseCompactTable(table) { var result = "{|" + table.tableProperty.trim() + "\n", td = table.td; table.trProperty.forEach(function(e, i) { if(i || e.trim()) { result += "|-" + e.trim() + "\n"; } for(var j = 0; j < td[i].length / 2; j++) { result += td[i][j * 2].slice(-1) + td[i][j * 2 + 1].trim() + ' ' + (td[i][j * 2 + 2] || "\n").slice(-1); } }); return result + "|}"; } function insertCol(table) { var init = prompt( wgULS("请输入插入列的初始内容:", "請輸入插入列的初始內容:") ); table.td = table.td.map(e => [...e, '|', init]); return table; } function permuteCol(table) { var order = prompt( wgULS("请输入新的列序。原第一列记为0,依次类推。以半角符号(,)分隔,省略想要删除的列的序号", "請輸入新的列序。原第一列記為0,依此類推。以半形符號(,)分隔,省略想要刪除的列的序號") ).split(','); if( order.find(e => isNaN(e) || e < 0) ) { mw.notify("列序输入格式不正确", "列序輸入格式不正確"); return table; } table.td = table.td.map(e => { var tdArray = []; order.forEach(function(i) { tdArray.push(e[2 * i] || '|'); tdArray.push(e[2 * i + 1] || ''); }); return tdArray; }); return table; } editBox.wikiEditor('addToToolbar', { sections: { 'tables': { type: 'toolbar', label: '表格' } } }); editBox.wikiEditor('addToToolbar', { section: 'tables', groups: { 'tables': {} } }); function addButton(text, icon, handler) { editBox.wikiEditor('addToToolbar', { section: 'tables', group: 'tables', tools: { ident: { label: text, type: 'button', icon: icon, action: { type: 'callback', execute: function() { var parts = getSelection(editBox), table = readTable( parts[1] ); if(!table) { mw.notify( wgULS("表格不完整或存在错误", "表格不完整或存在錯誤") ); return; } editBox.val( parts[0] + handler(table) + parts[2] ); } } } } }); } addButton(wgULS("<tr>分行书写", "<tr>分行書寫"), "//upload.wikimedia.org/wikipedia/commons/c/c0/Knop_onzijdig.png", parseTable ); addButton(wgULS("<tr>一行书写", "<tr>一行書寫"), "//upload.wikimedia.org/wikipedia/commons/8/8e/Button_number_1.png", parseCompactTable ); addButton(wgULS("在最右侧插入一列", "在最右側插入一列"), "//upload.wikimedia.org/wikipedia/commons/6/60/Button_support.png", function(table) { return parseCompactTable( insertCol(table) ); } ); addButton(wgULS("改变列序和/或删除部分列", "改變列序和/或刪除部分列"), "//upload.wikimedia.org/wikipedia/commons/9/98/Button_oppose.png", function(table) { return parseCompactTable( permuteCol(table) ); } ); });
本页使用的模板:
Template:Copyright
(
查看源代码
)(受保护)
Template:Fc
(
查看源代码
)
Template:FileCategory
(
查看源代码
)
返回
User:Bhsd/tool.js
。
导航菜单
个人工具
创建账号
登录
命名空间
用户页
讨论
变体
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
随机页面
最近更改
沙盒
互助客栈
方针与指引
帮助
工具
链入页面
相关更改
用户贡献
日志
查看用户组
特殊页面
页面信息