some minor improvements \\ enough work for today

This commit is contained in:
2024-02-14 00:02:35 +01:00
parent 512ef3b357
commit 9ca119e4df
14 changed files with 233 additions and 119 deletions

View File

@@ -1,81 +0,0 @@
// /\_/|
// { ' ' } JellyCAT
// \____\
//----------------------------DOMView--------------------------------------------
var JCATAboutXML = '<?xml version="1.0" encoding="UTF-8"?>\n' +
'<atv>\n' +
' <head>\n' +
' </head>\n' +
' <body>\n' +
' <scrollingText id="com.jellycat.jcatabout" initialSelection="1">\n' +
' <title>JellyCAT About</title>\n' +
' <text><![CDATA[\n' +
'// /\\_/ |\n' +
'// { \' \' } JellyCAT\n' +
'// \\____\\\n' +
'\n' +
'ENGLISH | ABOUT\n' +
' \n' +
'JellyCAT $atvcsettings.version\n' +
' \n' +
'Thank you for using JellyCAT! A (hacky) Jellyfin client for Apple TV 2 & 3.\n' +
' \n' +
'== soon more ==\n' +
' \n' +
'\n\n\n' +
'-=JellyCAT Server (JCHOST) Information=-\n' +
'\n\n' +
'JellyCAT Server Host (fallback):\n' +
'http://jcathost.dns\n' +
'\n' +
'ATVCSETTINGS pick-up location:\n' +
'http://jcathost.dns/atvcsettings\n' +
'\n' +
'ATVCSETTINGS Hello:\n' +
'$atvcsettings.hello\n' +
'\n' +
'ATVCSETTINGS System Information:\n' +
'$atvcsettings.system\n' +
'\n' +
'JellyCat Version:\n' +
'$atvcsettings.version\n' +
'\n' +
'Hijacked Host App domain\n' +
'$atvcsettings.sighost\n' +
'\n' +
'JellyCAT Server Host IP\n' +
'$atvcsettings.hostip\n' +
'\n' +
'-=Jellyfin Client settings=-\n' +
' ]]></text>\n' +
' <buttons>\n' +
' <actionButton onSelect="DomViewManager.unloadView(\'JcatAboutView\');" id="close">\n' +
' <title>Close</title>\n' +
' </actionButton>\n' +
' </buttons>\n' +
' </scrollingText>\n' +
' </body>\n' +
'</atv>';
JCATAboutXML = JCATAboutXML
.replace(/\$atvcsettings\.hello/g, atv.jcathost.HelloMessage)
.replace(/\$atvcsettings\.system/g, atv.jcathost.System)
.replace(/\$atvcsettings\.version/g, atv.jcathost.Version)
.replace(/\$atvcsettings\.sighost/g, atv.jcathost.SigHost)
.replace(/\$atvcsettings\.hostip/g, atv.jcathost.HostIP);
function generateJCATAboutXML() {
var doc = atv.parseXML( JCATAboutXML );
console.log( "Creating the view --> " );
DomViewManager.createView( "JcatAboutView" );
console.log( "Loading the view --> " );
DomViewManager.loadView( "JcatAboutView", doc );
console.log( "View is loaded" );
}

View File

@@ -7,6 +7,7 @@
var JCATHOSTInfoXML = '<?xml version="1.0" encoding="UTF-8"?>\n' +
'<atv>\n' +
' <head>\n' +
' <script src="http://jcathost.dns/js/settingloader.js"/>\n' +
' </head>\n' +
' <body>\n' +
' <scrollingText id="com.jellycat.jcathostinfo" initialSelection="1">\n' +
@@ -42,7 +43,7 @@ var JCATHOSTInfoXML = '<?xml version="1.0" encoding="UTF-8"?>\n' +
'$atvcsettings.hostip\n' +
']]></text>\n' +
' <buttons>\n' +
' <actionButton onSelect="generateJCATAboutXML();" id="about">\n' +
' <actionButton onSelect="loadAbout();" id="about">\n' +
' <title>About</title>\n' +
' </actionButton>\n' +
' <actionButton onSelect="DomViewManager.unloadView(\'JcathostInfoView\');" id="close">\n' +
@@ -71,4 +72,6 @@ function generateJCATHOSTInfoXML() {
DomViewManager.loadView( "JcathostInfoView", doc );
console.log( "View is loaded" );
}
}
// I will keep this DomView generator for reference, however I like my new way of templating better

View File

