Template:Playercount: Difference between revisions
test for player count without modules |
move to JSONP, api not compliant with CORS |
||
Line 1: | Line 1: | ||
<div id=" | <div id="pc-{{{1|1}}}" style="display:inline-block;background:linear-gradient(135deg,#667eea,#764ba2);color:white;padding:12px 20px;border-radius:8px;font-family:sans-serif;box-shadow:0 4px 6px rgba(0,0,0,0.1);margin:10px 0"> <div style="font-size:14px;font-weight:600;margin-bottom:4px">Players Online</div> <div style="font-size:24px;font-weight:700" id="count-{{{1|1}}}">...</div> <div style="font-size:12px;margin-top:4px;opacity:0.8" id="status-{{{1|1}}}">Loading...</div> </div> <script> window['jsonp_{{{1|1}}}'] = function(data) { var count = typeof data === 'number' ? data : (data.players || data.online || data.count || 0); document.getElementById('count-{{{1|1}}}').textContent = count; document.getElementById('status-{{{1|1}}}').textContent = count > 0 ? 'Online' : 'Empty'; document.getElementById('pc-{{{1|1}}}').style.background = count > 0 ? 'linear-gradient(135deg,#10b981,#059669)' : 'linear-gradient(135deg,#667eea,#764ba2)'; }; var script = document.createElement('script'); script.src = 'https://betamc.org:8080/api/players?callback=jsonp_{{{1|1}}}'; script.onerror = function() { document.getElementById('count-{{{1|1}}}').textContent = '✗'; document.getElementById('status-{{{1|1}}}').textContent = 'Offline'; document.getElementById('pc-{{{1|1}}}').style.background = 'linear-gradient(135deg,#ef4444,#dc2626)'; }; document.head.appendChild(script); </script> | ||
</div><script> |
Revision as of 06:04, 17 June 2025
<script> window['jsonp_1'] = function(data) { var count = typeof data === 'number' ? data : (data.players || data.online || data.count || 0); document.getElementById('count-1').textContent = count; document.getElementById('status-1').textContent = count > 0 ? 'Online' : 'Empty'; document.getElementById('pc-1').style.background = count > 0 ? 'linear-gradient(135deg,#10b981,#059669)' : 'linear-gradient(135deg,#667eea,#764ba2)'; }; var script = document.createElement('script'); script.src = 'https://betamc.org:8080/api/players?callback=jsonp_1'; script.onerror = function() { document.getElementById('count-1').textContent = '✗'; document.getElementById('status-1').textContent = 'Offline'; document.getElementById('pc-1').style.background = 'linear-gradient(135deg,#ef4444,#dc2626)'; }; document.head.appendChild(script); </script>