Skip to content

Commit

Permalink
Changes to the Extension so it doesn't need to get reloaded after Con…
Browse files Browse the repository at this point in the history
…nection failures
  • Loading branch information
Quadrubo committed May 15, 2021
1 parent ab33b18 commit aa67551
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ function next() {

function connectToServer(server_tmp, port_tmp) {
var ws_connection_url = "ws://" + server_tmp + ":" + port_tmp;
const ws = new WebSocket(ws_connection_url);

var ws = new WebSocket(ws_connection_url);
// On opened connection
ws.addEventListener("open", () => {
window.alert("Connected to Websocket Server \"" + ws_connection_url + "\".");
Expand Down Expand Up @@ -123,12 +123,16 @@ function connectToServer(server_tmp, port_tmp) {

});

ws.addEventListener("close", () => {
ws.addEventListener("close", function(e) {
window.alert("Connection closed.");
ws = undefined;
});

// On play_pause button press
document.getElementsByClassName("videoOsd-btnPause")[0].addEventListener("click", function(e) {
if(ws == undefined) {
return;
}
if(e.isTrusted){
// Human input, sending to other people
var percentage = document.getElementsByClassName("emby-slider-background-lower")[0].getAttribute("style");
Expand Down Expand Up @@ -159,6 +163,9 @@ function connectToServer(server_tmp, port_tmp) {
for(var i = 0; i < page.length; i++){
if (page[i].getAttribute("data-properties") == "fullscreen"){
page[i].addEventListener("click", function(e) {
if(ws == undefined) {
return;
}
if(e.isTrusted){
if(e.target.className == "view flex page"){
if(e.target.getAttribute)
Expand Down Expand Up @@ -193,6 +200,9 @@ function connectToServer(server_tmp, port_tmp) {

// On next_track button press
document.getElementsByClassName("btnNextTrack")[0].addEventListener("click", function(e) {
if(ws == undefined) {
return;
}
if(e.isTrusted) {
sending = {
"command": "next",
Expand All @@ -205,6 +215,9 @@ function connectToServer(server_tmp, port_tmp) {

// On previous_track button press
document.getElementsByClassName("btnPreviousTrack")[0].addEventListener("click", function(e){
if(ws == undefined) {
return;
}
if(e.isTrusted) {
sending = {
"command": "prev",
Expand All @@ -218,6 +231,9 @@ function connectToServer(server_tmp, port_tmp) {
// On 10_backward button press
document.getElementsByClassName("btnRewind")[0].addEventListener("click", function(e) {
if(e.isTrusted) {
if(ws == undefined) {
return;
}
var time_left = document.getElementsByClassName("videoOsdPositionText")[0].textContent.split(":");
var time_right = document.getElementsByClassName("videoOsdDurationText")[0].textContent.split(":");

Expand Down Expand Up @@ -258,6 +274,9 @@ function connectToServer(server_tmp, port_tmp) {

// On 10_forward button press
document.getElementsByClassName("btnOsdFastForward")[0].addEventListener("click", function(e) {
if(ws == undefined) {
return;
}
if(e.isTrusted) {
var time_left = document.getElementsByClassName("videoOsdPositionText")[0].textContent.split(":");
var time_right = document.getElementsByClassName("videoOsdDurationText")[0].textContent.split(":");
Expand Down Expand Up @@ -299,6 +318,9 @@ function connectToServer(server_tmp, port_tmp) {

// On slider change
document.getElementsByClassName("videoOsdPositionSlider emby-slider")[0].addEventListener("click", function(e) {
if(ws == undefined) {
return;
}
if(e.isTrusted){
var percentage = document.getElementsByClassName("emby-slider-background-lower")[0].getAttribute("style");
percentage = percentage.split(":")[1].split("%")[0];
Expand Down

0 comments on commit aa67551

Please sign in to comment.