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

Commit a2dc8c7

Browse files
committed
style: formatting
1 parent df171ff commit a2dc8c7

File tree

2 files changed

+126
-122
lines changed

2 files changed

+126
-122
lines changed

Contents/Resources/web/js/plexauth.js

Lines changed: 103 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,164 +4,167 @@ var p = {
44
name: 'Unknown',
55
version: 'Unknown',
66
os: 'Unknown'
7-
};
7+
}
88
if (typeof platform !== 'undefined') {
9-
p.name = platform.name;
10-
p.version = platform.version;
11-
p.os = platform.os.toString();
9+
p.name = platform.name
10+
p.version = platform.version
11+
p.os = platform.os.toString()
1212
}
1313

1414
function getPlexHeaders(clientID) {
1515
return {
1616
'Accept': 'application/json',
1717
'X-Plex-Product': 'Themerr',
1818
'X-Plex-Version': 'Plex OAuth',
19-
'X-Plex-Client-Identifier': clientID ? clientID : getLocalStorage('Tautulli_ClientID', uuidv4(), false),
19+
'X-Plex-Client-Identifier': clientID ? clientID : getLocalStorage('Themerr_ClientID', uuidv4(), false),
2020
'X-Plex-Platform': p.name,
2121
'X-Plex-Platform-Version': p.version,
2222
'X-Plex-Model': 'Plex OAuth',
2323
'X-Plex-Device': p.os,
2424
'X-Plex-Device-Name': p.name + ' (Themerr)',
2525
'X-Plex-Device-Screen-Resolution': window.screen.width + 'x' + window.screen.height,
2626
'X-Plex-Language': 'en'
27-
};
27+
}
2828
}
2929

3030
function encodeData(data) {
31-
return Object.keys(data).map(function(key) {
32-
return [key, data[key]].map(encodeURIComponent).join("=");
33-
}).join("&");
31+
return Object.keys(data).map(function (key) {
32+
return [key, data[key]].map(encodeURIComponent).join("=")
33+
}).join("&")
3434
}
3535

36-
var plex_oauth_window = null;
36+
var plex_oauth_window = null
3737
const plex_oauth_loader = '<style>' +
38-
'.login-loader-container {' +
39-
'font-family: "Open Sans", Arial, sans-serif;' +
40-
'position: absolute;' +
41-
'top: 0;' +
42-
'right: 0;' +
43-
'bottom: 0;' +
44-
'left: 0;' +
45-
'}' +
46-
'.login-loader-message {' +
47-
'color: #282A2D;' +
48-
'text-align: center;' +
49-
'position: absolute;' +
50-
'left: 50%;' +
51-
'top: 25%;' +
52-
'transform: translate(-50%, -50%);' +
53-
'}' +
54-
'.login-loader {' +
55-
'border: 5px solid #ccc;' +
56-
'-webkit-animation: spin 1s linear infinite;' +
57-
'animation: spin 1s linear infinite;' +
58-
'border-top: 5px solid #282A2D;' +
59-
'border-radius: 50%;' +
60-
'width: 50px;' +
61-
'height: 50px;' +
62-
'position: relative;' +
63-
'left: calc(50% - 25px);' +
64-
'}' +
65-
'@keyframes spin {' +
66-
'0% { transform: rotate(0deg); }' +
67-
'100% { transform: rotate(360deg); }' +
68-
'}' +
38+
'.login-loader-container {' +
39+
'font-family: "Open Sans", Arial, sans-serif;' +
40+
'position: absolute;' +
41+
'top: 0;' +
42+
'right: 0;' +
43+
'bottom: 0;' +
44+
'left: 0;' +
45+
'}' +
46+
'.login-loader-message {' +
47+
'color: #282A2D;' +
48+
'text-align: center;' +
49+
'position: absolute;' +
50+
'left: 50%;' +
51+
'top: 25%;' +
52+
'transform: translate(-50%, -50%);' +
53+
'}' +
54+
'.login-loader {' +
55+
'border: 5px solid #ccc;' +
56+
'-webkit-animation: spin 1s linear infinite;' +
57+
'animation: spin 1s linear infinite;' +
58+
'border-top: 5px solid #282A2D;' +
59+
'border-radius: 50%;' +
60+
'width: 50px;' +
61+
'height: 50px;' +
62+
'position: relative;' +
63+
'left: calc(50% - 25px);' +
64+
'}' +
65+
'@keyframes spin {' +
66+
'0% { transform: rotate(0deg); }' +
67+
'100% { transform: rotate(360deg); }' +
68+
'}' +
6969
'</style>' +
7070
'<div class="login-loader-container">' +
71-
'<div class="login-loader-message">' +
72-
'<div class="login-loader"></div>' +
73-
'<br>' +
74-
'Redirecting to the Plex login page...' +
75-
'</div>' +
76-
'</div>';
71+
'<div class="login-loader-message">' +
72+
'<div class="login-loader"></div>' +
73+
'<br>' +
74+
'Redirecting to the Plex login page...' +
75+
'</div>' +
76+
'</div>'
7777

7878
function closePlexOAuthWindow() {
7979
if (plex_oauth_window) {
80-
plex_oauth_window.close();
80+
plex_oauth_window.close()
8181
}
8282
}
8383

84-
function setLocalStorage(key, value, path) {
85-
var key_path = key;
84+
function getKeyPath(key, path) {
85+
var key_path = key
8686
if (path !== false) {
87-
key_path = key_path + '_' + window.location.pathname;
87+
key_path = `${key_path}_${window.location.pathname}`
8888
}
89-
localStorage.setItem(key_path, value);
89+
return key_path
90+
}
91+
92+
function setLocalStorage(key, value, path) {
93+
var key_path = getKeyPath(key, path)
94+
localStorage.setItem(key_path, value)
9095
}
96+
9197
function getLocalStorage(key, default_value, path) {
92-
var key_path = key;
93-
if (path !== false) {
94-
key_path = key_path + '_' + window.location.pathname;
95-
}
96-
var value = localStorage.getItem(key_path);
98+
var key_path = getKeyPath(key, path)
99+
var value = localStorage.getItem(key_path)
97100
if (value !== null) {
98101
return value
99102
} else if (default_value !== undefined) {
100-
setLocalStorage(key, default_value, path);
103+
setLocalStorage(key, default_value, path)
101104
return default_value
102105
}
103106
}
104107

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

112115
getPlexOAuthPin = function (clientID) {
113-
var x_plex_headers = getPlexHeaders(clientID);
114-
var deferred = $.Deferred();
116+
var x_plex_headers = getPlexHeaders(clientID)
117+
var deferred = $.Deferred()
115118

116119
$.ajax({
117120
url: 'https://plex.tv/api/v2/pins?strong=true',
118121
type: 'POST',
119122
headers: x_plex_headers,
120-
success: function(data) {
121-
deferred.resolve({pin: data.id, code: data.code});
123+
success: function (data) {
124+
deferred.resolve({ pin: data.id, code: data.code })
122125
},
123-
error: function() {
124-
closePlexOAuthWindow();
125-
deferred.reject();
126+
error: function () {
127+
closePlexOAuthWindow()
128+
deferred.reject()
126129
}
127-
});
128-
return deferred;
129-
};
130+
})
131+
return deferred
132+
}
130133

131134
function PopupCenter(url, title, w, h) {
132-
// Fixes dual-screen position Most browsers Firefox
133-
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
134-
var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;
135+
// Fixes dual-screen position Most browsers Firefox
136+
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX
137+
var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY
135138

136-
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
137-
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
139+
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width
140+
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height
138141

139-
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
140-
var top = ((height / 2) - (h / 2)) + dualScreenTop;
141-
var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
142+
var left = ((width / 2) - (w / 2)) + dualScreenLeft
143+
var top = ((height / 2) - (h / 2)) + dualScreenTop
144+
var newWindow = window.open(url, title, `scrollbars=yes, width=${w}, height=${h}, top=${top}, left=${left}`)
142145

143146
// Puts focus on the newWindow
144147
if (window.focus) {
145-
newWindow.focus();
148+
newWindow.focus()
146149
}
147150

148-
return newWindow;
151+
return newWindow
149152
}
150153

151-
var polling = null;
154+
var polling = null
152155

