Last active
July 31, 2024 11:39
-
-
Save davejbax/42abae54865f2ba1e3c649c7949fbbe1 to your computer and use it in GitHub Desktop.
Higher Discord volume control
This file contains hidden or 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
(function() { | |
// The following utility function are taken from EnhancedDiscord, developed by | |
// joe27g <https://github.com/joe27g>, and licensed under an MIT License. | |
// All credit goes to joe27g for the breadth of the work regarding accessing | |
// webpack modules at runtime. | |
// | |
// --- | |
// MIT License | |
// | |
// Copyright (c) 2019 joe27g | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all | |
// copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
// SOFTWARE. | |
// | |
// --- | |
// | |
// Taken from dom_shit.js, lines 79-149, commit 8795de5f80608f4647668fcd5c3a5a7d508f350b | |
// https://github.com/joe27g/EnhancedDiscord/blob/8795de5f80608f4647668fcd5c3a5a7d508f350b/dom_shit.js#L79 | |
// | |
// < BEGIN EnhancedDiscord CODE > | |
window.req = webpackJsonp.push([[], { | |
'__extra_id__': (module, exports, req) => module.exports = req | |
}, [['__extra_id__']]]); | |
delete req.m['__extra_id__']; | |
delete req.c['__extra_id__']; | |
window.findModule = (module, silent) => { | |
for (let i in req.c) { | |
if (req.c.hasOwnProperty(i)) { | |
let m = req.c[i].exports; | |
if (m && m.__esModule && m.default && m.default[module] !== undefined) | |
return m.default; | |
if (m && m[module] !== undefined) | |
return m; | |
} | |
} | |
if (!silent) c.warn(`Could not find module ${module}.`, {name: 'Modules', color: 'black'}); | |
return null; | |
}; | |
window.findModules = (module) => { | |
let mods = []; | |
for (let i in req.c) { | |
if (req.c.hasOwnProperty(i)) { | |
let m = req.c[i].exports; | |
if (m && m.__esModule && m.default && m.default[module] !== undefined) | |
mods.push(m.default); | |
if (m && m[module] !== undefined) | |
mods.push(m); | |
} | |
} | |
return mods; | |
}; | |
window.findRawModule = (module, silent) => { | |
for (let i in req.c) { | |
if (req.c.hasOwnProperty(i)) { | |
let m = req.c[i].exports; | |
if (m && m.__esModule && m.default && m.default[module] !== undefined) | |
return req.c[i]; | |
if (m && m[module] !== undefined) | |
return req.c[i]; | |
} | |
} | |
if (!silent) c.warn(`Could not find module ${module}.`, {name: 'Modules', color: 'black'}); | |
return null; | |
}; | |
window.findReactComponent = (name) => { | |
const named = findModules('displayName'); | |
return named.find(m => m.displayName === name); | |
}; | |
window.monkeyPatch = function(what, methodName, newFunc) { | |
if (!what || typeof what !== 'object') | |
return c.error(`Could not patch ${methodName} - Invalid module passed!`, {name: 'Modules', color: 'black'}); | |
const displayName = what.displayName || what.name || what.constructor.displayName || what.constructor.name; | |
const origMethod = what[methodName]; | |
const cancel = () => { | |
what[methodName] = origMethod; | |
console.log(`%c[EnhancedDiscord] %c[Modules]`, 'color: red;', `color: black;`, `Unpatched ${methodName} in module:`, what); | |
return true; | |
}; | |
what[methodName] = function() { | |
const data = { | |
thisObject: this, | |
methodArguments: arguments, | |
//cancelPatch: cancel, | |
originalMethod: origMethod, | |
callOriginalMethod: () => data.returnValue = data.originalMethod.apply(data.thisObject, data.methodArguments) | |
}; | |
return newFunc(data); | |
}; | |
what[methodName].__monkeyPatched = true; | |
what[methodName].displayName = 'patched ' + (what[methodName].displayName || methodName); | |
what[methodName].unpatch = cancel; | |
console.log(`%c[EnhancedDiscord] %c[Modules]`, 'color: red;', `color: black;`, `Patched ${methodName} in module:`, what); | |
return true; | |
}; | |
// < END EnhancedDiscord CODE > | |
// Find the relevant components | |
const UserVolumeGroup = findReactComponent('UserVolumeGroup'); | |
const Slider = findReactComponent('Slider'); | |
// Unpatch render methods if already patched (this allows re-pasting) | |
if (UserVolumeGroup.prototype.render.__monkeyPatched) { | |
UserVolumeGroup.prototype.render.unpatch(); | |
} | |
if (Slider.prototype.render.__monkeyPatched) { | |
Slider.prototype.render.unpatch(); | |
} | |
// Our global state | |
var maxVolumeMult = 1; | |
// We patch the Slider component, because we need to change it's max value; | |
// we can change this prop and re-render, but the state of the component does NOT | |
// change until it is re-created entirely. We therefore change the state ourselves | |
// on render (without re-invoking render) so that state.max and state.range are | |
// set correctly to the props (as if the component had been re-created). | |
monkeyPatch(Slider.prototype, 'render', (data) => { | |
// Check whether there's a discrepancy between prop max and state max | |
if (data.thisObject && data.thisObject.props.maxValue != data.thisObject.state.max) { | |
let state = Object.assign({}, data.thisObject.state); | |
state.max = data.thisObject.props.maxValue; | |
state.range = state.max; | |
data.thisObject.state = state; | |
} | |
return data.callOriginalMethod(); | |
}); | |
// We patch the UserVolumeGroup component, because we add another item to the | |
// menu group to control the | |
monkeyPatch(UserVolumeGroup.prototype, 'render', (data) => { | |
// Invoke the original render function so we have something to work with | |
// (we can modify the components; this is more future-proof than creating | |
// them ourselves) | |
var menuGroup = data.callOriginalMethod(); | |
// Set the max value of the user volume slider to 100 (displayed as 200%) * mult. | |
var userVolumeSliderMenuItem = menuGroup.props.children; | |
if (!userVolumeSliderMenuItem) { | |
// Sanity check: we might be the menu for ourselves | |
return menuGroup; | |
} | |
userVolumeSliderMenuItem.props.maxValue = 100 * maxVolumeMult; | |
// Create another SliderMenuItem, from 1 to 20, that controls the range/max of | |
// the user volume slider | |
var maxVolumeMultSliderMenuItem = Object.assign({}, userVolumeSliderMenuItem); | |
maxVolumeMultSliderMenuItem.props = Object.assign({}, userVolumeSliderMenuItem.props); | |
maxVolumeMultSliderMenuItem.props.maxValue = 20; | |
maxVolumeMultSliderMenuItem.props.minValue = 1; | |
maxVolumeMultSliderMenuItem.props.defaultValue = maxVolumeMult; | |
maxVolumeMultSliderMenuItem.props.label = 'Max Volume Multiplier'; | |
maxVolumeMultSliderMenuItem.props.onValueChange = (value) => { | |
// Floor the value (it's a float) and update the UserVolumeGroup component | |
// so we can display the changed user volume slider | |
maxVolumeMult = Math.floor(value); | |
userVolumeSliderMenuItem.props.maxValue = 100 * maxVolumeMult; | |
data.thisObject.forceUpdate.apply(data.thisObject, []); | |
} | |
maxVolumeMultSliderMenuItem.props.onValueRender = (e) => (Math.floor(e) + 'x'); | |
// Add both user volume & max volume multiplier sliders | |
menuGroup.props.children = [ | |
userVolumeSliderMenuItem, | |
maxVolumeMultSliderMenuItem | |
]; | |
return menuGroup; | |
}); | |
})(); |
can always get the latest version from here
ах ты хуеплет, нихуя не понятно
yep same here
Doesn't seem to work anymore, I get this error:
VM516:121 Uncaught TypeError: Cannot read property 'prototype' of undefined at <anonymous>:121:25 at <anonymous>:191:3
Try this instead, it's Japanese but it worked for me.
I'm actually getting the same error on the Japanese version too (line numbers are slightly different but same error)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.githubusercontent.com/silver-mixer/6e0e73165e1774ec81ea60193ec81bb5/raw/8aa8bd707da0dbcdcf77e20bcdce564238168e74/discord.js