User:魔琴/gadgets/PQR/pqr.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
mw.loader.using( ['mediawiki.util'], function () {

mw.loader.load('/w/index.php?title=User:魔琴/gadgets/PQR/pqr.css&action=raw&ctype=text/css', 'text/css');

if ($('.ext-discussiontools-init-replylink-buttons').length === 0) {
    return;
}

main();

function main() {
    $('.ext-discussiontools-init-replylink-buttons').each(function () {
        id = $(this).attr("data-mw-thread-id");
        user = id.slice(2).replace(/^(.*)\d{4}-?\d{2}-?\d{2}T?\d{2}:?\d{2}:?\d{2}(\.\d{3}Z)?-.*$/g, '$1').slice(0,-1);

        $(this).find(".ext-discussiontools-init-replylink-reply").addClass("PQR").css('margin-right', 0).text('R');
        $(this).find(".ext-discussiontools-init-replylink-bracket").first().after($('<a>').addClass("PQR").addClass("PQR-quote").attr("quote-id", id).text('Q'));
        $(this).find(".ext-discussiontools-init-replylink-bracket").first().after($('<a>').addClass("PQR").addClass("PQR-ping").attr("user", user).text('P'));
    });
	
	
	$('.PQR-ping').click(function (e) {
	    e.preventDefault();
	    user = $(this).attr('user');
	    if (user.search('=')>-1) {
	    	ping = '{{ping|1=' + user + '}}';
	    	parg = '|50=' + user;
	    } else {
	    	ping = '{{ping|' + user + '}}';
	    	parg = '|' + user;
	    }
	    mw.loader.using('oojs-ui').then(function () {
	        var $ping = $('<div>');
	        $ping.append(new mw.widgets.CopyTextLayout({ title: 'ping', copyText: ping }).$element);
	        $ping.append(new mw.widgets.CopyTextLayout({ title: 'parg', copyText: parg }).$element);
	        OO.ui.alert($ping);
	    });
	});
	
	$('.PQR-quote').click(function (e) {
	    e.preventDefault();
	    anchor = "#" + $(this).attr('quote-id') + "]]";
	    full = "[[" + mw.config.get('wgPageName') + anchor;
	    anchor = "[[" + anchor;
	
	    mw.loader.using('oojs-ui').then(function () {
	        var $quote = $('<div>');
	        $quote.append(new mw.widgets.CopyTextLayout({ title: 'anchor', copyText: anchor }).$element);
	        $quote.append(new mw.widgets.CopyTextLayout({ title: 'full', copyText: full }).$element);
	        OO.ui.alert($quote);
	    });
	});

}

let iid;
setInterval(() => {
    if ($('.ext-discussiontools-init-replylink-buttons .PQR').length === 0) {
        main();
    }
}, 2000);

});