Skip to content

Commit

Permalink
feat: fetch previous settings from stremio configure
Browse files Browse the repository at this point in the history
  • Loading branch information
xick authored Jul 22, 2024
1 parent ff27f31 commit b42f4fb
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion comet/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,15 @@
document.body.classList.add("ready");
defaultLanguages = webConfig.languages;
defaultResolutions = webConfig.resolutions;

// try populate the form from previous settings
try {
const settings = getSettingsFromUrl();
if (settings != null) { populateFormFromSettings(settings); }
} catch (error) {
console.log("Failed to retrieve or parse settings from URL:", error);
}

});

function populateSelect(selectId, options) {
Expand Down Expand Up @@ -668,8 +677,35 @@
console.log(settingsString);
installAlert.toast();
});

function getSettingsFromUrl() {
const url = window.location.href;
// Try parse settings from the URL
if (url.split('/').length < 5) {
console.log("no previous settings"); return null;
}
const settingsString = url.split('/')[3];
if (typeof settingsString === 'undefined') {
console.log("can't fetch previous settings", settingsString)
return null;
}
const settingsJson = atob(settingsString);
return JSON.parse(settingsJson);
}

function populateFormFromSettings(settings) {
document.getElementById("maxResults").value = settings.maxResults;
document.getElementById("maxSize").value = settings.maxSize / 1073741824; // Convert back from bytes to GB
document.getElementById("debridService").value = settings.debridService;
document.getElementById("debridApiKey").value = settings.debridApiKey;
document.getElementById("debridStreamProxyPassword").value = settings.debridStreamProxyPassword;
document.getElementById("indexers").value = settings.indexers;
document.getElementById("languages").value = settings.languages;
document.getElementById("resolutions").value = settings.resolutions;
}

</script>
</div>
</div>
</body>
</html>
</html>

0 comments on commit b42f4fb

Please sign in to comment.