mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Improvements to scrobbler extension
This commit is contained in:
parent
9b3519d80a
commit
10a30ccfe8
@ -3,12 +3,12 @@
|
|||||||
chrome.tabs.onUpdated.addListener(onTabUpdated);
|
chrome.tabs.onUpdated.addListener(onTabUpdated);
|
||||||
chrome.tabs.onRemoved.addListener(onTabRemoved);
|
chrome.tabs.onRemoved.addListener(onTabRemoved);
|
||||||
//chrome.tabs.onActivated.addListener(onTabChanged);
|
//chrome.tabs.onActivated.addListener(onTabChanged);
|
||||||
chrome.runtime.onMessage.addListener(onPlaybackUpdate);
|
chrome.runtime.onMessage.addListener(onInternalMessage);
|
||||||
|
|
||||||
tabManagers = {}
|
tabManagers = {}
|
||||||
|
|
||||||
pages = {
|
pages = {
|
||||||
"plex":{
|
"Plex Web":{
|
||||||
"patterns":[
|
"patterns":[
|
||||||
"https://app.plex.tv",
|
"https://app.plex.tv",
|
||||||
"http://app.plex.tv",
|
"http://app.plex.tv",
|
||||||
@ -17,7 +17,7 @@ pages = {
|
|||||||
],
|
],
|
||||||
"script":"plex.js"
|
"script":"plex.js"
|
||||||
},
|
},
|
||||||
"youtube_music":{
|
"YouTube Music":{
|
||||||
"patterns":[
|
"patterns":[
|
||||||
"https://music.youtube.com",
|
"https://music.youtube.com",
|
||||||
"http://music.youtube.com"
|
"http://music.youtube.com"
|
||||||
@ -84,15 +84,34 @@ function onTabRemoved(tabId,removeInfo) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function onPlaybackUpdate(request,sender) {
|
function onInternalMessage(request,sender) {
|
||||||
tabId = sender.tab.id
|
// message from settings menu
|
||||||
//console.log("Message was sent from tab id " + tabId)
|
if (request.type == "query") {
|
||||||
if (tabManagers.hasOwnProperty(tabId)) {
|
answer = [];
|
||||||
//console.log("This is managed! Seems to be " + tabManagers[tabId].page)
|
for (tabId in tabManagers) {
|
||||||
tabManagers[tabId].playbackUpdate(request)
|
manager = tabManagers[tabId]
|
||||||
|
if (manager.currentlyPlaying) {
|
||||||
|
answer.push([manager.page,manager.currentArtist,manager.currentTitle])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
answer.push([manager.page,null])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
chrome.runtime.sendMessage({"type":"response","content":answer})
|
||||||
}
|
}
|
||||||
//console.log("Got update from Plex Web!")
|
|
||||||
|
//message from content script
|
||||||
|
if (request.type == "startPlayback" || request.type == "stopPlayback") {
|
||||||
|
tabId = sender.tab.id
|
||||||
|
//console.log("Message was sent from tab id " + tabId)
|
||||||
|
if (tabManagers.hasOwnProperty(tabId)) {
|
||||||
|
//console.log("This is managed! Seems to be " + tabManagers[tabId].page)
|
||||||
|
tabManagers[tabId].playbackUpdate(request)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,15 +21,22 @@
|
|||||||
border: 0px solid;
|
border: 0px solid;
|
||||||
padding:2px;
|
padding:2px;
|
||||||
}
|
}
|
||||||
|
span {
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="wat">
|
<div id="wat">
|
||||||
<span id="checkmark_url"></span> <span style="line-height:20px">Server:</span><br />
|
<span id="checkmark_url"></span> <span>Server:</span><br />
|
||||||
<input type="text" id="serverurl" value="http://localhost:42010" />
|
<input type="text" id="serverurl" value="http://localhost:42010" />
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<span id="checkmark_key"></span> <span style="line-height:20px">API key:</span><br />
|
<span id="checkmark_key"></span> <span>API key:</span><br />
|
||||||
<input type="text" id="apikey" />
|
<input type="text" id="apikey" />
|
||||||
|
<br/><br/>
|
||||||
|
<span>Tabs:</span>
|
||||||
|
<list id="playinglist">
|
||||||
|
</list>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -10,20 +10,53 @@ document.addEventListener("DOMContentLoaded",function() {
|
|||||||
document.getElementById("apikey").addEventListener("focusout",checkServer);
|
document.getElementById("apikey").addEventListener("focusout",checkServer);
|
||||||
|
|
||||||
|
|
||||||
|
chrome.runtime.onMessage.addListener(onInternalMessage);
|
||||||
|
|
||||||
|
|
||||||
chrome.storage.local.get({"serverurl":"http://localhost:42010"},function(result) {
|
chrome.storage.local.get({"serverurl":"http://localhost:42010"},function(result) {
|
||||||
document.getElementById("serverurl").value = result["serverurl"]
|
document.getElementById("serverurl").value = result["serverurl"]
|
||||||
checkServer()
|
checkServerMaybe()
|
||||||
});
|
});
|
||||||
chrome.storage.local.get({"apikey":"BlackPinkInYourArea"},function(result) {
|
chrome.storage.local.get({"apikey":"BlackPinkInYourArea"},function(result) {
|
||||||
document.getElementById("apikey").value = result["apikey"]
|
document.getElementById("apikey").value = result["apikey"]
|
||||||
checkServer()
|
checkServerMaybe()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
chrome.runtime.sendMessage({"type":"query"})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//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
|
||||||
|
html = "";
|
||||||
|
for (var i=0;i<players.length;i++) {
|
||||||
|
if (players[i][1]) {
|
||||||
|
html += "<li>" + players[i][0] + ": " + players[i][1] + " - " + players[i][2]
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
html += "<li>" + players[i][0] + ": Playing nothing"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.getElementById("playinglist").innerHTML = html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function updateServer() {
|
function updateServer() {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user