LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-custommenu.js”的版本间差异
跳转到导航
跳转到搜索
(安全性修改) |
|||
第15行: | 第15行: | ||
cache: setting.cache !== false |
cache: setting.cache !== false |
||
}).then(function(data) { |
}).then(function(data) { |
||
const api = new mw.Api(), |
|||
dynamicList = data.dynamic.map(function(query) { |
|||
if (query.type == 'prefixindex') { |
|||
return mw.timedQuery(api, {list: 'allpages', apprefix: query.prefix, apnamespace: query.ns}) |
|||
.then(function(res) { |
|||
return res.query.allpages.map(function(page) { |
|||
return {text: page.title, title: page.title}; |
|||
}); |
|||
}); |
|||
} |
|||
}); |
|||
if (skin == 'vector') { |
if (skin == 'vector') { |
||
menu.children().append( data.map(function(entry) { |
menu.children().append( data.static.map(function(entry) { |
||
return $('<li>', {html: $('<a>', { |
return $('<li>', {html: $('<a>', { |
||
text: entry.text, |
text: entry.text, |
||
第22行: | 第33行: | ||
})}); |
})}); |
||
}) ); |
}) ); |
||
Promise.allSettled( dynamicList ).then(function(lists) { |
|||
⚫ | |||
menu.append( lists.filter(function(ele) { return ele.status == 'fulfilled'; }).map(function(ele) { |
|||
⚫ | |||
return $('<ul>', {html: ele.value.map(function(entry) { |
|||
return $('<li>', {html: $('<a>', {text: entry.text, href: mw.util.getUrl( entry.title )})}); |
|||
})}); |
|||
}) ); |
|||
⚫ | |||
⚫ | |||
}); |
|||
} |
} |
||
else { |
else { |
||
menu.children().append( data.map(function(entry) { |
menu.children().append( data.static.map(function(entry) { |
||
return $('<li>', {html: $('<a>', { |
return $('<li>', {html: $('<a>', { |
||
href: entry.title ? mw.util.getUrl( entry.title ) : entry.href, |
href: entry.title ? mw.util.getUrl( entry.title ) : entry.href, |
||
第32行: | 第50行: | ||
})}); |
})}); |
||
}) ); |
}) ); |
||
Promise.allSettled( dynamicList ).then(function(lists) { |
|||
menu.append( lists.filter(function(ele) { return ele.status == 'fulfilled'; }).map(function(ele) { |
|||
⚫ | |||
return $('<ul>', {html: ele.value.map(function(entry) { |
|||
⚫ | |||
return $('<li>', {html: $('<a>', { |
|||
href: mw.util.getUrl( entry.title ), |
|||
html: [$('<i>', {class: 'fa fa-arrow-circle-right'}), $('<span>', {text: entry.text})] |
|||
})}); |
|||
})}); |
|||
}) ); |
|||
mw.hook( 'mobile.menu' ).add(function($content) { |
|||
⚫ | |||
⚫ | |||
}); |
|||
}); |
}); |
||
} |
} |
2021年11月10日 (三) 06:11的版本
// 由ResourceLoader直接调用,不可使用ES6语法 "use strict"; /*global mw, $, wgULS*/ const gadgets = mw.gadgets || {}, setting = gadgets.custommenu || {}, skin = mw.config.get('skin'); $(function () { if (skin == 'vector' && setting.mode == 'mobile' || skin == 'minerva' && setting.mode == 'desktop') { return; } const username = mw.config.get( 'wgUserName' ), src = setting.src || 'user:' + username + '/Sidebar.json', menu = $('<div>', {class: 'body', html: $('<ul>')}); $.get({ dataType: 'json', url: mw.util.getUrl(src, {action: 'raw', ctype: 'application/json'}), cache: setting.cache !== false }).then(function(data) { const api = new mw.Api(), dynamicList = data.dynamic.map(function(query) { if (query.type == 'prefixindex') { return mw.timedQuery(api, {list: 'allpages', apprefix: query.prefix, apnamespace: query.ns}) .then(function(res) { return res.query.allpages.map(function(page) { return {text: page.title, title: page.title}; }); }); } }); if (skin == 'vector') { menu.children().append( data.static.map(function(entry) { return $('<li>', {html: $('<a>', { text: entry.text, href: entry.title ? mw.util.getUrl( entry.title ) : entry.href })}); }) ); Promise.allSettled( dynamicList ).then(function(lists) { menu.append( lists.filter(function(ele) { return ele.status == 'fulfilled'; }).map(function(ele) { return $('<ul>', {html: ele.value.map(function(entry) { return $('<li>', {html: $('<a>', {text: entry.text, href: mw.util.getUrl( entry.title )})}); })}); }) ); $('<div>', {class: "portal", role: "navigation"}).append( $('<h3>', {text: wgULS('自定义', '定製')}) ) .append(menu).appendTo( "#mw-panel" ); }); } else { menu.children().append( data.static.map(function(entry) { return $('<li>', {html: $('<a>', { href: entry.title ? mw.util.getUrl( entry.title ) : entry.href, html: [$('<i>', {class: entry.icon || 'fa fa-arrow-circle-right'}), $('<span>', {text: entry.text})] })}); }) ); Promise.allSettled( dynamicList ).then(function(lists) { menu.append( lists.filter(function(ele) { return ele.status == 'fulfilled'; }).map(function(ele) { return $('<ul>', {html: ele.value.map(function(entry) { return $('<li>', {html: $('<a>', { href: mw.util.getUrl( entry.title ), html: [$('<i>', {class: 'fa fa-arrow-circle-right'}), $('<span>', {text: entry.text})] })}); })}); }) ); mw.hook( 'mobile.menu' ).add(function($content) { console.log('Hook: mobile.menu,开始添加自定义菜单'); $content.find( ".hlist" ).before( menu.children() ); }); }); } }); }); // [[category:编辑工具]] [[category:需要用户权限的小工具]] [[category:桌面版小工具]] [[category:手机版小工具]] [[category:作为模块的小工具]] // {{DEFAULTSORT:custommenu.js}}