Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
style: semicolons
Browse files Browse the repository at this point in the history
  • Loading branch information
zdimension committed Jan 28, 2024
1 parent 7f4ccb7 commit b9e08ad
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 76 deletions.
120 changes: 60 additions & 60 deletions Contents/Resources/web/js/plexauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ var p = {
name: 'Unknown',
version: 'Unknown',
os: 'Unknown'
}
};
if (typeof platform !== 'undefined') {
p.name = platform.name
p.version = platform.version
p.os = platform.os.toString()
p.name = platform.name;
p.version = platform.version;
p.os = platform.os.toString();
}

function getPlexHeaders(clientID) {
Expand All @@ -24,16 +24,16 @@ function getPlexHeaders(clientID) {
'X-Plex-Device-Name': p.name + ' (Themerr)',
'X-Plex-Device-Screen-Resolution': window.screen.width + 'x' + window.screen.height,
'X-Plex-Language': 'en'
}
};
}

function encodeData(data) {
return Object.keys(data).map(function (key) {
return [key, data[key]].map(encodeURIComponent).join("=")
}).join("&")
return [key, data[key]].map(encodeURIComponent).join("=");
}).join("&");
}

var plex_oauth_window = null
var plex_oauth_window = null;
const plex_oauth_loader = '<style>' +
'.login-loader-container {' +
'font-family: "Open Sans", Arial, sans-serif;' +
Expand Down Expand Up @@ -73,98 +73,98 @@ const plex_oauth_loader = '<style>' +
'<br>' +
'Redirecting to the Plex login page...' +
'</div>' +
'</div>'
'</div>';

function closePlexOAuthWindow() {
if (plex_oauth_window) {
plex_oauth_window.close()
plex_oauth_window.close();
}
}

function getKeyPath(key, path) {
var key_path = key
var key_path = key;
if (path !== false) {
key_path = `${key_path}_${window.location.pathname}`
key_path = `${key_path}_${window.location.pathname}`;
}
return key_path
return key_path;
}

function setLocalStorage(key, value, path) {
var key_path = getKeyPath(key, path)
localStorage.setItem(key_path, value)
var key_path = getKeyPath(key, path);
localStorage.setItem(key_path, value);
}

function getLocalStorage(key, default_value, path) {
var key_path = getKeyPath(key, path)
var value = localStorage.getItem(key_path)
var key_path = getKeyPath(key, path);
var value = localStorage.getItem(key_path);
if (value !== null) {
return value
return value;
} else if (default_value !== undefined) {
setLocalStorage(key, default_value, path)
return default_value
setLocalStorage(key, default_value, path);
return default_value;
}
}

function uuidv4() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
var cryptoObj = window.crypto || window.msCrypto // for IE 11
return (c ^ cryptoObj.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
})
var cryptoObj = window.crypto || window.msCrypto; // for IE 11
return (c ^ cryptoObj.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16);
});
}

getPlexOAuthPin = function (clientID) {
var x_plex_headers = getPlexHeaders(clientID)
var deferred = $.Deferred()
var x_plex_headers = getPlexHeaders(clientID);
var deferred = $.Deferred();

$.ajax({
url: 'https://plex.tv/api/v2/pins?strong=true',
type: 'POST',
headers: x_plex_headers,
success: function (data) {
deferred.resolve({ pin: data.id, code: data.code })
deferred.resolve({ pin: data.id, code: data.code });
},
error: function () {
closePlexOAuthWindow()
deferred.reject()
closePlexOAuthWindow();
deferred.reject();
}
})
return deferred
}
});
return deferred;
};

function PopupCenter(url, title, w, h) {
// Fixes dual-screen position Most browsers Firefox
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX
var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;

var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

var left = ((width / 2) - (w / 2)) + dualScreenLeft
var top = ((height / 2) - (h / 2)) + dualScreenTop
var newWindow = window.open(url, title, `scrollbars=yes, width=${w}, height=${h}, top=${top}, left=${left}`)
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(url, title, `scrollbars=yes, width=${w}, height=${h}, top=${top}, left=${left}`);

// Puts focus on the newWindow
if (window.focus) {
newWindow.focus()
newWindow.focus();
}

return newWindow
return newWindow;
}

var polling = null
var polling = null;

function PlexOAuth(success, error, pre, clientID) {
if (typeof pre === "function") {
pre()
pre();
}
closePlexOAuthWindow()
plex_oauth_window = PopupCenter('', 'Plex-OAuth', 600, 700)
$(plex_oauth_window.document.body).html(plex_oauth_loader)
closePlexOAuthWindow();
plex_oauth_window = PopupCenter('', 'Plex-OAuth', 600, 700);
$(plex_oauth_window.document.body).html(plex_oauth_loader);

getPlexOAuthPin(clientID).then(function (data) {
var x_plex_headers = getPlexHeaders(clientID)
const pin = data.pin
const code = data.code
var x_plex_headers = getPlexHeaders(clientID);
const pin = data.pin;
const code = data.code;

var oauth_params = {
'clientID': x_plex_headers['X-Plex-Client-Identifier'],
Expand All @@ -178,9 +178,9 @@ function PlexOAuth(success, error, pre, clientID) {
'context[device][screenResolution]': x_plex_headers['X-Plex-Device-Screen-Resolution'],
'context[device][layout]': 'desktop',
'code': code
}
};

plex_oauth_window.location = `https://app.plex.tv/auth/#!?${encodeData(oauth_params)}`
plex_oauth_window.location = `https://app.plex.tv/auth/#!?${encodeData(oauth_params)}`;
polling = pin;

(function poll() {
Expand All @@ -190,32 +190,32 @@ function PlexOAuth(success, error, pre, clientID) {
headers: x_plex_headers,
success: function (data) {
if (data.authToken) {
closePlexOAuthWindow()
closePlexOAuthWindow();
if (typeof success === "function") {
success(data.authToken)
success(data.authToken);
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
if (textStatus !== "timeout") {
closePlexOAuthWindow()
closePlexOAuthWindow();
if (typeof error === "function") {
error()
error();
}
}
},
complete: function () {
if (!plex_oauth_window.closed && polling === pin) {
setTimeout(function () { poll() }, 1000)
setTimeout(function () { poll(); }, 1000);
}
},
timeout: 10000
})
})()
});
})();
}, function () {
closePlexOAuthWindow()
closePlexOAuthWindow();
if (typeof error === "function") {
error()
error();
}
})
});
}
32 changes: 16 additions & 16 deletions Contents/Resources/web/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@
<script src="{{ url_for('static', filename='js/plexauth.js') }}"></script>
<script>
function OAuthSuccessCallback(authToken) {
signIn(authToken)
signIn(authToken);
}
function OAuthErrorCallback() {
$('#sign-in-alert').text('Error communicating with Plex.tv.').show()
$('#sign-in-alert').text('Error communicating with Plex.tv.').show();
}

$('#sign-in-plex').click(function () {
PlexOAuth(OAuthSuccessCallback, OAuthErrorCallback)
})
PlexOAuth(OAuthSuccessCallback, OAuthErrorCallback);
});

function signIn(token) {
$('.login-container button').prop('disabled', true)
$('#sign-in-plex').html('<i class="fa fa-refresh fa-spin"></i>&nbsp; Sign In with Plex')
$('.login-container button').prop('disabled', true);
$('#sign-in-plex').html('<i class="fa fa-refresh fa-spin"></i>&nbsp; Sign In with Plex');

var data = {
token: token
}
var x_plex_headers = getPlexHeaders()
data = $.extend(data, x_plex_headers)
};
var x_plex_headers = getPlexHeaders();
data = $.extend(data, x_plex_headers);

$.ajax({
url: '{{ url_for("login") }}',
Expand All @@ -55,21 +55,21 @@
dataType: 'json',
statusCode: {
200: function (xhr, status) {
window.location = "{{ redirect_uri }}"
window.location = "{{ redirect_uri }}";
},
401: function (xhr, status) {
$('#sign-in-alert').text('Invalid Plex account, or the account is not the owner of the server.').show()
$('#sign-in-alert').text('Invalid Plex account, or the account is not the owner of the server.').show();
},
429: function (xhr, status) {
var retry = Math.ceil(xhr.getResponseHeader('Retry-After') / 60)
$('#sign-in-alert').text(`Too many login attempts. Try again in ${retry} minute(s).`).show()
var retry = Math.ceil(xhr.getResponseHeader('Retry-After') / 60);
$('#sign-in-alert').text(`Too many login attempts. Try again in ${retry} minute(s).`).show();
}
},
complete: function () {
$('.login-container button').prop('disabled', false)
$('#sign-in-plex').html('<i class="fa fa-sign-in"></i>&nbsp; Sign In with Plex')
$('.login-container button').prop('disabled', false);
$('#sign-in-plex').html('<i class="fa fa-sign-in"></i>&nbsp; Sign In with Plex');
}
})
});
}
</script>
{% endblock scripts %}

0 comments on commit b9e08ad

Please sign in to comment.