-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
25 lines (24 loc) · 1.17 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var clientIdRegex = new RegExp("server\/([a-f0-9]{40})\/");
var metadataIdRegex = new RegExp("key=%2Flibrary%2Fmetadata%2F(\\d+)");
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "clicked_browser_action" ) {
if (typeof localStorage.myPlexAccessToken != "undefined") {
clientId = clientIdRegex.exec(window.location.href);
metadataId = metadataIdRegex.exec(window.location.href);
if (clientId && clientId.length == 2) {
if (metadataId && metadataId.length == 2) {
chrome.runtime.sendMessage({"message": "got_plex_token", "token": localStorage.myPlexAccessToken,
"clientId": clientId[1], "metadataId": metadataId[1]});
} else {
console.log("couldn't get metadataId - possibly you're not looking at a media item");
}
} else {
console.log("couldn't get clientId");
}
} else {
console.log("You are currently not browsing or logged into a Plex web environment.");
}
}
}
);