Skip to content

Instantly share code, notes, and snippets.

@typhonrt
Created July 5, 2021 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typhonrt/e3f8afd1cd5aad92e69f9d846e2e069a to your computer and use it in GitHub Desktop.
Save typhonrt/e3f8afd1cd5aad92e69f9d846e2e069a to your computer and use it in GitHub Desktop.
A macro for Foundry VTT `0.7.10` or below to fix any corrupted quest data w/ and old version of Forien's Quest Log.
(async () =>
{
const folder = game.journal.directory.folders.find((f) => f.name === '_fql_quests');
// Stop now if no FQL quests folder exists.
if (!folder) { return; }
for (const entry of folder.content)
{
// Detect and skip any new style FQL quests.
const json = entry.getFlag('forien-quest-log', 'json');
if (json !== void 0) { continue; }
// Strip leading / trailing HTML tags in case someone attempted to look at / modify the JE.
let entryContent = entry.data.content;
try
{
JSON.parse(entryContent);
}
catch (err)
{
console.log(`Forien Quest Log | detected corrupted quest data for: '${entry.data.name}' attempting to fix.`);
entryContent = entryContent.replace(/^<p>/, '');
entryContent = entryContent.replace(/<\/p>$/, '');
// These regex substitutions will attempt to reverse damage to the stored JSON.
entryContent = entryContent.replace(/("\\&quot;|\\&quot;")/gm, '\\"');
entryContent = entryContent.replace(/:">/gm, '\\">');
entryContent = entryContent.replace(/:" /gm, '\\" ');
// Non-printable characters need to be removed; replace the entire range of non-printable characters.
entryContent = entryContent.replace(/[\x00-\x1F]/gm, ''); // eslint-disable-line no-control-regex
await entry.update({
content: entryContent,
});
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment