[SCRIPT|TOOL] DashingDown


This is a script you can run in your browser to download the scenes’ text file from a game hosted at DashingDon or Moody.ink.

:warning: Do no evil!

This is an honor-based system:

  • Do not use this script to keep illegal copies of games.
  • Do not use it on games whose author has requested not to peek into their code.
  • Preferably, use the script only on your own games or on those whose author has granted explicit permission.

:face_with_monocle: Observations

  • The script only automatizes something that is already possible to do manually.
  • The script will not download game assets, such as images and audio files.
  • It won’t work on compiled games.

Reasoning

Personally, when giving feedback on typos or awkward wording I like to be specific, pointing out the file name and if possible the code line. This means I’m constantly peeking into others’ code.


  • Easily reclaim your own lost game that only exists on DashingDon or Moody.ink.
  • Easily access game files to study someone else’s code (code diving).
Installation

These instructions are for Chrome. However, they should be similar for other browsers.

  • Open the Bookmark Manager.
  • Create a new bookmark manually.
    • Name: DashingDown (or anything to your fancy)
    • URL (copy code below):
      javascript:(function(){let i=window.location.href;if(!/dashingdon\.com|moody\.ink/.test(i)){alert("You must be on Dashingdon or Moody.ink to run the script.");return}if(!/mygame/.test(i)){alert("You must be on a game's page to run the script!");return}const a=i.match(/play\/(.+)\/mygame/)[1].split("/")[1];try{JSZip}catch(e){const t=Object.assign(document.createElement("script"),{src:"https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js",crossorigin:"anonymous",referrerpolicy:"no-referrer"});document.head.appendChild(t)}setTimeout(async()=>{let e;if(/scenes\/?$/.test(i)){e=[...document.querySelectorAll("a")]}else{history.pushState({},null,"scenes");i=location.href;const o=await fetch(i).then(e=>e.status>=200&&e.status<300?e.text():null);const r=new DOMParser;const c=r.parseFromString(o,"text/html");e=[...c.querySelectorAll("a")]}const{files:t,promises:n}=e.reduce(function(e,t){const n=t.innerText.trim();const s=fetch(`${i}/${t.getAttribute("href")}`).then(e=>e.blob())["catch"](e=>null);e.files[n]=s;e.promises.push(s);return e},{files:{},promises:[]});await Promise.all(n);const s=new JSZip;Object.entries(t).forEach(([e,t])=>s.file(e,t,{binary:true}));s.generateAsync({type:"blob"}).then(e=>{const t=window.URL.createObjectURL(e);const n=document.createElement("a");n.href=t;n.setAttribute("download",a+".zip");n.click()})},500)})();
      
Use Instruction

Whenever you’re in a game’s page on DashignDon or Moody.ink which you wish to download the text files, just click the bookmark you created and the script will fetch and zip all files for you.

Unminified Script Code

Here’s the unminified code of the script for anyone who’s interested.

(function () {
	let url = window.location.href;

	if (!/dashingdon\.com|moody\.ink/.test(url)) {
		alert('You must be on Dashingdon or Moody.ink to run the script.');
		return;
	}

	if (!/mygame/.test(url)) {
		alert("You must be on a game's page to run the script!");
		return;
	}

	// if (!/\/scenes\/?$/.test(url)) {
	// 	window.location.href = 'scenes/';
	// 	alert('Run the script again to download files.');
	// 	return;
	// }

	const gameTitle = url.match(/play\/(.+)\/mygame/)[1].split('/')[1];

	// add jszip to page
	try {
		JSZip;
	} catch (_) {
		const JSZipScript = Object.assign(document.createElement('script'), {
			src: 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js',
			// integrity:
			// 	'sha512-XMVd28F1oH/O71fzwBnV7HucLxVwtxf26XV8P4wPk26EDxuGZ91N8bsOttmnomcCD3CS5ZMRL50H0GgOHvegtg==',
			crossorigin: 'anonymous',
			referrerpolicy: 'no-referrer',
		});
		document.head.appendChild(JSZipScript);
	}

	setTimeout(async () => {
		let scenes;

		if (/scenes\/?$/.test(url)) {
			scenes = [...document.querySelectorAll('a')];
		} else {
            history.pushState({}, null, 'scenes');
            url = location.href;

			const scenesPage = await fetch(url).then(res =>
				res.status >= 200 && res.status < 300 ? res.text() : null
			);

            const parser = new DOMParser();

            const scenesDocument = parser.parseFromString(scenesPage, "text/html");

            scenes = [...scenesDocument.querySelectorAll('a')];
		}

		const { files, promises } = scenes.reduce(
			function (acc, a) {
				const filename = a.innerText.trim();

				const blob = fetch(`${url}/${a.getAttribute("href")}`)
					.then(data => data.blob())
					.catch(e => null);

				acc.files[filename] = blob;
				acc.promises.push(blob);

				return acc;
			},
			{
				files: {},
				promises: [],
			}
		);

		await Promise.all(promises);

		// save to zip
		const zip = new JSZip();

		Object.entries(files).forEach(([filename, data]) =>
			zip.file(filename, data, { binary: true })
		);

		zip.generateAsync({ type: 'blob' }).then(data => {
			const objectURL = window.URL.createObjectURL(data);
			const a = document.createElement('a');
			a.href = objectURL;
			a.setAttribute('download', gameTitle + '.zip');
			a.click();
		});
	}, 500);
})();
13 Likes