start move blog to gronk
This commit is contained in:
parent
ad7096bca2
commit
816896537d
63
blog/lastfm_bookmarklets.md
Executable file
63
blog/lastfm_bookmarklets.md
Executable file
@ -0,0 +1,63 @@
|
|||||||
|
---
|
||||||
|
author: Akbar Rahman
|
||||||
|
pub_date: Sat, 13 Apr 2024 20:00:31 +0100
|
||||||
|
title: last.fm bookmarklets
|
||||||
|
tags: [ last.fm, scripts ]
|
||||||
|
uuid: e54ebf58-4033-4dae-81db-91db344f1311
|
||||||
|
---
|
||||||
|
|
||||||
|
# last.fm bookmarklets
|
||||||
|
|
||||||
|
last.fm doesn't let you see how many scrobbled you've made in one day particularly easily.
|
||||||
|
Here is a bookmarklet to solve that.
|
||||||
|
|
||||||
|
<label for="days"> Number of days to view: </label>
|
||||||
|
<input type="number" value="1" id="days" placeholder="Days"/><br><br>
|
||||||
|
<label for="offset"> Offset (e.g. 0 to include today, 7 to look at last week): </label>
|
||||||
|
<input type="number" value="0" id="offset" placeholder="Offset (Days)" /><br><br>
|
||||||
|
<label for="username"> last.fm username </label>
|
||||||
|
<input type="text" value="" id="username" placeholder="Username" /><br><br>
|
||||||
|
<input type="button" id="button" value="Generate bookmarklet"><br>
|
||||||
|
|
||||||
|
<p><a style="display: none" href="" id="scriptLink">Bookmark this link</a></p>
|
||||||
|
|
||||||
|
When you press generate bookmarklet, the values `OFFSET`, `DAYS`, `USERNAME` will be
|
||||||
|
subsituted and put into the link above.
|
||||||
|
It's always best to inspect bookmarklets though.
|
||||||
|
Inspect the page to view the script used to generate the bookmarklet.
|
||||||
|
|
||||||
|
<textarea cols="109" rows="15" readonly id="scriptText">
|
||||||
|
javascript: (() => {
|
||||||
|
const MILLESECONDS_PER_DAY = 1000 * 24 * 60 * 60;
|
||||||
|
const OFFSET;
|
||||||
|
const DAYS;
|
||||||
|
const USERNAME;
|
||||||
|
|
||||||
|
const currentDate = new Date();
|
||||||
|
const to = new Date(currentDate - (OFFSET * MILLESECONDS_PER_DAY));
|
||||||
|
const from = new Date(to - ((DAYS-1) * MILLESECONDS_PER_DAY));
|
||||||
|
const toDate = to.getFullYear() + "-" + (to.getMonth()+1) + "-" + to.getDate();
|
||||||
|
const fromDate = from.getFullYear() + "-" + (from.getMonth()+1) + "-" + from.getDate();
|
||||||
|
|
||||||
|
document.location = "https://www.last.fm/user/" + USERNAME + "/library?from=" + fromDate + "&to=" + toDate;
|
||||||
|
})();
|
||||||
|
</textarea>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.getElementById("button").addEventListener("click", () => {
|
||||||
|
scriptText = document.getElementById("scriptText").value;
|
||||||
|
offset = document.getElementById("offset").value;
|
||||||
|
days = document.getElementById("days").value;
|
||||||
|
username = document.getElementById("username").value;
|
||||||
|
|
||||||
|
newscript = scriptText.replace(
|
||||||
|
"OFFSET", "OFFSET = " + offset
|
||||||
|
).replace(
|
||||||
|
"DAYS", "DAYS = " + days
|
||||||
|
).replace(
|
||||||
|
"USERNAME", "USERNAME = '" + username + "'"
|
||||||
|
);
|
||||||
|
document.getElementById("scriptLink").href = newscript;
|
||||||
|
document.getElementById("scriptLink").style = "";
|
||||||
|
});
|
||||||
|
</script>
|
4
blog/readme.md
Normal file
4
blog/readme.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
title: alv's blog
|
||||||
|
blog: true
|
||||||
|
---
|
Loading…
Reference in New Issue
Block a user