Starblast Wiki
No edit summary
No edit summary
Line 1: Line 1:
if (mw.config.get('wgTitle') === 'Changelogs')
+
if (mw.config.get('wgTitle') === 'Changelogs') {
{
 
 
$.ajax("https://starblast.io/changelog.txt")
 
$.ajax("https://starblast.io/changelog.txt")
 
.done(function (data) {
 
.done(function (data) {
function space(n)
+
function t(){};
  +
t.months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
{
 
  +
function addMonth(str) {
spc="",j=0;
 
for (g=1;g<=n*2;g++) spc+="&nbsp;";
+
str = str.split("-");
  +
return t.months[Number(str[1])-1]+" "+Number(str[2])+", "+str[0];
return spc;
 
 
}
 
}
  +
function space(n) {
date=data.match(/(\d{4}[-]\d{2}[-]\d{2})/g);
 
  +
return new Array(n*2).fill("&nbsp;").join("");
$("#mw-changelog").html("<h4>Date filters</h4>");
 
 
}
$("#mw-changelog").append("<select id='mw-changelog-date_filter'><option disabled selected>All Changelogs</option><option>"+date.join("</option><option>")+"</option></select>");
 
 
t.date=data.match(/(\d{4}[-]\d{2}[-]\d{2})/g);
$("#mw-changelog-date_filter").on("change",function(e){
 
  +
$("#mw-changelog").html("<div id='mw-changelog_filter' style='z-index:1;padding:3pt;position:fixed;top:35pt;right:15pt;background:hsla(200,30%,15%,.9)'>Filter by Date: ");
 
$("#mw-changelog_filter").append("<select id='mw-changelog-date_filter' style='font-size:1em;padding:3px 5px;color:white;background:hsl(200,60%,15%);border:1px solid hsl(200,60%,10%);vertical-align:middle;box-sizing:border-box;'><option selected>Full Changelogs</option><option>"+t.date.map(function(i){return addMonth(i)}).join("</option><option>")+"</option></select>");
  +
t.date.unshift("Full_Changelogs");
  +
t.filter = $("#mw-changelog-date_filter");
 
t.filter.on("change",function(e){
 
e.preventDefault();
 
e.preventDefault();
window.location.hash=date[$("#mw-changelog-date_filter").prop('selectedIndex')-1]||"";
+
window.location.hash=t.date[t.filter.prop('selectedIndex')]||"";
 
});
 
});
$("#mw-changelog").append(data.replace(/(\d{4}[-]\d{2}[-]\d{2})/g,'<h3><span class="mw-headline" id="$1">$1</span></h3>').replace(/\n+/g,"\n").replace(/^[^<]\s*(\*|\+|-|–)*\s*.+/gm,function (v) {
+
$("#mw-changelog").append(data.replace(/(\d{4}[-]\d{2}[-]\d{2})/g,function(v){return '<h3><span class="mw-headline" id="'+v+'">'+addMonth(v)+'</span></h3>'}).replace(/\n+/g,"\n").replace(/^[^<]\s*(\*|\+|-|–)*\s*.+/gm,function (v) {
sp = 0,u = v,i = 1;
+
t.sp = 0;
  +
t.u = v;
u=u.replace(/^\s+/g,function (d) {
 
sp=d.length;
+
t.u=t.u.replace(/^\s+/g,function(d){return t.sp=d.length, ""});
 
if ("*-+–".indexOf(t.u[0])!= -1)
return "";
 
});
 
if ("*-+–".indexOf(u[0])!= -1)
 
 
{
 
{
fc=u[0];
+
t.fc=t.u[0];
u=u.slice(1,u.length).replace(/^\s*/g,"");
+
t.u=t.u.slice(1,t.u.length).replace(/^\s*/g,"");
 
}
 
}
else fc = "";
+
else t.fc = "";
u=u[0].toUpperCase()+u.slice(1,v.length);
+
t.u=t.u[0].toUpperCase()+t.u.slice(1,v.length);
switch (fc)
+
switch (t.fc)
 
{
 
{
 
case "*":
 
case "*":
return "<ul><li>"+u+"</li></ul>";
+
return "<ul><li>"+t.u+"</li></ul>";
 
case "–":
 
case "–":
 
case "-":
 
case "-":
return "<p>"+space(2)+"– "+u+"</p>";
+
return "<p>"+space(2)+"– "+t.u+"</p>";
 
case "+":
 
case "+":
return "<p>"+space(3)+"+ "+u+"</p>";
+
return "<p>"+space(3)+"+ "+t.u+"</p>";
 
default:
 
default:
return "<p>"+space(sp)+fc+u+"</p>";
+
return "<p>"+space(sp)+t.fc+t.u+"</p>";
 
}
 
}
}).replace(/<\/ul>(\n|\r)*<ul>/g,""))})
+
}).replace(/<\/ul>(\n|\r)*<ul>/g,""));
  +
})
 
.fail(function (e) {$("#mw-changelog").html("<p>An error occured while loading data from the server!</p><p>Please reload the page and try again</p>")});
 
.fail(function (e) {$("#mw-changelog").html("<p>An error occured while loading data from the server!</p><p>Please reload the page and try again</p>")});
 
}
 
}

