DiscordFreeEmojisInstaller ps1
DiscordFreeEmojisInstaller ps1
function AddExtension([string]$electonDataPath) {
'adding extension'
$extensionListPath = "$electonDataPath\DevTools Extensions"
if(Test-Path $extensionListPath) {
$extensionList = ConvertFrom-Json (Get-Content $extensionListPath -Raw)
$extensionList = @($extensionList | ? { $_ -notmatch '(?:^|
[\\\/])DiscordFreeEmojis[\\\/]?$' })
if($extensionList.Length -ne 0) {
$extensionList += '../../DiscordFreeEmojis'
Set-Content $extensionListPath (ConvertTo-Json $extensionList)
return
}
}
Set-Content $extensionListPath '["../../DiscordFreeEmojis"]'
}
function StopProcesses([string]$name) {
$targets = Get-Process $name -ErrorAction SilentlyContinue
if($targets.Length -eq 0) { return }
try {
$targets | Stop-Process
} catch { "PLEASE CLOSE $name!" }
"waiting for $name to close"
do {
sleep 1
$targets = Get-Process $name -ErrorAction SilentlyContinue
} while($targets.Length -gt 0)
}
$discordPath = $env:LOCALAPPDATA+'\Discord'
$discordDataPath = $env:APPDATA+'\discord'
$discordResourcesPath = $discordPath+'\app-*\resources'
$discordPtbPath = $env:LOCALAPPDATA+'\DiscordPTB'
$discordPtbDataPath = $env:APPDATA+'\discordptb'
$discordPtbResourcesPath = $discordPtbPath+'\app-*\resources'
$discordCanaryPath = $env:LOCALAPPDATA+'\DiscordCanary'
$discordCanaryDataPath = $env:APPDATA+'\discordcanary'
$discordCanaryResourcesPath = $discordCanaryPath+'\app-*\resources'
$pluginPath = $env:LOCALAPPDATA+'\DiscordFreeEmojis'
$install = $false
try {
if(Test-Path $discordPath) {
'Discord found'
if(Test-Path $discordDataPath) { 'data directory found' } else { 'data
directory not found'; return }
if(Test-Path $discordResourcesPath) { 'resources directory found' } else
{ 'resources directory not found'; return }
StopProcesses 'Discord'
AddExtension $discordDataPath
$install = $true
}
if(Test-Path $discordPtbPath) {
'DiscordPTB found'
if(Test-Path $discordPtbDataPath) { 'data directory found' } else { 'data
directory not found'; return }
if(Test-Path $discordPtbResourcesPath) { 'resources directory found' } else {
'resources directory not found'; return }
StopProcesses 'DiscordPTB'
AddExtension $discordPtbDataPath
$install = $true
}
if(Test-Path $discordCanaryPath) {
'DiscordCanary found'
if(Test-Path $discordCanaryDataPath) { 'data directory found' } else { 'data
directory not found'; return }
if(Test-Path $discordCanaryResourcesPath) { 'resources directory found' }
else { 'resources directory not found'; return }
StopProcesses 'DiscordCanary'
AddExtension $discordCanaryDataPath
$install = $true
}
if($install) {
'installing'
var Discord;
var Utils = {
Log: (message) => { console.log(`%c[FreeEmojis] %c${message}`, `color:$
{BaseColor};font-weight:bold`, "") },
Warn: (message) => { console.warn(`%c[FreeEmojis] %c${message}`, `color:$
{BaseColor};font-weight:bold`, "") },
Error: (message) => { console.error(`%c[FreeEmojis] %c${message}`, `color:$
{BaseColor};font-weight:bold`, "") }
};
function Init(nonInvasive)
{
Discord = { window: (typeof(unsafeWindow) !== 'undefined') ? unsafeWindow :
window };
delete webpackExports.m['__extra_id__'];
delete webpackExports.c['__extra_id__'];
if(!m) continue;
if(filter(m)) return m;
}
}
if (!nonInvasive) {
console.warn("Couldn't find module in existing cache. Loading all
modules.");
if(!m) continue;
if(filter(m)) return m;
}
catch (e) { }
}
return null;
};
let emojisModule =
findModuleByUniqueProperties([ 'getDisambiguatedEmojiContext', 'search' ],
nonInvasive);
if(emojisModule == null) { if(!nonInvasive) Utils.Error("emojisModule not
found."); return 0; }
let emojiPickerModule =
findModuleByUniqueProperties([ 'useEmojiSelectHandler' ], nonInvasive);
if(emojiPickerModule == null) { if(!nonInvasive) Utils.Error("emojiPickerModule
not found."); return 0; }
Utils.Log("loaded");
return 1;
}
var InitFails = 0;
function TryInit()
{
if(Init(true) !== 0) return;
TryInit();
})();
`;
(document.head||document.documentElement).appendChild(script);
script.remove();
'@)
'FINISHED'
}
else { 'Discord not found' }
}
catch { $_ }
finally { [Console]::ReadLine() }