diff options
author | Marvin Borner | 2023-01-05 15:03:48 +0100 |
---|---|---|
committer | Marvin Borner | 2023-01-05 15:03:48 +0100 |
commit | a10ea4d3ae03406b230a1fbcbc77a60c48a7154e (patch) | |
tree | 0eed81a1a60203401f30a0c85896cdc4a4bfe4ab /assets | |
parent | b63f1f0ae48d14863cd2dc7da0d7310b513ed6a8 (diff) |
Diffstat (limited to 'assets')
-rwxr-xr-x | assets/js/main.js | 42 | ||||
-rwxr-xr-x | assets/php/getData.php | 2 |
2 files changed, 33 insertions, 11 deletions
diff --git a/assets/js/main.js b/assets/js/main.js index 77dc22e..537b3d7 100755 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -78,7 +78,7 @@ function analyze(data) { obj.count++; }); - drawTotalSpent(filtered); + drawTotalSpent(data); drawTimeline(filtered); drawTopTitles(filtered); drawHeatmap(filtered); @@ -87,14 +87,12 @@ function analyze(data) { } function drawTotalSpent(data) { - const totalHours = Object.keys(data) - .map((key) => data[key].duration) - .reduce((a, b) => a + b); + const totalSeconds = data.reduce((a,b) => a + b.duration, 0); document.querySelector("#totalSpent").innerHTML = ` - ${Math.floor(totalHours / 24)} days or - ${Math.floor(totalHours)} hours or - ${Math.round(totalHours * 60)} minutes or - ${Math.round(totalHours * 60 * 60)} seconds!`; + ${Math.floor(totalSeconds / 60 / 60 / 24)} days or + ${Math.floor(totalSeconds / 60 / 60)} hours or + ${Math.round(totalSeconds / 60)} minutes or + ${Math.round(totalSeconds)} seconds!`; } function drawTimeline(data) { @@ -189,6 +187,10 @@ function drawTopTitles(data) { // TODO: There may be a bug in the first week in January function drawHeatmap(data) { + const prev = document.getElementById("prevYear"); + const selected = document.getElementById("selectedYear"); + const next = document.getElementById("nextYear"); + Date.prototype.getWeek = function () { var d = new Date( Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()) @@ -198,8 +200,15 @@ function drawHeatmap(data) { return Math.ceil(((d - yearStart) / 86400000 + 1) / 7); }; - const currentYear = new Date().getFullYear(); - const currentWeek = new Date().getWeek(); + let currentYear, currentWeek; + if (selected.innerText == "") { + currentYear = new Date().getFullYear(); + currentWeek = new Date().getWeek(); + selected.innerText = currentYear; + } else { + currentYear = +selected.innerText; + currentWeek = 52; + } const days = [[], [], [], [], [], [], []]; Object.keys(data).forEach((elem) => { @@ -302,6 +311,19 @@ function drawHeatmap(data) { }, }); chart.render(); + + prev.onclick = () => { + selected.innerText = +selected.innerText - 1; + chart.destroy(); + drawHeatmap(data); + } + + next.onclick = () => { + selected.innerText = +selected.innerText + 1; + chart.destroy(); + drawHeatmap(data); + } + } Apex.colors = ["#e50914"]; diff --git a/assets/php/getData.php b/assets/php/getData.php index a236d49..603670d 100755 --- a/assets/php/getData.php +++ b/assets/php/getData.php @@ -19,7 +19,7 @@ $result = '['; while ($isLastPage === false) { // Anywhere on netflix.com in console: netflix.appContext.state.model.models.serverDefs.data.BUILD_IDENTIFIER - $ch = curl_init('https://www.netflix.com/shakti/vbe1263cd/viewingactivity?pg=' . $currentPage . '&pgSize=100'); + $ch = curl_init('https://www.netflix.com/api/shakti/mre/viewingactivity?pg=' . $currentPage . '&pgSize=100'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_COOKIE, $cookie); |