// ==UserScript==
// @name Dreadcast Script Manager
// @namespace Violentmonkey Scripts
// @match https://www.dreadcast.net/Main
// @match https://www.dreadcast.net/Forum
// @match https://www.dreadcast.net/Forum/*
// @match https://www.dreadcast.net/EDC
// @match https://www.dreadcast.net/EDC/*
// @version 1.0.2
// @author Pelagia/Isilin
// @description Centralize all dreadcast scripts in one single source, integrated to the game.
// @license http://creativecommons.org/licenses/by-nc-nd/4.0/
// @require https://update.greasyfork.icu/scripts/507382/Dreadcast%20Development%20Kit.user.js
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @connect docs.google.com
// @connect googleusercontent.com
// @connect sheets.googleapis.com
// @connect raw.githubusercontent.com
// @downloadURL none
// ==/UserScript==
// TODO ajouter dans la liste tous les scripts (en utilisant le lien greasemonkey) et remplacer petit à petit par les versions locales nettoyées.
// TODO add function to export, import settings, and to reset all settings.
// TODO add text to say that disabling a script does not remove settings.
// To check if a script is used in a DSM context.
Util.isDSM = () => true;
const LIST_TAG = 'dcm_list';
const ALL_DISABLED_TAG = 'dcm_all_disabled';
let newSettings, newAllDisabled;
const initPersistence = () => {
// Init persistent memory if needed.
DC.LocalMemory.init(LIST_TAG, {});
DC.LocalMemory.init(ALL_DISABLED_TAG, false);
// Load the current settings.
let settings = DC.LocalMemory.get(LIST_TAG);
let allDisabled = DC.LocalMemory.get(ALL_DISABLED_TAG);
return { settings, allDisabled };
};
const synchronizeSettings = (settings, scripts) => {
let tmp = settings;
scripts.forEach((script) => {
if (!Object.hasOwn(tmp, script.id)) {
// Update the settings, if there is new scripts.
tmp[script.id] = false;
}
});
// Remove in settings, scripts that doesn't exist anymore.
tmp = Object.keys(tmp)
.filter((key) => scripts.find((script) => script.id === key) !== undefined)
.reduce((obj, key) => {
obj[key] = tmp[key];
return obj;
}, {});
// Save the new settings in persistent memory.
DC.LocalMemory.set(LIST_TAG, tmp);
return tmp;
};
const createScriptLine = (script, index) => {
const line = $(`