User:魔琴/gadgets/TCP/tcp.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
//<nowiki>
mw.loader.using( 'mediawiki.util' , function () {
$('.mw-heading2 h2 a').each(function(){
page = $(this).attr('href').replace(/^(https:\/\/zh\.(m\.)?wikipedia.org)?\/w(\/index\.php\?title=|iki\/)(.*?)(&.*)?$/g,'$4');
try {
page = decodeURI(page);
} catch (e) { // catches a malformed URI
console.error(e);
}
if (page.slice(0,5) !== 'User:') return;
user = page.slice(5);
html = `<sup style="user-select:none"> [ <a href="/wiki/User_talk:${user}">T</a> <a href="/wiki/Special:Contribs/${user}">C</a> <a class="TCP-ping" user="${user}" href="javascript:void(0)">P</a> ] </sup>`
$(this).after(html);
});
$('.TCP-ping').click(function(e) {
e.preventDefault();
user = $(this).attr('user');
ping = '{{ping|' + user + '}}';
mw.loader.using('oojs-ui').then(function () {
OO.ui.alert(
new mw.widgets.CopyTextLayout({ title: 'ping', copyText: ping }).$element
);
});
});
});
//</nowiki>