1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2024-11-14 17:42:47 +01:00
TweetDuck/Plugins/PluginScriptGenerator.cs

36 lines
1.3 KiB
C#

using TweetDuck.Plugins.Enums;
namespace TweetDuck.Plugins{
static class PluginScriptGenerator{
public static string GenerateConfig(PluginConfig config){
return config.AnyDisabled ? "window.TD_PLUGINS.disabled = [\""+string.Join("\",\"", config.DisabledPlugins)+"\"];" : string.Empty;
}
public static string GeneratePlugin(string pluginIdentifier, string pluginContents, int pluginToken, PluginEnvironment environment){
return PluginGen
.Replace("%params", environment.GetPluginScriptVariables())
.Replace("%id", pluginIdentifier)
.Replace("%token", pluginToken.ToString())
.Replace("%contents", pluginContents);
}
private const string PluginGen = "(function(%params,$d){let tmp={id:'%id',obj:new class extends PluginBase{%contents}};$d(tmp.obj,'$id',{value:'%id'});$d(tmp.obj,'$token',{value:%token});window.TD_PLUGINS.install(tmp);})(%params,Object.defineProperty);";
/* PluginGen
(function(%params, $d){
let tmp = {
id: '%id',
obj: new class extends PluginBase{%contents}
};
$d(tmp.obj, '$id', { value: '%id' });
$d(tmp.obj, '$token', { value: %token });
window.TD_PLUGINS.install(tmp);
})(%params, Object.defineProperty);
*/
}
}