// ==UserScript==
// @name Evolve Idle Cloud Save
// @namespace https://github.com/Alistair1231/my-userscripts/
// @version 1.2.1
// @description Automatically upload your evolve save to a gist
// @author Alistair1231
// @match https://pmotschmann.github.io/Evolve/
// @icon https://icons.duckduckgo.com/ip2/github.io.ico
// @license GPL-3.0
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.deleteValue
// @grant GM.listValues
// @grant GM.addStyle
// @grant GM.xmlHttpRequest
// @require https://cdn.jsdelivr.net/gh/Alistair1231/my-userscripts@5b9e5e7ee0169de3181ceab0332b390dab39c4d8/lib.js
// @require https://cdn.jsdelivr.net/npm/@trim21/gm-fetch@0.2.1
// @downloadURL none
// ==/UserScript==
// https://greasyfork.org/en/scripts/490376-automatic-evolve-save-upload-to-gist
// https://github.com/Alistair1231/my-userscripts/raw/master/EvolveIdleSavegameBackup.user.js
/*
# Evolve Idle Cloud Save
I lost my save game 😞, so I created a quick backup solution using GitHub Gist to store save data.
### Key Features:
- **Automatic Upload:** On first use, you'll be prompted to enter your Gist ID and Personal Access Token. These credentials are stored as plain text in the Userscript storage. The token must have the `gist` scope.
- **Manual Setup:** You need to manually create the Gist and enter its ID in the settings.
- **Export Settings:** Saves are exported to the filename specified in the settings.
- **Import Flexibility:** Import your save from any file in the Gist, making it easy to restore data after switching devices or PCs.
- **Backup Options:**
- Automatic backups are performed every 15 minutes.
- Manual backups can be triggered by clicking the "Save to" button.
- **Advanced Use:** The `evolveCloudSave` object is exposed to the window, allowing for manual interaction.
With this setup, your progress is secure, and you can easily transfer your saves between devices.

*/
;(async function () {
'use strict'
const evolveCloudSave = {
// Create an overlay to collect secrets from the user
openSettings: () => {
const saveSettings = () => {
const gistId = document.getElementById('gist_id').value.trim()
const token = document.getElementById('gist_token').value.trim()
const frequency =
document.getElementById('save_frequency').value.trim() || '15'
const filename =
document.getElementById('file_name').value.trim() || 'save.txt'
if (!gistId || !token) {
alert('Gist ID and Token are required!')
return
}
lib.settings.gistId = gistId
lib.settings.token = token
lib.settings.filename = filename
lib.settings.frequency = frequency
document.body.removeChild(overlay)
}
const fillCurrentSettings = async () => {
document.getElementById('gist_id').value =
(await lib.settings.gistId) || ''
document.getElementById('gist_token').value =
(await lib.settings.token) || ''
document.getElementById('file_name').value =
(await lib.settings.filename) || 'save.txt'
document.getElementById('save_frequency').value =
(await lib.settings.frequency) || '15'
}
let overlay = document.createElement('div')
overlay.innerHTML = `
You will need a GistID and a Personal Access Token to use this cloud-save script. They will be saved as
cleartext in the Userscript storage!