mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Improved scrobbler slightly
This commit is contained in:
parent
03c3202cdf
commit
19c928773d
@ -207,6 +207,14 @@ class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
backlog_scrobble() {
|
||||
while (this.alreadyPlayed > this.currentLength) {
|
||||
this.alreadyPlayed = this.alreadyPlayed - this.currentLength
|
||||
var secondsago = this.alreadyPlayed
|
||||
scrobble(this.currentArtist,this.currentTitle,this.currentLength,secondsago)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -216,12 +224,8 @@ class Controller {
|
||||
if (artist == this.currentArtist && title == this.currentTitle && !this.currentlyPlaying) {
|
||||
console.log("Resuming playback of " + this.currentTitle)
|
||||
|
||||
// Already played full song
|
||||
while (this.alreadyPlayed > this.currentLength) {
|
||||
this.alreadyPlayed = this.alreadyPlayed - this.currentLength
|
||||
var secondsago = this.alreadyPlayed
|
||||
scrobble(this.currentArtist,this.currentTitle,this.currentLength,secondsago)
|
||||
}
|
||||
// Already played full song?
|
||||
this.backlog_scrobble()
|
||||
|
||||
this.setUpdate()
|
||||
this.currentlyPlaying = true
|
||||
@ -263,12 +267,8 @@ class Controller {
|
||||
}
|
||||
|
||||
|
||||
// Already played full song
|
||||
while (this.alreadyPlayed > this.currentLength) {
|
||||
this.alreadyPlayed = this.alreadyPlayed - this.currentLength
|
||||
var secondsago = this.alreadyPlayed
|
||||
scrobble(this.currentArtist,this.currentTitle,this.currentLength,secondsago)
|
||||
}
|
||||
// Already played full song?
|
||||
this.backlog_scrobble()
|
||||
|
||||
this.currentlyPlaying = false
|
||||
|
||||
|
@ -29,10 +29,10 @@
|
||||
<body>
|
||||
<div id="wat">
|
||||
<span id="checkmark_url"></span> <span>Server:</span><br />
|
||||
<input type="text" id="serverurl" value="http://localhost:42010" />
|
||||
<input type="text" id="serverurl" oninput="saveConfig()" />
|
||||
<br /><br />
|
||||
<span id="checkmark_key"></span> <span>API key:</span><br />
|
||||
<input type="text" id="apikey" />
|
||||
<input type="text" id="apikey" oninput="saveConfig()" />
|
||||
<br/><br/>
|
||||
<span>Tabs:</span>
|
||||
<list id="playinglist">
|
||||
|
@ -1,7 +1,10 @@
|
||||
var config_defaults = {
|
||||
serverurl:"http://localhost:42010",
|
||||
apikey:"BlackPinkInYourArea"
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded",function() {
|
||||
document.getElementById("serverurl").addEventListener("input",updateServer);
|
||||
document.getElementById("apikey").addEventListener("input",updateAPIKey);
|
||||
|
||||
document.getElementById("serverurl").addEventListener("change",checkServer);
|
||||
document.getElementById("apikey").addEventListener("change",checkServer);
|
||||
@ -12,15 +15,12 @@ document.addEventListener("DOMContentLoaded",function() {
|
||||
|
||||
chrome.runtime.onMessage.addListener(onInternalMessage);
|
||||
|
||||
|
||||
chrome.storage.local.get({"serverurl":"http://localhost:42010"},function(result) {
|
||||
document.getElementById("serverurl").value = result["serverurl"]
|
||||
checkServerMaybe()
|
||||
});
|
||||
chrome.storage.local.get({"apikey":"BlackPinkInYourArea"},function(result) {
|
||||
document.getElementById("apikey").value = result["apikey"]
|
||||
checkServerMaybe()
|
||||
});
|
||||
chrome.storage.local.get(config_defaults,function(result){
|
||||
for (var key in result) {
|
||||
document.getElementById(key).value = result[key];
|
||||
}
|
||||
checkServer();
|
||||
})
|
||||
|
||||
chrome.runtime.sendMessage({"type":"query"})
|
||||
|
||||
@ -29,17 +29,6 @@ document.addEventListener("DOMContentLoaded",function() {
|
||||
});
|
||||
|
||||
|
||||
//this makes sure only the second call actually makes a request (the first request is pointless
|
||||
//when the other element isn't filled yet and might actually overwrite the correct result because
|
||||
//of a race condition)
|
||||
var done = 0
|
||||
function checkServerMaybe() {
|
||||
done++;
|
||||
if (done == 2) {
|
||||
checkServer()
|
||||
}
|
||||
}
|
||||
|
||||
function onInternalMessage(request,sender) {
|
||||
if (request.type == "response") {
|
||||
players = request.content
|
||||
@ -58,17 +47,11 @@ function onInternalMessage(request,sender) {
|
||||
|
||||
|
||||
|
||||
function updateServer() {
|
||||
|
||||
text = document.getElementById("serverurl").value
|
||||
|
||||
|
||||
chrome.storage.local.set({"serverurl":text})
|
||||
}
|
||||
|
||||
function updateAPIKey() {
|
||||
text = document.getElementById("apikey").value
|
||||
chrome.storage.local.set({"apikey":text})
|
||||
function saveConfig() {
|
||||
for (var key in config_defaults) {
|
||||
var value = document.getElementById(key).value;
|
||||
chrome.storage.local.set({ [key]: value });
|
||||
}
|
||||
}
|
||||
|
||||
function checkServer() {
|
||||
|
Loading…
Reference in New Issue
Block a user