No edit summary |
Krantuckety (talk | contribs) mNo edit summary |
||
Line 84: | Line 84: | ||
}); |
}); |
||
} |
} |
||
+ | |||
+ | const images = document.querySelectorAll("#content img"); |
||
+ | const regex = new RegExp(/cb=\d+/); |
||
+ | |||
+ | images.forEach(function(image) { |
||
+ | image.setAttribute("src", image.src.replace(regex, "format=original")); |
||
+ | }); |
||
$(addAjaxDisplayLink); |
$(addAjaxDisplayLink); |
Revision as of 20:27, 25 April 2021
/* Any JavaScript here will be loaded for all users on every page load. */
// Disable creation of non-talk pages by anonymous IP editors and link to registration (also disabled by abuse filter but this provides warning before attempting edit)
var wgPageName = mw.config.get( 'wgPageName' );
var wgUserName = mw.config.get( 'wgUserName' );
var isTalk = false, isAnon = false;
if (wgPageName.indexOf('talk:') > -1 || wgPageName.indexOf('Talk:') > -1) isTalk = true;
if (wgUserName === null) isAnon = true;
if (isAnon == true){
$('a.new').each(function(){
var href = $(this).attr('href');
$(this).attr('href', href.replace(/&action=edit/g, '') );
});
}
if (isAnon == true && isTalk == false) {
var anonWarnText = 'Page creation by anonymous editors is currently disabled. <br> To create this page, please <a href="https://spiritmod.gamepedia.com/Special:CreateAccount">register an account</a> first.';
$('body').append('<div class="anonWarnOverlay" style="display:none; background-color: #000; opacity: 0.4; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; z-index: 500;"></div>');
$('body').prepend('<div class="anonWarnBox" style="display:none; text-align:center; font-weight: bold; box-shadow: 7px 7px 5px #000; font-size: 0.9em; line-height: 1.5em; z-index: 501; opacity: 1; position: fixed; width: 50%; left: 25%; top: 30%; background: #F7F7F7; border: #222 ridge 1px; padding: 20px;">' + anonWarnText + '</div>');
var newSelect = 'a.new, #ca-edit a:contains(Create), #ca-ve-edit a:contains(Create), a.external.text:contains(edit this page)';
$(newSelect).each(function(){
if ($(this).attr('title').search(/talk\:/gi) < 0) {
$(this).attr('href', '#').click(function(){
$('.anonWarnBox').show();
$('.anonWarnOverlay').show();
});
}
});
$('.anonWarnOverlay').click(function(){
$('.anonWarnBox').hide();
$(this).hide();
});
}
// AJAX tables (for Template:Ajax)
function addAjaxDisplayLink() {
$("table.ajax").each(function (i) {
var table = $(this).attr("id", "ajaxTable" + i);
table.find(".nojs-message").remove();
var headerLinks = $('<span style="float: right;">').appendTo(table.find('th').first());
var cell = table.find("td").first(), needLink = true;
cell.parent().show();
if (cell.hasClass("showLinkHere")) {
var old = cell.html(), rep = old.replace(/\[link\](.*?)\[\/link\]/, '<a href="javascript:;" class="ajax-load-link">$1</a>');
if (rep != old) {
cell.html(rep);
needLink = false;
}
}
if (needLink) headerLinks.html('[<a href="javascript:;" class="ajax-load-link">show data</a>]');
table.find(".ajax-load-link").parent().andSelf().filter('a').click(function(event) {
event.preventDefault();
var sourceTitle = table.data('ajax-source-page'), baseLink = mw.config.get('wgScript') + '?';
cell.text('Please wait, the content is being loaded...');
$.get(baseLink + $.param({ action: 'render', title: sourceTitle }), function (data) {
if (data) {
cell.html(data);
cell.find('.ajaxHide').remove();
cell.find('.terraria').removeClass('terraria');
if (cell.find("table.sortable").length) {
mw.loader.using('jquery.tablesorter', function() {
cell.find("table.sortable").tablesorter();
});
}
headerLinks.text('[');
headerLinks.append($('<a>edit</a>').attr('href', baseLink + $.param({ action: 'edit', title: sourceTitle })));
headerLinks.append(document.createTextNode(']\u00A0['));
var shown = true;
$("<a href='javascript:;'>hide</a>").click(function() {
shown = !shown;
shown ? cell.show() : cell.hide();
$(this).text(shown ? "hide" : "show");
}).appendTo(headerLinks);
headerLinks.append(document.createTextNode(']'));
}
}).error(function() {
cell.text('Unable to load table; the source article for it might not exist.');
});
});
});
}
const images = document.querySelectorAll("#content img");
const regex = new RegExp(/cb=\d+/);
images.forEach(function(image) {
image.setAttribute("src", image.src.replace(regex, "format=original"));
});
$(addAjaxDisplayLink);