MediaWiki:AddAnnouncement/code.js

(function {   var i18n;    function addAnnouncement {        var ajaxProps = {            action: 'parse',            page: wgPageName,            format: 'json',            section: 0,            disablepp: 1        };        $.get('/api.php', ajaxProps, function(res) { var text = $(res.parse.text['*']).text.trim; if(!text.length) { ajaxProps.section = 1; $.get('/api.php', ajaxProps, function(res) {               var text = $(res.parse.text['*']).text.trim;                    if(text.length > 100) {                        text = text.slice(0, 99) + '\u2026';                    }                    saveAnnouncement(text);			                }); return; }           else if(text.length > 100) { text = text.slice(0, 99) + '\u2026'; }           saveAnnouncement(text); });   }    function saveAnnouncement(text) {        $.ajax({ url: 'https://services.wikia.com/announcements/' + mw.config.get('wgCityId') + '/announcements', type: 'POST', contentType: 'application/json', processData: false, xhrFields: { withCredentials: true },           data: JSON.stringify({                text: text,                url: window.location.href            }), success: function(res) { console.log(res); },           error: function(e) { console.error(JSON.parse(e.responseText).title); },           dataType: 'json' });   }    mw.hook('dev.i18n').add(function(i18no) { i18no.loadMessages('AddAnnouncement').done(function(d) {           i18n = d;            if(wgNamespaceNumber === 500) {                $(' ', { type: 'checkbox', id: 'addAnnouncement', text: i18n.msg('add').plain }).click(addAnnouncement).appendTo(mw.util.$content);            }        }); }); });