Skip to content

Instantly share code, notes, and snippets.

@KageDesu
Last active March 8, 2023 00:01
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 KageDesu/2b3069dd18414ecbf7c50f03e1ddf9d7 to your computer and use it in GitHub Desktop.
Save KageDesu/2b3069dd18414ecbf7c50f03e1ddf9d7 to your computer and use it in GitHub Desktop.
PKD Protector
/**
* Checks whether the string contains a given string.
*
* @memberof JsExtensions
* @param {string} string - The string to search for.
* @returns {boolean} True if the string contains a given string.
* @deprecated includes() should be used instead.
*/
String.prototype.contains = function(string) {
return this.includes(string);
};
// * Вывести себя в console.log
String.prototype.p = function () {
console.log(this.toString().format(...arguments));
};
/**
* Replaces %1, %2 and so on in the string to the arguments.
*
* @memberof JsExtensions
* @param {any} ...args The objects to format.
* @returns {string} A formatted string.
*/
String.prototype.format = function () {
return this.replace(/%([0-9]+)/g, (s, n) => arguments[Number(n) - 1]);
};
var masterFileName = 'MasterFile.js';
const testFolder = 'js/plugins';
const fs = require('fs');
// * Данные мастер файла
var masterContent = "";
function masterFilePath() {
return testFolder + "/" + masterFileName;
}
// * Получить список имён плагинов
function getPluginOrderedList() {
var pluginsJS = fs.readFileSync("js/plugins.js", 'utf8');
var pluginNames = [];
try {
eval(pluginsJS);
} catch (error) {
return [];
}
for(let plugin of $plugins) {
if(plugin.status == true) {
pluginNames.push(plugin.name + ".js");
}
}
masterFileName = pluginNames[0];
return pluginNames;
}
let Main = () => {
console.log("PKD Protector. v1.1. Start working...");
// * Занулить (очистить) мастер файл
//fs.writeFileSync(masterFilePath(), "");
let pluginOrderedList = getPluginOrderedList();
let IGNORE = ['Alpha_ABS_build.js', 'Iavra Self Variables.js', 'GradientWipe.js'];
for(const name of pluginOrderedList) {
console.log("Working with " + name);
var pluginContent = fs.readFileSync(testFolder + "/" + name, 'utf8');
console.log("Read - ok " + pluginContent.length);
if(!IGNORE.includes(name)) {
pluginContent = pluginContent.replace(/\/\*[\s\S]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g, '').trim();
}
masterContent += pluginContent;
masterContent += "; ";
console.log("Remove data - ok");
// * Очистить файл
fs.writeFileSync(testFolder + "/" + name, "", "utf8");
console.log("Clear file - ok");
//break;
}
console.log("Write master file");
fs.writeFileSync(masterFilePath(), "");
fs.writeFileSync(masterFilePath(), masterContent, 'utf8');
console.log("ALL DONE");
};
Main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment