mirror of
https://github.com/JasonHHouse/gaps.git
synced 2026-05-21 00:39:43 -05:00
Changing to use cookie js instead of direct document.cookie
This commit is contained in:
@@ -109,6 +109,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
|
||||
<script type="text/javascript" src="js/materialize.min.js"></script>
|
||||
<script type="text/javascript" src="js/js.cookie.min.js"></script>
|
||||
<script type="text/javascript" src="js/index.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -14,16 +14,7 @@ function onStart() {
|
||||
|
||||
$("#plex").click(function () {
|
||||
if (validateInput()) {
|
||||
let obj;
|
||||
try {
|
||||
obj = JSON.parse(document.cookie);
|
||||
} catch (e) {
|
||||
obj = {};
|
||||
}
|
||||
|
||||
obj.movie_db_api_key = $("#movie_db_api_key").val();
|
||||
document.cookie = JSON.stringify(obj);
|
||||
|
||||
Cookies.set('movie_db_api_key', $("#movie_db_api_key").val());
|
||||
location.assign("plex_configuration.html");
|
||||
}
|
||||
});
|
||||
@@ -37,14 +28,10 @@ function onStart() {
|
||||
|
||||
function populateCookieValues() {
|
||||
if (document.cookie) {
|
||||
try {
|
||||
let obj = JSON.parse(document.cookie);
|
||||
const movieDbApiKey = Cookies.get('movie_db_api_key');
|
||||
|
||||
if (obj.movie_db_api_key) {
|
||||
$("#movie_db_api_key").val(obj.movie_db_api_key);
|
||||
}
|
||||
} catch (e) {
|
||||
//Nothing, no cookie
|
||||
if (movieDbApiKey) {
|
||||
$("#movie_db_api_key").val(movieDbApiKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/*! js-cookie v3.0.0-beta.0 | MIT */
|
||||
;
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, (function () {
|
||||
var current = global.Cookies;
|
||||
var exports = global.Cookies = factory();
|
||||
exports.noConflict = function () { global.Cookies = current; return exports; };
|
||||
}()));
|
||||
}(this, function () { 'use strict';
|
||||
|
||||
function extend () {
|
||||
var result = {};
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var attributes = arguments[i];
|
||||
for (var key in attributes) {
|
||||
result[key] = attributes[key];
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function decode (s) {
|
||||
return s.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
|
||||
}
|
||||
|
||||
function init (converter) {
|
||||
function set (key, value, attributes) {
|
||||
if (typeof document === 'undefined') {
|
||||
return
|
||||
}
|
||||
|
||||
attributes = extend(api.defaults, attributes);
|
||||
|
||||
if (typeof attributes.expires === 'number') {
|
||||
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e5);
|
||||
}
|
||||
if (attributes.expires) {
|
||||
attributes.expires = attributes.expires.toUTCString();
|
||||
}
|
||||
|
||||
value = converter.write
|
||||
? converter.write(value, key)
|
||||
: encodeURIComponent(String(value)).replace(
|
||||
/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,
|
||||
decodeURIComponent
|
||||
);
|
||||
|
||||
key = encodeURIComponent(String(key))
|
||||
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
|
||||
.replace(/[()]/g, escape);
|
||||
|
||||
var stringifiedAttributes = '';
|
||||
for (var attributeName in attributes) {
|
||||
if (!attributes[attributeName]) {
|
||||
continue
|
||||
}
|
||||
stringifiedAttributes += '; ' + attributeName;
|
||||
if (attributes[attributeName] === true) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Considers RFC 6265 section 5.2:
|
||||
// ...
|
||||
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
||||
// character:
|
||||
// Consume the characters of the unparsed-attributes up to,
|
||||
// not including, the first %x3B (";") character.
|
||||
// ...
|
||||
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
||||
}
|
||||
|
||||
return (document.cookie = key + '=' + value + stringifiedAttributes)
|
||||
}
|
||||
|
||||
function get (key) {
|
||||
if (typeof document === 'undefined' || (arguments.length && !key)) {
|
||||
return
|
||||
}
|
||||
|
||||
// To prevent the for loop in the first place assign an empty array
|
||||
// in case there are no cookies at all.
|
||||
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
||||
var jar = {};
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var parts = cookies[i].split('=');
|
||||
var cookie = parts.slice(1).join('=');
|
||||
|
||||
if (cookie.charAt(0) === '"') {
|
||||
cookie = cookie.slice(1, -1);
|
||||
}
|
||||
|
||||
try {
|
||||
var name = decode(parts[0]);
|
||||
jar[name] =
|
||||
(converter.read || converter)(cookie, name) || decode(cookie);
|
||||
|
||||
if (key === name) {
|
||||
break
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
return key ? jar[key] : jar
|
||||
}
|
||||
|
||||
var api = {
|
||||
defaults: {
|
||||
path: '/'
|
||||
},
|
||||
set: set,
|
||||
get: get,
|
||||
remove: function (key, attributes) {
|
||||
set(
|
||||
key,
|
||||
'',
|
||||
extend(attributes, {
|
||||
expires: -1
|
||||
})
|
||||
);
|
||||
},
|
||||
withConverter: init
|
||||
};
|
||||
|
||||
return api
|
||||
}
|
||||
|
||||
var js_cookie = init(function () {});
|
||||
|
||||
return js_cookie;
|
||||
|
||||
}));
|
||||
@@ -0,0 +1,2 @@
|
||||
/*! js-cookie v3.0.0-beta.0 | MIT */
|
||||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self,function(){var t=e.Cookies,o=e.Cookies=n();o.noConflict=function(){return e.Cookies=t,o}}())}(this,function(){"use strict";function e(){for(var e={},n=0;n<arguments.length;n++){var t=arguments[n];for(var o in t)e[o]=t[o]}return e}function n(e){return e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)}return function t(o){function r(n,t,r){if("undefined"!=typeof document){"number"==typeof(r=e(i.defaults,r)).expires&&(r.expires=new Date(1*new Date+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=o.write?o.write(t,n):encodeURIComponent(String(t)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),n=encodeURIComponent(String(n)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var f in r)r[f]&&(c+="; "+f,!0!==r[f]&&(c+="="+r[f].split(";")[0]));return document.cookie=n+"="+t+c}}var i={defaults:{path:"/"},set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],r={},i=0;i<t.length;i++){var c=t[i].split("="),f=c.slice(1).join("=");'"'===f.charAt(0)&&(f=f.slice(1,-1));try{var u=n(c[0]);if(r[u]=(o.read||o)(f,u)||n(f),e===u)break}catch(e){}}return e?r[e]:r}},remove:function(n,t){r(n,"",e(t,{expires:-1}))},withConverter:t};return i}(function(){})});
|
||||
@@ -17,21 +17,9 @@ function onStart() {
|
||||
|
||||
$("#next").click(function () {
|
||||
if (validateInput()) {
|
||||
let obj;
|
||||
try {
|
||||
obj = JSON.parse(document.cookie);
|
||||
} catch (e) {
|
||||
const errorMessage = "Missing cookie information for address, port, and token";
|
||||
M.toast({html: errorMessage});
|
||||
Console.error(errorMessage);
|
||||
obj = {};
|
||||
}
|
||||
|
||||
obj.address = $('#address').val();
|
||||
obj.port = $('#port').val();
|
||||
obj.plex_token = $('#plex_token').val();
|
||||
|
||||
document.cookie = JSON.stringify(obj);
|
||||
Cookies.set('address', $("#address").val());
|
||||
Cookies.set('port', $("#port").val());
|
||||
Cookies.set('plex_token', $("#plex_token").val());
|
||||
|
||||
location.assign("plex_libraries.html");
|
||||
}
|
||||
@@ -44,20 +32,20 @@ function onStart() {
|
||||
}
|
||||
|
||||
function populateCookieValues() {
|
||||
if (document.cookie) {
|
||||
let obj = JSON.parse(document.cookie);
|
||||
const address = Cookies.get('address');
|
||||
const port = Cookies.get('port');
|
||||
const plexToken = Cookies.get('plex_token');
|
||||
|
||||
if (obj.address) {
|
||||
$('#address').val(obj.address);
|
||||
}
|
||||
if (address) {
|
||||
$('#address').val(address);
|
||||
}
|
||||
|
||||
if (obj.port) {
|
||||
$('#port').val(obj.port);
|
||||
}
|
||||
if (port) {
|
||||
$('#port').val(port);
|
||||
}
|
||||
|
||||
if (obj.plex_token) {
|
||||
$('#plex_token').val(obj.plex_token);
|
||||
}
|
||||
if (plexToken) {
|
||||
$('#plex_token').val(plexToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,7 @@ function onStart() {
|
||||
});
|
||||
|
||||
$("#search").click(function () {
|
||||
let obj = JSON.parse(document.cookie);
|
||||
|
||||
if (!obj.dialogDontShowAgain) {
|
||||
if (Cookies.get('dialogDontShowAgain')) {
|
||||
if (validateInput()) {
|
||||
$("#warningModal").modal("open");
|
||||
|
||||
@@ -35,9 +33,7 @@ function onStart() {
|
||||
|
||||
$("#agree").click(function () {
|
||||
if (validateInput()) {
|
||||
let obj = JSON.parse(document.cookie);
|
||||
obj.dialogDontShowAgain = $("#dialogDontShowAgain").is(":checked");
|
||||
document.cookie = JSON.stringify(obj);
|
||||
Cookies.set('dialogDontShowAgain', $("#dialogDontShowAgain").is(":checked"));
|
||||
updatedSelectedLibraries();
|
||||
location.assign("plex_movie_list.html");
|
||||
}
|
||||
@@ -74,23 +70,21 @@ function clearLibrariesAndErrors() {
|
||||
}
|
||||
|
||||
function getLibraries() {
|
||||
|
||||
setSearchEnabled(false);
|
||||
clearLibrariesAndErrors();
|
||||
|
||||
let obj = JSON.parse(document.cookie);
|
||||
let token = obj.plex_token;
|
||||
let port = obj.port;
|
||||
let address = obj.address;
|
||||
const address = Cookies.get('address');
|
||||
const port = Cookies.get('port');
|
||||
const plexToken = Cookies.get('plex_token');
|
||||
|
||||
if (!token || !port || !address) {
|
||||
if (!plexToken || !port || !address) {
|
||||
console.warn("Could not find plex token, port, or address in cookies");
|
||||
M.toast({html: "Could not find plex token, port, or address in cookies"});
|
||||
return;
|
||||
}
|
||||
|
||||
let data = {
|
||||
token: token,
|
||||
token: plexToken,
|
||||
port: port,
|
||||
address: address
|
||||
};
|
||||
@@ -135,8 +129,7 @@ function setErrorMessage() {
|
||||
}
|
||||
|
||||
function generateLibrariesCheckbox() {
|
||||
let obj = JSON.parse(document.cookie);
|
||||
let selectedLibraries = obj.libraries || [];
|
||||
const selectedLibraries = Cookies.get('libraries') || [];
|
||||
|
||||
let row = "";
|
||||
for (const library of allLibraries) {
|
||||
@@ -157,9 +150,7 @@ function findIfChecked(selectedLibraries, key) {
|
||||
}
|
||||
|
||||
function updatedSelectedLibraries() {
|
||||
let obj = JSON.parse(document.cookie);
|
||||
obj.libraries = findSelectedLibraries();
|
||||
document.cookie = JSON.stringify(obj);
|
||||
Cookies.set('libraries', findSelectedLibraries());
|
||||
}
|
||||
|
||||
function findSelectedLibraries() {
|
||||
|
||||
@@ -79,21 +79,25 @@ function search() {
|
||||
searchTitle.text("Searching for Movies...");
|
||||
searchDescription.text("Gaps is looking through your Plex libraries. This could take a while so just sit tight and we'll find all the missing movies for you.");
|
||||
|
||||
let obj = JSON.parse(document.cookie);
|
||||
const libraries = Cookies.get('libraries');
|
||||
const address = Cookies.get('address');
|
||||
const port = Cookies.get('port');
|
||||
const plexToken = Cookies.get('plex_token');
|
||||
const movieDbApiKey = Cookies.get('movie_db_api_key');
|
||||
|
||||
let plexMovieUrls = [];
|
||||
|
||||
for (let library of obj.libraries) {
|
||||
for (let library of libraries) {
|
||||
let data = {
|
||||
'X-Plex-Token': obj.plex_token
|
||||
'X-Plex-Token': plexToken
|
||||
};
|
||||
|
||||
let plexMovieUrl = "http://" + obj.address + ":" + obj.port + "/library/sections/" + library.key + "/all/?" + encodeQueryData(data);
|
||||
let plexMovieUrl = "http://" + address + ":" + port + "/library/sections/" + library.key + "/all/?" + encodeQueryData(data);
|
||||
plexMovieUrls.push(plexMovieUrl);
|
||||
}
|
||||
|
||||
const gaps = {
|
||||
movieDbApiKey: obj.movie_db_api_key,
|
||||
movieDbApiKey: movieDbApiKey,
|
||||
writeToFile: true,
|
||||
searchFromPlex: true,
|
||||
movieUrls: plexMovieUrls
|
||||
|
||||
@@ -151,6 +151,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
|
||||
<script type="text/javascript" src="js/materialize.min.js"></script>
|
||||
<script type="text/javascript" src="js/js.cookie.min.js"></script>
|
||||
<script type="text/javascript" src="js/plex_configuration.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -133,6 +133,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
|
||||
<script type="text/javascript" src="js/materialize.min.js"></script>
|
||||
<script type="text/javascript" src="js/js.cookie.min.js"></script>
|
||||
<script type="text/javascript" src="js/plex_libraries.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -117,6 +117,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
|
||||
<script type="text/javascript" src="js/materialize.min.js"></script>
|
||||
<script type="text/javascript" src="js/js.cookie.min.js"></script>
|
||||
<script type="text/javascript" src="js/sockjs-1.4.0.min.js"></script>
|
||||
<script type="text/javascript" src="js/stomp-2.3.3.min.js"></script>
|
||||
<script type="text/javascript" src="js/plex_movie_list.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user