PKD Protector
This file contains 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 characters
/** | |
* 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