// ==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 = $(` ${index} ${ script.icon && script.icon !== '' ? `` : '' } ${ script.name || '' } ${ script.authors || '' } ${ script.description || '' } `); $('.enabled_cell', line).append( DC.UI.Checkbox( `${script.id}_check`, newSettings[script.id], () => (newSettings[script.id] = !newSettings[script.id]), ), ); if (script.settings) { $('.setting_cell', line).append( DC.UI.Tooltip( 'Settings', DC.UI.Button( `${script.id}_setting`, '', () => {}, ), ), ); } if (script.doc && script.doc !== '') { $('.doc_cell', line).append( DC.UI.Tooltip( 'Documentation', DC.UI.Button(`${script.id}_doc`, '', () => window.open(script.doc, '_blank'), ), ), ); } if (script.rp && script.rp !== '') { $('.rp_cell', line).append( DC.UI.Tooltip( 'Topic RP', DC.UI.Button( `${script.id}_rp`, '
RP
', () => window.open(script.doc, '_blank'), ), ), ); } if (script.contact && script.contact !== '') { $('.contact_cell', line).append( DC.UI.Tooltip( 'Contact', DC.UI.Button(`${script.id}_rp`, '', () => nav.getMessagerie().newMessage(script.contact), ), ), ); } return line; }; $(() => { let { settings, allDisabled } = initPersistence(); const createUI = (scripts, settings) => { DC.UI.addSubMenuTo( 'Paramètres ▾', DC.UI.SubMenu( 'Scripts & Skins', () => { // On récupère une config temporaire qu'on appliquera uniquement si sauvegardée. newSettings = settings; newAllDisabled = allDisabled; const sections = [ { id: 'all', label: 'Tous' }, { id: 'game', label: 'Jeu' }, { id: 'forum', label: 'Forum' }, { id: 'edc', label: 'EDC' }, ]; const categories = [ { id: 'all', label: 'Tous' }, { id: 'mailing', label: 'Messagerie' }, { id: 'chat', label: 'Chat' }, { id: 'silhouette', label: 'Silhouette' }, { id: 'ui', label: 'UI' }, { id: 'mech', label: 'Mécaniques' }, { id: 'fix', label: 'Correctifs' }, { id: 'misc', label: 'Autres' }, ]; const content = $(`

Tout désactiver

Filtrer :
${sections .map( (section, index) => `
`, ) .join('')}
Filtrer :
${categories .map( (category, index) => `
`, ) .join('')}
# Nom Auteurs Actif
`); $(document).on('change', "input[name='category']", (e) => { const category = e.target.value; const section = $("input[name='section']:checked").val(); // Empty the table $('tbody', content).empty(); // Add filtered lines scripts .filter( (script) => (script.section.includes(section) || section === 'all') && (script.category.includes(category) || category === 'all'), ) .forEach((script, index) => { const line = createScriptLine(script, index); $('tbody', content).append(line); }); }); $(document).on('change', "input[name='section']", (e) => { const section = e.target.value; const category = $("input[name='category']:checked").val(); // Empty the table $('tbody', content).empty(); // Add filtered lines scripts .filter( (script) => (script.section.includes(section) || section === 'all') && (script.category.includes(category) || category === 'all'), ) .forEach((script, index) => { const line = createScriptLine(script, index); $('tbody', content).append(line); }); }); // Sauvegarder les paramètres. content.append( DC.UI.TextButton('scripts_refresh', 'Sauvegarder', () => { settings = newSettings; allDisabled = newAllDisabled; DC.LocalMemory.set(LIST_TAG, settings); DC.LocalMemory.set(ALL_DISABLED_TAG, allDisabled); location.reload(); }), ); content.append( $( `

⚠ Sauvegarder votre configuration va raffraichir la page.
Pensez à sauvegarder votre travail en cours avant.

`, ), ); // Switch button pour désactiver tous les scripts. $('#scripts_all_switch', content).append( DC.UI.Checkbox( 'scripts_all_check', newAllDisabled, () => (newAllDisabled = !newAllDisabled), ), ); scripts.forEach((script, index) => { const line = createScriptLine(script, index); $('tbody', content).append(line); }); return DC.UI.PopUp('scripts_modal', 'Scripts & Skins', content); }, true, ), 5, ); }; // Load list of scripts DC.Network.loadJson( 'https://raw.githubusercontent.com/Isilin/dreadcast-scripts/main/data/scripts.json', ) .then((scripts) => { settings = synchronizeSettings(settings, scripts); // Create the interface. if (Util.isGame()) { createUI(scripts, settings); } // Load the scripts if (!allDisabled) { const context = Util.getContext(); scripts .filter((script) => script.section.includes(context)) .forEach((script) => { if (settings[script.id]) { DC.Network.loadScript(script.url) .then(() => { console.info( `DCSM - '${script.name}' script has been loaded successfully.`, ); }) .catch((err) => { console.error( `DCSM - Error loading '${script.name}' script: ` + err, ); }); } }); } }) .catch((err) => { console.error('DCSM - Error loading the list of scripts :' + err); }); });