153156
function PlexOAuth(success, error, pre, clientID) {
154157
if (typeof pre === "function") {
155158
pre()
156159
}
157-
closePlexOAuthWindow();
158-
plex_oauth_window = PopupCenter('', 'Plex-OAuth', 600, 700);
159-
$(plex_oauth_window.document.body).html(plex_oauth_loader);
160+
closePlexOAuthWindow()
161+
plex_oauth_window = PopupCenter('', 'Plex-OAuth', 600, 700)
162+
$(plex_oauth_window.document.body).html(plex_oauth_loader)
160163

161164
getPlexOAuthPin(clientID).then(function (data) {
162-
var x_plex_headers = getPlexHeaders(clientID);
163-
const pin = data.pin;
164-
const code = data.code;
165+
var x_plex_headers = getPlexHeaders(clientID)
166+
const pin = data.pin
167+
const code = data.code
165168

166169
var oauth_params = {
167170
'clientID': x_plex_headers['X-Plex-Client-Identifier'],
@@ -177,42 +180,42 @@ function PlexOAuth(success, error, pre, clientID) {
177180
'code': code
178181
}
179182

180-
plex_oauth_window.location = 'https://app.plex.tv/auth/#!?' + encodeData(oauth_params);
183+
plex_oauth_window.location = `https://app.plex.tv/auth/#!?${encodeData(oauth_params)}`
181184
polling = pin;
182185

183186
(function poll() {
184187
$.ajax({
185-
url: 'https://plex.tv/api/v2/pins/' + pin,
188+
url: `https://plex.tv/api/v2/pins/${pin}`,
186189
type: 'GET',
187190
headers: x_plex_headers,
188191
success: function (data) {
189-
if (data.authToken){
190-
closePlexOAuthWindow();
192+
if (data.authToken) {
193+
closePlexOAuthWindow()
191194
if (typeof success === "function") {
192195
success(data.authToken)
193196
}
194197
}
195198
},
196199
error: function (jqXHR, textStatus, errorThrown) {
197200
if (textStatus !== "timeout") {
198-
closePlexOAuthWindow();
201+
closePlexOAuthWindow()
199202
if (typeof error === "function") {
200203
error()
201204
}
202205
}
203206
},
204207
complete: function () {
205-
if (!plex_oauth_window.closed && polling === pin){
206-
setTimeout(function() {poll()}, 1000);
208+
if (!plex_oauth_window.closed && polling === pin) {
209+
setTimeout(function () { poll() }, 1000)
207210
}
208211
},
209212
timeout: 10000
210-
});
211-
})();
213+
})
214+
})()
212215
}, function () {
213-
closePlexOAuthWindow();
216+
closePlexOAuthWindow()
214217
if (typeof error === "function") {
215218
error()
216219
}
217-
});
218-
}
220+
})
221+
}

Contents/Resources/web/templates/login.html

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
</div>
1616
<div class="row">
1717
<div class="col-sm-12">
18-
<button id="sign-in-plex" class="btn btn-primary login-button"><i class="fa fa-sign-in"></i>&nbsp; Sign In with Plex</button>
18+
<button id="sign-in-plex" class="btn btn-primary login-button"><i class="fa fa-sign-in"></i>&nbsp;
19+
Sign In with Plex</button>
1920
</div>
2021
</div>
2122
</div>
@@ -27,48 +28,48 @@
2728
<script src="{{ url_for('static', filename='js/plexauth.js') }}"></script>
2829
<script>
2930
function OAuthSuccessCallback(authToken) {
30-
signIn(authToken);
31+
signIn(authToken)
3132
}
3233
function OAuthErrorCallback() {
33-
$('#sign-in-alert').text('Error communicating with Plex.tv.').show();
34+
$('#sign-in-alert').text('Error communicating with Plex.tv.').show()
3435
}
3536

36-
$('#sign-in-plex').click(function() {
37-
PlexOAuth(OAuthSuccessCallback, OAuthErrorCallback);
38-
});
37+
$('#sign-in-plex').click(function () {
38+
PlexOAuth(OAuthSuccessCallback, OAuthErrorCallback)
39+
})
3940

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

4445
var data = {
4546
token: token
46-
};
47-
var x_plex_headers = getPlexHeaders();
48-
data = $.extend(data, x_plex_headers);
47+
}
48+
var x_plex_headers = getPlexHeaders()
49+
data = $.extend(data, x_plex_headers)
4950

5051
$.ajax({
5152
url: '{{ url_for("login") }}',
5253
type: 'POST',
5354
data: data,
5455
dataType: 'json',
5556
statusCode: {
56-
200: function(xhr, status) {
57-
window.location = "{{ redirect_uri }}";
57+
200: function (xhr, status) {
58+
window.location = "{{ redirect_uri }}"
5859
},
59-
401: function(xhr, status) {
60-
$('#sign-in-alert').text('Invalid Plex account, or the account is not the owner of the server.').show();
60+
401: function (xhr, status) {
61+
$('#sign-in-alert').text('Invalid Plex account, or the account is not the owner of the server.').show()
6162
},
62-
429: function(xhr, status) {
63+
429: function (xhr, status) {
6364
var retry = Math.ceil(xhr.getResponseHeader('Retry-After') / 60)
64-
$('#sign-in-alert').text('Too many login attempts. Try again in ' + retry + ' minute(s).').show();
65+
$('#sign-in-alert').text(`Too many login attempts. Try again in ${retry} minute(s).`).show()
6566
}
6667
},
67-
complete: function() {
68-
$('.login-container button').prop('disabled', false);
69-
$('#sign-in-plex').html('<i class="fa fa-sign-in"></i>&nbsp; Sign In with Plex');
68+
complete: function () {
69+
$('.login-container button').prop('disabled', false)
70+
$('#sign-in-plex').html('<i class="fa fa-sign-in"></i>&nbsp; Sign In with Plex')
7071
}
71-
});
72+
})
7273
}
7374
</script>
74-
{% endblock scripts %}
75+
{% endblock scripts %}

0 commit comments

Comments
 (0)