Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%
- function msToTime(duration) {
- const portions = [];
- const msInHour = 1000 * 60 * 60;
- const hours = Math.trunc(duration / msInHour);
- if (hours > 0) {
- portions.push(hours + 'h');
- duration = duration - (hours * msInHour);
- }
- const msInMinute = 1000 * 60;
- const minutes = Math.trunc(duration / msInMinute);
- if (minutes > 0) {
- portions.push(minutes + 'm');
- duration = duration - (minutes * msInMinute);
- }
- const seconds = Math.trunc(duration / 1000);
- if (seconds > 0) {
- portions.push(seconds + 's');
- }
- return portions.join(' ');
- }
- function numberWithCommas(x) {
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- }
- function niceifyType(d) {
- var table = {
- 'coins': 'Coins',
- 'kills': 'Kills',
- 'time': 'Survived',
- }
- var arr = [table[d]]
- arr = arr.concat(Object.values(table).filter(x => x != table[d]));
- return arr;
- }
- function niceifyDur(d) {
- var table = {
- 'all': 'All-Time',
- 'day': 'Past Day',
- 'week': 'Past Week',
- }
- var arr = [table[d]]
- arr = arr.concat(Object.values(table).filter(x => x != table[d]));
- return arr;
- }
- function tableDur(d) {
- var table = ["all", "day", "week"];
- //remove d from table
- table.splice(table.indexOf(d), 1);
- return table;
- }
- function tableType(d) {
- var table = ["coins", "kills", "time"];
- //remove d from table
- table.splice(table.indexOf(d), 1);
- return table;
- }
- function forHumans ( seconds ) {
- var levels = [
- [Math.floor(seconds / 31536000), 'years'],
- [Math.floor((seconds % 31536000) / 86400), 'days'],
- [Math.floor(((seconds % 31536000) % 86400) / 3600), 'hours'],
- [Math.floor((((seconds % 31536000) % 86400) % 3600) / 60), 'minutes'],
- [(((seconds % 31536000) % 86400) % 3600) % 60, 'seconds'],
- ];
- var returntext = '';
- for (var i = 0, max = levels.length; i < max; i++) {
- if ( levels[i][0] === 0 ) continue;
- returntext += ' ' + levels[i][0] + ' ' + (levels[i][0] === 1 ? levels[i][1].substr(0, levels[i][1].length-1): levels[i][1]);
- break;
- };
- return returntext.trim();
- }
- function go() {
- var date = new Date(user.created_at);
- //time since Date
- var timeSince =(new Date(new Date().toUTCString().slice(0, -3)))- date;
- //time since in seconds
- timeSince = timeSince / 1000;
- //convert to readable format
- return forHumans(timeSince);
- }
- function br() {
- var recent = games.sort(function(a, b) {
- return new Date(b.game_date) - new Date(a.game_date);
- })[0];
- if(recent) {
- var date = new Date(recent.game_date);
- var today = new Date();
- var diff = today - date;
- var days = Math.floor(diff / 86400000);
- if(days == 0) {
- return "today";
- } else if( days-1 == 0) {
- return "yesterday";
- } else {
- return days + " days ago";
- }
- } else return false
- }
- %>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title><%= user.username %></title>
- <meta
- content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
- name="viewport"
- />
- <link
- rel="stylesheet"
- href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
- />
- <link rel="stylesheet" type="text/css" href="css/style.css" />
- <link
- href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
- rel="stylesheet"
- integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
- crossorigin="anonymous"
- />
- <script
- src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
- integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
- crossorigin="anonymous"
- ></script>
- <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
- <script>
- function updateQueryStringParameter(uri, key, value) {
- var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
- var separator = uri.indexOf("?") !== -1 ? "&" : "?";
- if (uri.match(re)) {
- return uri.replace(re, "$1" + key + "=" + value + "$2");
- } else {
- return uri + separator + key + "=" + value;
- }
- }
- </script>
- <style>
- @import url("https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap");
- body {
- background: #f9f9f9;
- font-family: "Roboto", sans-serif;
- }
- .main-content {
- padding-top: 100px;
- padding-bottom: 100px;
- }
- .leaderboard-card {
- background: #fff;
- margin-bottom: 30px;
- border-radius: 5px;
- overflow: hidden;
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
- }
- .leaderboard-card.leaderboard-card--first {
- transform: scale(1.05);
- }
- .leaderboard-card.leaderboard-card--first .leaderboard-card__top {
- background: linear-gradient(45deg, #7e57c2, #ab47bc);
- color: #fff;
- }
- .leaderboard-card__top {
- background: #f9f6ff;
- padding: 20px 0 10px 0;
- }
- .leaderboard-card__body {
- padding: 15px;
- margin-top: -40px;
- z-index: inherit;
- }
- img.circle-img {
- height: 70px;
- width: 70px;
- border-radius: 70px;
- border: 3px solid #fff;
- box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
- }
- img.circle-img.circle-img--small {
- height: 55px;
- width: 55px;
- border-radius: 55px;
- }
- .table {
- border-spacing: 0 15px;
- border-collapse: separate;
- }
- .table thead tr th,
- .table thead tr td,
- .table tbody tr th,
- .table tbody tr td {
- vertical-align: middle;
- border: none;
- }
- .table thead tr th:nth-last-child(1),
- .table thead tr td:nth-last-child(1),
- .table tbody tr th:nth-last-child(1),
- .table tbody tr td:nth-last-child(1) {
- text-align: center;
- }
- .table tbody tr {
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
- border-radius: 5px;
- }
- .table tbody tr td {
- background: #fff;
- }
- .table tbody tr td:nth-child(1) {
- border-radius: 5px 0 0 5px;
- }
- .table tbody tr td:nth-last-child(1) {
- border-radius: 0 5px 5px 0;
- }
- .tooltipy {
- position: relative;
- display: inline-block;
- border-bottom: 1px dotted black;
- }
- .tooltipy .tooltiptexty {
- visibility: hidden;
- width: 120px;
- background-color: black;
- color: #fff;
- text-align: center;
- border-radius: 6px;
- padding: 5px 0;
- /* Position the tooltip */
- position: absolute;
- z-index: 9999;
- top: -30px;
- left: 20%;
- }
- .tooltipy:hover .tooltiptexty {
- visibility: visible;
- }
- </style>
- </head>
- <body>
- <section class="main-content">
- <div class="container">
- <h1><%= user.username %></h1>
- <br />
- <h3>Joined <%=go()%> ago<% if(br()) { %> <br> Last seen <%=br()%> <% } %>
- <br /> <br>
- <% var arank =(lb.findIndex((l)=>l.username==user.username)+1); %>
- <%= (arank==0?"":`#${arank} all time`) %>
- <br>
- <% var brank =(lb2.findIndex((l)=>l.username==user.username)+1); %>
- <%= (brank==0?"":`#${brank} today`) %>
- <br/>
- <br/>
- <% function conv(num) {
- return num>999?parseFloat((num/1000).toFixed(num<10000?2:1))+"k":num;
- } %>
- <%= conv(user.views+1) %> profile views
- </h3>
- <br />
- <div class="row">
- <div class="col-sm-4">
- <div class="leaderboard-card">
- <div class="leaderboard-card__top">
- <h3 class="text-center"><%= numberWithCommas(games.reduce((a,b)=>a+b.game_count,0)) %></h3>
- </div>
- <div class="leaderboard-card__body">
- <div class="text-center">
- <br /><br />
- <h5 class="mb-0">Games Played</h5>
- <p class="text-muted mb-0"></p>
- </div>
- </div>
- </div>
- </div>
- <div class="col-sm-4">
- <div class="leaderboard-card">
- <div class="leaderboard-card__top">
- <h3 class="text-center">
- <% var e = 0; games.forEach((x)=>e+=(x.stabs*300)+x.coins ) %>
- <%= numberWithCommas(e) %>
- </h3>
- </div>
- <div class="leaderboard-card__body">
- <div class="text-center">
- <br /><br />
- <div class="tooltipy">
- <h5 class="mb-0">XP</h5>
- <span class="tooltiptexty"
- >1 coin = 1 XP<br />1 stab = 300 XP</span
- >
- </div>
- <p class="text-muted mb-0"></p>
- </div>
- </div>
- </div>
- </div>
- <div class="col-sm-4">
- <div class="leaderboard-card">
- <div class="leaderboard-card__top">
- <h3 class="text-center">
- <% var e = 0; games.forEach((x)=>e+=x.game_time ) %>
- <%= msToTime(e)==""?"0s":msToTime(e) %>
- </h3>
- </div>
- <div class="leaderboard-card__body">
- <div class="text-center">
- <br /><br />
- <h5 class="mb-0">Total Playtime</h5>
- <p class="text-muted mb-0"></p>
- </div>
- </div>
- </div>
- </div>
- <br/>
- <div class="col-sm-4">
- <div class="leaderboard-card">
- <div class="leaderboard-card__top">
- <h3 class="text-center">
- <% var e = 0; games.forEach((x)=>e+=x.stabs ) %>
- <%= numberWithCommas(e) %>
- </h3>
- </div>
- <div class="leaderboard-card__body">
- <div class="text-center">
- <br /><br />
- <h5 class="mb-0">Stabs</h5>
- <p class="text-muted mb-0"></p>
- </div>
- </div>
- </div>
- </div>
- <div class="col-sm-4">
- <div class="leaderboard-card">
- <div class="leaderboard-card__top">
- <h3 class="text-center">
- <% var e = 0; games.forEach((x)=>e+=(x.kills*300)+x.coins ) %>
- <%= user.skins.collected.length +" / "+ cosmetics.skins.length %>
- </h3>
- </div>
- <div class="leaderboard-card__body">
- <div class="text-center">
- <br /><br />
- <h5 class="mb-0">Skins Owned</h5>
- <p class="text-muted mb-0"></p>
- </div>
- </div>
- </div>
- </div>
- </div>
- <style>
- .dropdown {
- display:inline-block;
- /* additional code */
- }
- </style>
- <div>
- <div class="dropdown">
- <button
- class="btn btn-secondary dropdown-toggle"
- type="button"
- id="total"
- data-toggle="dropdown"
- aria-haspopup="true"
- aria-expanded="false"
- >
- Total
- </button>
- <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
- <button
- class="dropdown-item"
- id="totalClick"
- onclick="changeTotal()"
- >Gained</a
- >
- </div>
- </div>
- <div class="dropdown">
- <button
- class="btn btn-secondary dropdown-toggle"
- type="button"
- data-toggle="dropdown"
- aria-haspopup="true"
- aria-expanded="false"
- id="selected"
- >
- XP
- </button>
- <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
- <button
- class="dropdown-item"
- id="op1"
- >Coins</button>
- <button
- class="dropdown-item"
- id="op2"
- >Kills</button
- >
- <button
- class="dropdown-item"
- id="op3"
- >Time</button
- >
- </div>
- </div>
- <canvas id="myChart"></canvas>
- </div>
- <script>
- function msToTime(duration) {
- const portions = [];
- const msInHour = 1000 * 60 * 60;
- const hours = Math.trunc(duration / msInHour);
- if (hours > 0) {
- portions.push(hours + 'h');
- duration = duration - (hours * msInHour);
- }
- const msInMinute = 1000 * 60;
- const minutes = Math.trunc(duration / msInMinute);
- if (minutes > 0) {
- portions.push(minutes + 'm');
- duration = duration - (minutes * msInMinute);
- }
- const seconds = Math.trunc(duration / 1000);
- if (seconds > 0) {
- portions.push(seconds + 's');
- }
- return portions.join(' ') ? portions.join(' ') : "0s";
- }
- const labels = <%- "["+stats.map((e) => `"${e.dt.toString().split(" ").slice(0,3).join(" ")}"`).join(",")+"]" %>
- function runningTotal(nums) {
- let psum = 0;
- return nums.map(x => psum += x);
- };
- var xpData = <%- "["+stats.map((e) => `"${e.xp?e.xp:0}"`).join(",")+"]" %>
- var coinsData = <%- "["+stats.map((e) => `"${e.coins?e.coins:0}"`).join(",")+"]" %>
- var killsData = <%- "["+stats.map((e) => `"${e.kills?e.kills:0}"`).join(",")+"]" %>
- var timeData = <%- "["+stats.map((e) => `"${e.time?e.time:0}"`).join(",")+"]" %>
- function numberWithCommas(x) {
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- }
- var selected = "xp"
- function changeSelector(obj) {
- var list = ["XP", "Coins", "Kills", "Time"];
- selected = obj.innerHTML.toLowerCase();
- list = list.filter((o)=>o.toLowerCase()!=selected)
- document.getElementById("selected").innerHTML = obj.innerHTML;
- document.getElementById("op1").innerHTML = list[0];
- document.getElementById("op2").innerHTML = list[1];
- document.getElementById("op3").innerHTML = list[2];
- changeTotal(true);
- }
- document.getElementById("op1").addEventListener("click", () => {
- changeSelector(document.getElementById("op1"))
- })
- document.getElementById("op2").addEventListener("click", () => {
- changeSelector(document.getElementById("op2"))
- })
- document.getElementById("op3").addEventListener("click", () => {
- changeSelector(document.getElementById("op3"))
- })
- function getSelector() {
- if (selected == "xp") {
- return xpData
- } else if (selected == "coins") {
- return coinsData
- } else if (selected == "kills") {
- return killsData
- } else if(selected == "time") {
- return timeData
- }
- }
- var data = {
- labels: labels,
- datasets: [{
- label: 'Total xp',
- backgroundColor: 'rgb(255, 99, 132)',
- borderColor: 'rgb(255, 99, 132)',
- data: runningTotal(getSelector().map(Number)),
- }]
- };
- var config = {
- type: 'line',
- data: data,
- options: {
- plugins: {
- tooltip: {
- callbacks: {
- label: function(context) {
- return context.dataset.label+": "+(selected=="time"?msToTime(context.parsed.y):numberWithCommas(context.parsed.y));
- }
- }
- }
- },
- scales: {
- y: {
- ticks: {
- // Include a dollar sign in the ticks
- callback: function(value, index, ticks) {
- return selected=="time"?msToTime(value):numberWithCommas(value)
- }
- }
- }
- }
- }
- }
- var myChart = new Chart(
- document.getElementById('myChart'),
- config
- );
- document.getElementById("total").innerHTML = "Total"
- function changeTotal(e=false) {
- if(e) {
- if(document.getElementById("total").innerHTML == "Total") {
- data.datasets[0].data = runningTotal(getSelector(selected).map(Number))
- data.datasets[0].label = "Total "+selected
- } else {
- data.datasets[0].label = selected+" Gained"
- data.datasets[0].data = (getSelector().map(Number))
- }
- uh();
- return false;
- } else { if(document.getElementById("total").innerHTML == "Total") {
- document.getElementById("total").innerHTML = "Gained"
- document.getElementById("totalClick").innerHTML = "Total"
- data.datasets[0].label = selected+" Gained"
- data.datasets[0].data = (getSelector().map(Number))
- } else {
- document.getElementById("total").innerHTML = "Total"
- document.getElementById("totalClick").innerHTML = "Gained"
- data.datasets[0].data = runningTotal(getSelector(selected).map(Number))
- data.datasets[0].label = "Total "+selected
- }
- uh()
- return false;
- }
- }
- function uh() {
- myChart.destroy()
- myChart = new Chart(
- document.getElementById('myChart'),
- config
- );
- }
- </script>
- </div>
- </section>
- <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement