2022-09-26 12:33:57 +02:00
|
|
|
const path = require("path");
|
|
|
|
const fetch = require("node-fetch");
|
|
|
|
const fs = require("fs/promises");
|
|
|
|
const { existsSync } = require("fs");
|
|
|
|
|
|
|
|
const CACHE_PATH = path.join(__dirname, "..", "assets", "cache");
|
|
|
|
const BASE_URL = "https://discord.com";
|
|
|
|
|
2022-09-26 15:00:27 +02:00
|
|
|
const INSTANCE_NAME = "Slowcord";
|
|
|
|
|
2022-09-26 12:33:57 +02:00
|
|
|
// Manual for now
|
|
|
|
const INDEX_SCRIPTS = [
|
2022-09-26 14:29:30 +02:00
|
|
|
"83ace7450e110d16319e", // 50
|
|
|
|
"e02290aaa8dac5d195c2", // 1
|
|
|
|
"4f3b3c576b879a5f75d1", // 0?
|
|
|
|
"699456246fdfe7589855", // ~4500.
|
2022-09-26 12:33:57 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
const doPatch = (content) => {
|
|
|
|
//remove nitro references
|
2022-09-26 15:00:27 +02:00
|
|
|
content = content.replace(/Discord Nitro/g, `${INSTANCE_NAME} Premium`);
|
2022-09-26 14:29:30 +02:00
|
|
|
content = content.replace(/"Nitro"/g, '"Premium"');
|
2022-09-26 12:33:57 +02:00
|
|
|
content = content.replace(/Nitro /g, "Premium ");
|
|
|
|
content = content.replace(/ Nitro/g, " Premium");
|
|
|
|
content = content.replace(/\[Nitro\]/g, "[Premium]");
|
|
|
|
content = content.replace(/\*Nitro\*/g, "*Premium*");
|
2022-09-26 14:29:30 +02:00
|
|
|
content = content.replace(/\"Nitro \. /g, '"Premium. ');
|
2022-09-26 12:33:57 +02:00
|
|
|
|
|
|
|
//remove discord references
|
2022-09-26 15:00:27 +02:00
|
|
|
content = content.replace(/ Discord /g, ` ${INSTANCE_NAME} `);
|
|
|
|
content = content.replace(/Discord /g, `${INSTANCE_NAME} `);
|
|
|
|
content = content.replace(/ Discord/g, ` ${INSTANCE_NAME}`);
|
|
|
|
content = content.replace(/Discord Premium/g, `${INSTANCE_NAME} Premium`);
|
|
|
|
content = content.replace(/Discord Nitro/g, `${INSTANCE_NAME} Premium`);
|
|
|
|
content = content.replace(/Discord's/g, `${INSTANCE_NAME}'s`);
|
2022-09-26 12:33:57 +02:00
|
|
|
//content = content.replace(/DiscordTag/g, "FosscordTag");
|
2022-09-26 15:00:27 +02:00
|
|
|
content = content.replace(/\*Discord\*/g, `*${INSTANCE_NAME}*`);
|
2022-09-26 12:33:57 +02:00
|
|
|
|
|
|
|
//server -> guild
|
2022-09-26 14:29:30 +02:00
|
|
|
content = content.replace(/"Server"/g, '"Guild"');
|
|
|
|
content.replaceAll('server."', 'guild."');
|
2022-09-26 12:33:57 +02:00
|
|
|
content.replaceAll(" server ", " guild ");
|
|
|
|
content.replaceAll(" Server ", " Guild ");
|
2022-09-26 14:29:30 +02:00
|
|
|
content.replaceAll('"Server', '"Guild');
|
2022-09-26 12:33:57 +02:00
|
|
|
|
|
|
|
// //change some vars
|
|
|
|
// content = content.replace('dsn: "https://fa97a90475514c03a42f80cd36d147c4@sentry.io/140984"', "dsn: (/true/.test(localStorage.sentryOptIn)?'https://6bad92b0175d41a18a037a73d0cff282@sentry.thearcanebrony.net/12':'')");
|
|
|
|
// content = content.replace('t.DSN = "https://fa97a90475514c03a42f80cd36d147c4@sentry.io/140984"', "t.DSN = (/true/.test(localStorage.sentryOptIn)?'https://6bad92b0175d41a18a037a73d0cff282@sentry.thearcanebrony.net/12':'')");
|
|
|
|
// content = content.replace('--brand-experiment: hsl(235, calc(var(--saturation-factor, 1) * 85.6%), 64.7%);', '--brand-experiment: hsl(var(--brand-hue), calc(var(--saturation-factor, 1) * 85.6%), 50%);');
|
|
|
|
// content = content.replaceAll(/--brand-experiment-(\d{1,4}): hsl\(235/g, '--brand-experiment-\$1: hsl(var(--brand-hue)');
|
|
|
|
|
|
|
|
//logos
|
|
|
|
// content = content.replace(/d: "M23\.0212.*/, `d: "${icons.get("homeIcon.path")!.toString()}"`);
|
|
|
|
// content = content.replace('width: n, height: o, viewBox: "0 0 28 20"', 'width: 48, height: 48, viewBox: "0 0 48 48"');
|
|
|
|
|
|
|
|
//save some time on load resolving asset urls...
|
2022-09-26 14:29:30 +02:00
|
|
|
content = content.replaceAll(
|
|
|
|
'e.exports = n.p + "',
|
|
|
|
'e.exports = "/assets/',
|
|
|
|
);
|
|
|
|
content = content.replaceAll(
|
|
|
|
'e.exports = r.p + "',
|
|
|
|
'e.exports = "/assets/',
|
|
|
|
);
|
2022-09-26 12:33:57 +02:00
|
|
|
|
|
|
|
return content;
|
|
|
|
};
|
|
|
|
|
|
|
|
const processFile = async (name) => {
|
|
|
|
const res = await fetch(`${BASE_URL}/assets/${name}.js`);
|
|
|
|
let text = await res.text();
|
|
|
|
|
|
|
|
text = doPatch(text);
|
|
|
|
|
|
|
|
await fs.writeFile(path.join(CACHE_PATH, `${name}.js`), text);
|
|
|
|
|
2022-09-26 14:29:30 +02:00
|
|
|
return [...new Set(text.match(/[A-Fa-f0-9]{20}/g))];
|
2022-09-26 12:33:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
const start = Date.now();
|
|
|
|
|
|
|
|
// console.log("Deleting previous cache");
|
|
|
|
// await fs.rm(CACHE_PATH, { recursive: true });
|
2022-09-26 15:00:27 +02:00
|
|
|
if (!existsSync(CACHE_PATH)) await fs.mkdir(CACHE_PATH);
|
2022-09-26 12:33:57 +02:00
|
|
|
|
|
|
|
const assets = [];
|
|
|
|
|
|
|
|
while (INDEX_SCRIPTS.length > 0) {
|
|
|
|
const asset = INDEX_SCRIPTS.shift();
|
|
|
|
|
|
|
|
process.stdout.clearLine(0);
|
|
|
|
process.stdout.cursorTo(0);
|
2022-09-26 14:29:30 +02:00
|
|
|
process.stdout.write(
|
|
|
|
`Scraping asset ${asset}. Remaining: ${INDEX_SCRIPTS.length}`,
|
|
|
|
);
|
2022-09-26 12:33:57 +02:00
|
|
|
|
|
|
|
const newAssets = await processFile(asset);
|
|
|
|
assets.push(...newAssets);
|
|
|
|
}
|
|
|
|
|
|
|
|
process.stdout.moveCursor(0, 1);
|
|
|
|
|
|
|
|
let rates = [];
|
|
|
|
let lastFinished = Date.now();
|
|
|
|
let previousFinish = Date.now();
|
|
|
|
|
|
|
|
for (var i = 0; i < assets.length; i++) {
|
|
|
|
const asset = assets[i];
|
|
|
|
|
|
|
|
if (existsSync(path.join(CACHE_PATH, `${asset}.js`))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-09-26 15:00:27 +02:00
|
|
|
while (rates.length > 50) rates.shift();
|
2022-09-26 14:29:30 +02:00
|
|
|
const averageRate = rates.length
|
|
|
|
? rates.reduce((prev, curr) => prev + curr) / rates.length
|
|
|
|
: 1;
|
|
|
|
const finishTime = averageRate * (assets.length - i);
|
2022-09-26 12:33:57 +02:00
|
|
|
|
|
|
|
process.stdout.clearLine(0);
|
|
|
|
process.stdout.cursorTo(0);
|
|
|
|
process.stdout.write(
|
|
|
|
`Caching asset ${asset}. ` +
|
2022-09-26 14:29:30 +02:00
|
|
|
`${i}/${assets.length - 1} = ${Math.floor(
|
|
|
|
(i / (assets.length - 1)) * 100,
|
|
|
|
)}% ` +
|
|
|
|
`Finish at: ${new Date(
|
|
|
|
Date.now() + finishTime,
|
|
|
|
).toLocaleTimeString()}`,
|
2022-09-26 12:33:57 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
await processFile(asset);
|
|
|
|
|
|
|
|
lastFinished = Date.now();
|
|
|
|
rates.push(lastFinished - previousFinish);
|
|
|
|
previousFinish = lastFinished;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`\nDone`);
|
2022-09-26 14:29:30 +02:00
|
|
|
})();
|