2021-12-12 16:31:15 +00:00
|
|
|
function cookie_login_actions() {
|
2022-01-11 13:33:30 +00:00
|
|
|
cookie = get_cookie('wrapperr-user');
|
2021-12-12 16:31:15 +00:00
|
|
|
|
|
|
|
if(cookie) {
|
|
|
|
document.getElementById('search_wrapped_form').style.display = 'block';
|
|
|
|
document.getElementById('plex_login_form').style.display = 'none';
|
|
|
|
document.getElementById('sign_out_div').style.display = 'block';
|
|
|
|
|
2022-01-11 13:33:30 +00:00
|
|
|
validate_cookie_user(cookie);
|
2021-12-12 16:31:15 +00:00
|
|
|
}
|
2020-12-19 16:10:59 +00:00
|
|
|
}
|
|
|
|
|
2021-12-12 16:31:15 +00:00
|
|
|
function wrapped_link_actions(hash) {
|
|
|
|
|
|
|
|
hash_form = {
|
|
|
|
"hash" : hash
|
|
|
|
};
|
|
|
|
|
|
|
|
var hash_data = JSON.stringify(hash_form);
|
|
|
|
|
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
|
|
if (this.readyState == 4 && (this.status == 200 || this.status == 400 || this.status == 500)) {
|
|
|
|
try {
|
|
|
|
var result= JSON.parse(this.responseText);
|
|
|
|
} catch(error) {
|
|
|
|
document.getElementById('stats').innerHTML = "API response can't be parsed.";
|
|
|
|
reset_button();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(result.error) {
|
|
|
|
document.getElementById('stats').innerHTML = '<p>' + result.message + '</p><img id="bored_image" src="assets/img/bored.svg" style="width: 10em; height: 10em; display:block; margin: 1em auto;">';
|
|
|
|
} else {
|
|
|
|
results = result.data;
|
2022-01-11 13:33:30 +00:00
|
|
|
functions = result.functions;
|
|
|
|
load_page();
|
2021-12-12 16:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhttp.withCredentials = true;
|
|
|
|
xhttp.open("post", "api/get_link.php");
|
|
|
|
xhttp.send(hash_data);
|
|
|
|
}
|
2020-12-19 16:10:59 +00:00
|
|
|
|
2021-12-12 16:31:15 +00:00
|
|
|
function sign_out() {
|
2022-01-11 13:33:30 +00:00
|
|
|
set_cookie("wrapperr-user", "", 1);
|
2021-12-12 16:31:15 +00:00
|
|
|
document.getElementById('search_wrapped_form').style.display = 'none';
|
|
|
|
document.getElementById('plex_login_form').style.display = 'block';
|
|
|
|
document.getElementById("plex_login_button").disabled = false;
|
|
|
|
document.getElementById("plex_login_button").style.opacity = '1';
|
|
|
|
document.getElementById("search_wrapped_button").disabled = true;
|
|
|
|
document.getElementById("search_wrapped_button").style.opacity = '0.5';
|
|
|
|
document.getElementById('sign_out_div').style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).on('submit', '#search_wrapped_form', function(){
|
|
|
|
|
|
|
|
document.getElementById("search_wrapped_button").disabled = true;
|
|
|
|
document.getElementById("search_wrapped_button").style.opacity = '0.5';
|
|
|
|
document.getElementById("plex_signout_button").disabled = true;
|
|
|
|
document.getElementById("plex_signout_button").style.opacity = '0.5';
|
2021-03-09 15:22:41 +00:00
|
|
|
document.getElementById('results_error').innerHTML = "";
|
2021-03-08 18:45:06 +00:00
|
|
|
get_functions();
|
2020-12-19 16:10:59 +00:00
|
|
|
|
|
|
|
});
|
2021-12-12 16:31:15 +00:00
|
|
|
|
|
|
|
$(document).on('submit', '#plex_login_form', function(){
|
|
|
|
|
|
|
|
window_url = window.location.href.split('?')[0];
|
|
|
|
|
2022-01-11 13:33:30 +00:00
|
|
|
auth_form = {
|
|
|
|
"home_url" : window_url
|
|
|
|
};
|
2021-12-12 16:31:15 +00:00
|
|
|
|
|
|
|
var auth_data = JSON.stringify(auth_form);
|
|
|
|
|
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
|
|
if (this.readyState == 4 && (this.status == 200 || this.status == 400 || this.status == 500)) {
|
|
|
|
try {
|
|
|
|
var result= JSON.parse(this.responseText);
|
|
|
|
document.getElementById('snowflakes').style.display = 'none';
|
|
|
|
} catch(error) {
|
|
|
|
document.getElementById('results_error').innerHTML = "API response can't be parsed.";
|
|
|
|
}
|
2022-01-11 13:33:30 +00:00
|
|
|
|
|
|
|
//console.log(result);
|
|
|
|
|
2021-12-12 16:31:15 +00:00
|
|
|
if(result.error) {
|
|
|
|
document.getElementById('results_error').innerHTML = result.message;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
pop_up_login(result.url, result.code, result.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhttp.withCredentials = true;
|
|
|
|
xhttp.open("post", "api/get_login_url.php");
|
|
|
|
xhttp.send(auth_data);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
function pop_up_login(url, code, id) {
|
|
|
|
|
|
|
|
document.getElementById('plex_login_button_text').innerHTML = 'Loading...';
|
|
|
|
document.getElementById("plex_login_button").disabled = true;
|
|
|
|
document.getElementById("plex_login_button").style.opacity = '0.5';
|
|
|
|
|
|
|
|
const openedWindow = window.open(
|
|
|
|
url,
|
|
|
|
"Plex Login",
|
2022-01-11 13:33:30 +00:00
|
|
|
"width=500,height=750,resizable,scrollbars,popup=yes"
|
2021-12-12 16:31:15 +00:00
|
|
|
);
|
|
|
|
|
2022-01-11 13:33:30 +00:00
|
|
|
if (openedWindow == null || typeof(openedWindow)=='undefined') {
|
|
|
|
alert("Failed to open login window. Your browser might be blocking pop-up windows.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-12 16:31:15 +00:00
|
|
|
var timer = setInterval(function() {
|
|
|
|
if(openedWindow.closed) {
|
|
|
|
|
|
|
|
check_token(code, id);
|
|
|
|
|
|
|
|
clearInterval(timer);
|
|
|
|
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_token(code, id) {
|
|
|
|
|
|
|
|
auth_form = {
|
|
|
|
"code" : code,
|
|
|
|
"id" : id
|
|
|
|
};
|
|
|
|
|
|
|
|
var auth_data = JSON.stringify(auth_form);
|
|
|
|
|
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
|
|
if (this.readyState == 4 && (this.status == 200 || this.status == 400 || this.status == 500)) {
|
|
|
|
try {
|
|
|
|
var result= JSON.parse(this.responseText);
|
|
|
|
} catch(error) {
|
|
|
|
document.getElementById('results_error').innerHTML = "API response can't be parsed.";
|
2022-01-11 13:33:30 +00:00
|
|
|
console.log('API response can\'t be parsed. Error: ' + this.responseText)
|
2021-12-12 16:31:15 +00:00
|
|
|
reset_button();
|
|
|
|
}
|
|
|
|
|
2022-01-11 13:33:30 +00:00
|
|
|
//console.log(result);
|
|
|
|
|
2021-12-12 16:31:15 +00:00
|
|
|
if(result.error) {
|
|
|
|
reset_button();
|
|
|
|
} else {
|
2022-01-11 13:33:30 +00:00
|
|
|
set_cookie("wrapperr-user", result.cookie, 1);
|
2021-12-12 16:31:15 +00:00
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhttp.withCredentials = true;
|
|
|
|
xhttp.open("post", "api/get_login_cookie.php");
|
|
|
|
xhttp.send(auth_data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset_button() {
|
|
|
|
document.getElementById('plex_login_button_text').innerHTML = 'Sign in using Plex';
|
|
|
|
document.getElementById("plex_login_button").disabled = false;
|
|
|
|
document.getElementById("plex_login_button").style.opacity = '1';
|
|
|
|
}
|
|
|
|
|
2022-01-11 13:33:30 +00:00
|
|
|
function validate_cookie_user(cookie) {
|
2021-12-12 16:31:15 +00:00
|
|
|
var json_cookie = JSON.stringify({"cookie": cookie});
|
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
var result= JSON.parse(this.responseText);
|
|
|
|
} catch(error) {
|
|
|
|
document.getElementById('results_error').innerHTML = "API response can't be parsed.";
|
|
|
|
reset_button();
|
|
|
|
}
|
|
|
|
|
2022-01-11 13:33:30 +00:00
|
|
|
//console.log(result);
|
|
|
|
|
2021-12-12 16:31:15 +00:00
|
|
|
if(result.error) {
|
2022-01-11 13:33:30 +00:00
|
|
|
set_cookie("wrapperr-user", "", 1);
|
2021-12-12 16:31:15 +00:00
|
|
|
document.getElementById('search_wrapped_form').style.display = 'none';
|
|
|
|
document.getElementById('sign_out_div').style.display = 'none';
|
|
|
|
document.getElementById('plex_login_form').style.display = 'block';
|
|
|
|
} else {
|
|
|
|
document.getElementById("plex_login_button").disabled = true;
|
|
|
|
document.getElementById("plex_login_button").style.opacity = '0.5';
|
|
|
|
document.getElementById("search_wrapped_button").disabled = false;
|
|
|
|
document.getElementById("search_wrapped_button").style.opacity = '1';
|
2022-01-11 13:33:30 +00:00
|
|
|
get_user_links(cookie);
|
2021-12-12 16:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhttp.withCredentials = true;
|
|
|
|
xhttp.open("post", "api/validate_login_cookie.php");
|
|
|
|
xhttp.send(json_cookie);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-11 13:33:30 +00:00
|
|
|
function get_user_links(cookie) {
|
|
|
|
cookie_form = {
|
|
|
|
"cookie" : cookie
|
|
|
|
};
|
|
|
|
|
|
|
|
var cookie_data = JSON.stringify(cookie_form);
|
2021-12-12 16:31:15 +00:00
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
var result= JSON.parse(this.responseText);
|
|
|
|
} catch(error) {
|
2022-01-11 13:33:30 +00:00
|
|
|
console.log('Failed to parse Wrapperr links. Response: ' + this.responseText)
|
2021-12-12 16:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!result.error) {
|
2022-01-11 13:33:30 +00:00
|
|
|
for(var i = 0; i < result.links.length; i++) {
|
|
|
|
document.getElementById('share_wrapped_url').innerHTML = window.location.href.split('?')[0] + '?hash=' + result.links[i].url_hash;
|
|
|
|
document.getElementById('share_wrapped_title_div').style.display = 'block';
|
|
|
|
document.getElementById('share_wrapped_div').style.display = 'flex';
|
|
|
|
}
|
2021-12-12 16:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhttp.withCredentials = true;
|
2022-01-11 13:33:30 +00:00
|
|
|
xhttp.open("post", "api/get_link_user.php");
|
|
|
|
xhttp.send(cookie_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_wrapper_version() {
|
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
var result= JSON.parse(this.responseText);
|
|
|
|
} catch(error) {
|
|
|
|
console.log('Failed to parse Wrapperr version. Response: ' + this.responseText)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!result.error) {
|
|
|
|
document.getElementById('github_link').innerHTML = 'GitHub (' + result.wrapperr_version + ')';
|
|
|
|
|
|
|
|
if(result.application_name && result.application_name !== '' && !link_mode) {
|
|
|
|
document.getElementById('application_name').innerHTML = result.application_name;
|
|
|
|
document.title = result.application_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhttp.withCredentials = true;
|
|
|
|
xhttp.open("post", "api/get_wrapperr_version.php");
|
2021-12-12 16:31:15 +00:00
|
|
|
xhttp.send();
|
|
|
|
return;
|
2022-01-11 13:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function copy_link_user() {
|
|
|
|
window.open(document.getElementById('share_wrapped_url').innerHTML, '_blank').focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_link_user() {
|
|
|
|
|
|
|
|
if(!confirm('Are you sure you want to delete this link?')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cookie_form = {
|
|
|
|
"cookie" : cookie
|
|
|
|
};
|
|
|
|
|
|
|
|
var cookie_data = JSON.stringify(cookie_form);
|
|
|
|
var xhttp = new XMLHttpRequest();
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
|
|
if (this.readyState == 4 && this.status == 200) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
var result= JSON.parse(this.responseText);
|
|
|
|
} catch(error) {
|
|
|
|
console.log('Failed to parse Wrapperr response. Response: ' + this.responseText)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!result.error) {
|
|
|
|
document.getElementById('share_wrapped_title_div').style.display = 'none';
|
|
|
|
document.getElementById('share_wrapped_div').style.display = 'none';
|
|
|
|
} else {
|
|
|
|
console.log(result.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhttp.withCredentials = true;
|
|
|
|
xhttp.open("post", "api/delete_link_user.php");
|
|
|
|
xhttp.send(cookie_data);
|
|
|
|
return;
|
2021-12-12 16:31:15 +00:00
|
|
|
}
|