Jump to content
Toggle menu
  • 6 articles
  • 6 users
  • 196 edits
Adventure Builder 2 Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
Load live Roblox profile pictures
Load Central stats on wiki profiles
Line 4: Line 4:
return;
return;
}
}
var $img = $('.profile-avatar-image');
var $img = $('.profile-avatar-image');
if (!$img.length) {
if ($img.length) {
var fallback = $img.attr('src');
$img.on('error', function () {
$img.attr('src', fallback);
});
$img.attr(
'src',
'https://adventure-builder.net/api/roblox-proxy?service=profile-picture&userId=' +
encodeURIComponent(userId)
);
}
 
var $stats = $('.profile-header-statistics');
if (!$stats.length) {
return;
return;
}
}
var fallback = $img.attr('src');
 
$img.on('error', function () {
function compactCount(n) {
$img.attr('src', fallback);
var num = Number(n) || 0;
});
if (num >= 1e9) {
$img.attr(
return (num / 1e9).toFixed(1).replace(/\.0$/, '') + 'B';
'src',
}
'https://adventure-builder.net/api/roblox-proxy?service=profile-picture&userId=' +
if (num >= 1e6) {
encodeURIComponent(userId)
return (num / 1e6).toFixed(1).replace(/\.0$/, '') + 'M';
);
}
if (num >= 1e3) {
return (num / 1e3).toFixed(1).replace(/\.0$/, '') + 'K';
}
return String(Math.floor(num));
}
 
fetch(
'https://adventure-builder.net/api/v1/profiles/' + encodeURIComponent(userId)
)
.then(function (res) {
return res.ok ? res.json() : null;
})
.then(function (profile) {
if (!profile) {
return;
}
[
[profile.levels_count, 'Levels'],
[profile.clears, 'Clears'],
[profile.followers, 'Followers']
].forEach(function (pair) {
$('<li>')
.addClass('ab-central-stat')
.text(compactCount(pair[0]) + ' ' + pair[1])
.appendTo($stats);
});
})
.catch(function () {});
});
});

Revision as of 18:43, 27 August 2026

$(function () {
	var userId = mw.config.get('abRobloxUserId');
	if (!userId) {
		return;
	}

	var $img = $('.profile-avatar-image');
	if ($img.length) {
		var fallback = $img.attr('src');
		$img.on('error', function () {
			$img.attr('src', fallback);
		});
		$img.attr(
			'src',
			'https://adventure-builder.net/api/roblox-proxy?service=profile-picture&userId=' +
				encodeURIComponent(userId)
		);
	}

	var $stats = $('.profile-header-statistics');
	if (!$stats.length) {
		return;
	}

	function compactCount(n) {
		var num = Number(n) || 0;
		if (num >= 1e9) {
			return (num / 1e9).toFixed(1).replace(/\.0$/, '') + 'B';
		}
		if (num >= 1e6) {
			return (num / 1e6).toFixed(1).replace(/\.0$/, '') + 'M';
		}
		if (num >= 1e3) {
			return (num / 1e3).toFixed(1).replace(/\.0$/, '') + 'K';
		}
		return String(Math.floor(num));
	}

	fetch(
		'https://adventure-builder.net/api/v1/profiles/' + encodeURIComponent(userId)
	)
		.then(function (res) {
			return res.ok ? res.json() : null;
		})
		.then(function (profile) {
			if (!profile) {
				return;
			}
			[
				[profile.levels_count, 'Levels'],
				[profile.clears, 'Clears'],
				[profile.followers, 'Followers']
			].forEach(function (pair) {
				$('<li>')
					.addClass('ab-central-stat')
					.text(compactCount(pair[0]) + ' ' + pair[1])
					.appendTo($stats);
			});
		})
		.catch(function () {});
});