Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ There are <span data-playercounter-ip="mc.hypixel.net">0</span> players on Hypix
```

## Options
- refreshRate - The rate that the counter will refresh (1m by default. Note that https://mcapi.us/ has a 5 minute cache.)
- refreshRate - The rate that the counter will refresh (1m by default. Note that https://mcstatus.snowdev.com.br/ has a 30 seconds cache.)
- format - Format that the counter will be displayed
- `{max}` - Maximum players
- `{online}` - Online players
Expand Down Expand Up @@ -53,5 +53,5 @@ new PlayerCounter({

## License

Copyright (C) 2017-2020 leonardosnt <leonrdsnt@gmail.com>
Copyright (C) 2017-2021 leonardosnt <leonrdsnt@gmail.com>
Licensed under the MIT License. See LICENSE file in the project root for full license information.
17 changes: 7 additions & 10 deletions dist/mc-player-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ var PlayerCounter = function () {
if (!element) {
throw TypeError('element cannot be null or undefined');
}

var ipAddress = ip.split(':');
this.ip = ipAddress[0];
this.port = ipAddress[1] || '25565';


this.ip = ip;

this.format = format;
this.element = typeof element === 'string' ? document.querySelector(element) : element;

Expand All @@ -51,6 +49,7 @@ var PlayerCounter = function () {
// I'll use XMLHttpRequest because it has a better browser support
// than fetch & Promise.
var request = new XMLHttpRequest();

request.onreadystatechange = function () {
if (request.readyState !== 4 || request.status !== 200) return;

Expand All @@ -69,14 +68,12 @@ var PlayerCounter = function () {
// Make sure server is online
if (response.online) {
_this.element.innerHTML = _this.format.replace(FORMAT_REGEX, function (_, group) {
return (
// Change 'online' to 'now' to keep backward compatibility
response.players[group === 'online' ? 'now' : group]
);
return (group === 'online' ? response.players_online : response.max_players);
});
}
};
request.open('GET', 'https://mcapi.us/server/status?ip=' + this.ip + '&port=' + this.port);

request.open('GET', 'https://mcstatus.snowdev.com.br/api/query/v3/' + this.ip);
request.send();
}
}]);
Expand Down
2 changes: 1 addition & 1 deletion dist/mc-player-counter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.