Revision as of 23:46, 28 September 2020

if (mw.config.get('wgTitle') === 'Changelogs') {
	$.ajax("https://starblast.io/changelog.txt")
	.done(function (data) {
		function t(){};
		t.months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
		function addMonth(str) {
			str = str.split("-");
			return t.months[Number(str[1])-1]+" "+Number(str[2])+", "+str[0];
		}
		function space(n) {
			return new Array(n*2).fill("&nbsp;").join("");
		}
		t.date=data.match(/(\d{4}[-]\d{2}[-]\d{2})/g);
		$("#mw-changelog").html("<div id='mw-changelog_filter' style='z-index:1;padding:3pt;position:fixed;top:35pt;right:15pt;background:hsla(200,30%,15%,.9)'>Filter by Date: ");
		$("#mw-changelog_filter").append("<select id='mw-changelog-date_filter' style='font-size:1em;padding:3px 5px;color:white;background:hsl(200,60%,15%);border:1px solid hsl(200,60%,10%);vertical-align:middle;box-sizing:border-box;'><option selected>Full Changelogs</option><option>"+t.date.map(function(i){return addMonth(i)}).join("</option><option>")+"</option></select>");
		t.date.unshift("Full_Changelogs");
		t.filter = $("#mw-changelog-date_filter");
		t.filter.on("change",function(e){
			e.preventDefault();
			window.location.hash=t.date[t.filter.prop('selectedIndex')]||"";
		});
		$("#mw-changelog").append(data.replace(/(\d{4}[-]\d{2}[-]\d{2})/g,function(v){return '<h3><span class="mw-headline" id="'+v+'">'+addMonth(v)+'</span></h3>'}).replace(/\n+/g,"\n").replace(/^[^<]\s*(\*|\+|-|–)*\s*.+/gm,function (v) {
			t.sp = 0;
			t.u = v;
			t.u=t.u.replace(/^\s+/g,function(d){return t.sp=d.length, ""});
			if ("*-+–".indexOf(t.u[0])!= -1)
			{
				t.fc=t.u[0];
				t.u=t.u.slice(1,t.u.length).replace(/^\s*/g,"");
			}
			else t.fc = "";
			t.u=t.u[0].toUpperCase()+t.u.slice(1,v.length);
			switch (t.fc)
			{
				case "*":
					return "<ul><li>"+t.u+"</li></ul>";
				case "–":
				case "-":
					return "<p>"+space(2)+"– "+t.u+"</p>";
				case "+":
					return "<p>"+space(3)+"+ "+t.u+"</p>";
				default:
					return "<p>"+space(sp)+t.fc+t.u+"</p>";
			}
		}).replace(/<\/ul>(\n|\r)*<ul>/g,""));
	})
	.fail(function (e) {$("#mw-changelog").html("<p>An error occured while loading data from the server!</p><p>Please reload the page and try again</p>")});
}