Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
(function() {
if (mw.config.get('wgNamespaceNumber') !== 500) {
return;
}
var i18n;
function addAnnouncement() {
var ajaxProps = {
action: 'parse',
page: wgPageName,
format: 'json',
section: 0,
disablepp: 1
};
$.get(mw.util.wikiScript('api'), ajaxProps, function(res) {
var text = $(res.parse.text['*']).text().trim();
if(!text.length) {
ajaxProps.section = 1;
$.get(mw.util.wikiScript('api'), ajaxProps, function(res) {
var html = $.parseHTML(res.parse.text['*']);
// remove headline
html.shift();
var text = $('<div />').append(html).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;
$('<button />', {
type: 'checkbox',
id: 'addAnnouncement',
text: i18n.msg('add').plain()
}).click(addAnnouncement).appendTo(mw.util.$content);
});
});
importArticle({ type:'script', article: 'u:dev:I18n-js/code.js' });
})();