@@ -946,5 +946,65 @@ var DomViewManager = ( function() {
// ------ End DOM View Manager --------
// ***************************************************
// Extra's
// PlexConnect ATV UTILS
// https://github.com/iBaa/PlexConnect/blob/master/assets/js/utils.js
// Some
// atv.Document extensions
if( atv.Document ) {
atv.Document.prototype.getElementById = function(id) {
var elements = this.evaluateXPath("//*[@id='" + id + "']", this);
if ( elements && elements.length > 0 ) {
return elements[0];
}
return undefined;
}
}
// atv.Element extensions
if( atv.Element ) {
atv.Element.prototype.getElementsByTagName = function(tagName) {
return this.ownerDocument.evaluateXPath("descendant::" + tagName, this);
}
atv.Element.prototype.getElementByTagName = function(tagName) {
var elements = this.getElementsByTagName(tagName);
if ( elements && elements.length > 0 ) {
return elements[0];
}
return undefined;
}
}
// string extension: format()
// see http://stackoverflow.com/a/4673436
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined' ? args[number] : match;
});
};
}
// Always love a good hack haha!
/*
* xml updater Major Hack :)
*/
function updateContextXML()
{
xmlstr = '<atv><body><optionList id="fakeUpdater" autoSelectSingleItem="true"> \
<items><oneLineMenuItem id="0" onSelect="atv.unloadPage()"><label></label> \
</oneLineMenuItem></items></optionList></body></atv>';
xmlDoc = atv.parseXML(xmlstr);
atv.loadXML(xmlDoc);
}
console.log('Reached EOF!');

View File

@@ -27,9 +27,10 @@ function setServerAddress() {
function(value) {
// Save server address to localStorage
atv.localStorage['jellyfin_server_address'] = value;
fetchDataAndRender();
},
function() {
fetchDataAndRender();
},
atv.localStorage['jellyfin_server_address'] || ""
);
@@ -44,9 +45,10 @@ function setUsername() {
function(value) {
// Save username to localStorage
atv.localStorage['jellyfin_username'] = value;
fetchDataAndRender();
},
function() {
fetchDataAndRender();
},
atv.localStorage['jellyfin_username'] || ""
);
@@ -61,10 +63,30 @@ function setPassword() {
function(value) {
// Save password to localStorage
atv.localStorage['jellyfin_password'] = value;
fetchDataAndRender();
},
function() {
fetchDataAndRender();
},
atv.localStorage['jellyfin_password'] || ""
);
}
// Let's try finding and changing the values
function fetchDataAndRender() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var xmlstr = xhttp.responseText;
var serverAddress = atv.localStorage['jellyfin_server_address'];
var username = atv.localStorage['jellyfin_username'];
var modifiedXml = xmlstr.replace(/\$server_address/g, serverAddress).replace(/\$username/g, username);
var xmlDoc = atv.parseXML(modifiedXml);
atv.loadAndSwapXML(xmlDoc);
}
};
xhttp.open("GET", 'https://' + atv.jcathost.SigHost + '/xml/server-settings.xml', true);
xhttp.send();
}

42
app/js/settingloader.js Normal file
View File

@@ -0,0 +1,42 @@
// /\_/|
// { ' ' } JellyCAT
// \____\
function loadServerSettings(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var xmlstr = xhttp.responseText;
var serverAddress = atv.localStorage['jellyfin_server_address'];
var username = atv.localStorage['jellyfin_username'];
var modifiedXml = xmlstr.replace(/\$server_address/g, serverAddress).replace(/\$username/g, username);
var xmlDoc = atv.parseXML(modifiedXml);
atv.loadXML(xmlDoc);
}
};
xhttp.open("GET", 'https://' + atv.jcathost.SigHost + '/xml/server-settings.xml', true);
xhttp.send();
}
function loadAbout(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var xmlstr = xhttp.responseText;
var serverAddress = atv.localStorage['jellyfin_server_address'];
var username = atv.localStorage['jellyfin_username'];
var modifiedXml = xmlstr
.replace(/\$server_address/g, serverAddress)
.replace(/\$username/g, username)
.replace(/\$atvcsettings\.hello/g, atv.jcathost.HelloMessage)
.replace(/\$atvcsettings\.system/g, atv.jcathost.System)
.replace(/\$atvcsettings\.version/g, atv.jcathost.Version)
.replace(/\$atvcsettings\.sighost/g, atv.jcathost.SigHost)
.replace(/\$atvcsettings\.hostip/g, atv.jcathost.HostIP);
var xmlDoc = atv.parseXML(modifiedXml);
atv.loadXML(xmlDoc);
}
};
xhttp.open("GET", 'https://' + atv.jcathost.SigHost + '/xml/about.xml', true);
xhttp.send();
}