Last active
March 21, 2024 06:06
-
-
Save MarvNC/69968757ae8f1cc8808fab882861d66d to your computer and use it in GitHub Desktop.
Revisions
-
MarvNC revised this gist
Mar 21, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,4 +4,4 @@ - Run `dump.js` in the `script` folder - Scripts will be dumped in `script/out` **[Download scripts zip](https://gist.github.com/MarvNC/69968757ae8f1cc8808fab882861d66d/raw/scripts.zip)** -
MarvNC revised this gist
Mar 21, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
Binary file not shown. -
MarvNC revised this gist
Mar 21, 2024 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,6 @@ - Use asar to extract files in `resources` - Run `dump.js` in the `script` folder - Scripts will be dumped in `script/out` **[Download scripts zip](https://gist.github.com/MarvNC/69968757ae8f1cc8808fab882861d66d/raw/6d2a6296775ef8a619f4d33cfd3338c83ef004cc/scripts.zip)** -
MarvNC revised this gist
Mar 21, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
Binary file not shown. -
MarvNC created this gist
Mar 21, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ # For 寄甡 (Symbiotic Love) - Use asar to extract files in `resources` - Run `dump.js` in the `script` folder - Scripts will be dumped in `script/out` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ const fs = require('fs').promises; const path = require('path'); const outDir = './out'; async function readAndParseJSON() { try { const files = await fs.readdir('./'); for (const file of files) { const data = await fs.readFile(file, 'utf8'); let jsonData; try { jsonData = JSON.parse(data); // console.log(`JSON data from ${file}:`, jsonData); } catch (error) { // console.error(`Error parsing JSON from ${file}:`, error); } const script = readPossibleScriptJSON(jsonData); // If script exists, write it as a txt file if (script) { let filename = `${script.id}${script.title ? `-${script.title}` : ''}`; // Append length to filename filename += `-${script.lines.length}`; // Replace invalid characters filename = filename.replace(/[\\/:*?"<>|]/g, ''); // Create outDir if it doesn't exist try { await fs.access(outDir); } catch (error) { await fs.mkdir(outDir); } const filepath = path.join(outDir, `${filename}.txt`); await fs.writeFile(filepath, script.lines, 'utf8'); console.log(`Script written to filepath: ${filepath}`); } } } catch (err) { console.error('Error reading directory:', err); } } readAndParseJSON(); /** * Check if it's a script, return script text if so * @param {*} data */ function readPossibleScriptJSON(data) { const lines = []; // Check if data is array if (!Array.isArray(data)) { return null; } const id = data[0][3].id; const title = data[0][3].title; for (const line of data) { if (line && line[3] && line[3].text) { lines.push(line[3].text); } } if (lines.length > 0) { return { id, title, lines: lines.join('\n'), }; } else { return null; } }