User:Yining Chen/rdfrom.js

维基百科,自由的百科全书

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

(function($, mw) {
    $(function() {
        // Create portlet link
        var portletLinkOnline = mw.util.addPortletLink(
                'p-cactions',
                '#',
                '将页面重定向至本页');

        var api = new mw.Api();

        // Bind click handler
        $(portletLinkOnline).find('a').click(function(e) {
            e.preventDefault();
            var infoA = prompt("Target Page:","");
            if (infoA == "")
            {
                throw("NULL")
            }
            var params = {
                action: 'edit',
                title: infoA,
                text: '#REDIRECT [[' + mw.config.get('wgPageName') + ']]',
                format: 'json'
            };
            api.postWithToken( 'csrf', params ).done( function ( data ) {
                console.log( data );
            });
            window.location.replace("https://zh.wikipedia.org/wiki/" + infoA);
        });
    });
})(jQuery, mw);