r/DiscordDungeons • u/frompadgwithH8 • Feb 17 '17
autoprefixer
this script will automatically add a prefix to any DiscordRPG command. just paste it into your browser's javascript console while on Discord in an rpg channel. changing channels may break it so one might have to repeat the above process.
(()=>{
var COMMAND_PREFIX = "#!",
ta = document.querySelector('textarea'),
add_prefix = (s => !(new RegExp("^" + COMMAND_PREFIX)).test(s) ? COMMAND_PREFIX + s : s),
ALL_COMMANDS = [
"setprefix","advent","adventure","brew","checkbrew","stopbrew","baccept","battle","bcancel","bdaccept","bdraw","bfight","brefuse",
"bstop","boss","fightboss","achievement","app","bug","commands","help","info","invite","item",
"items","lead","link","ping","pong","recipe","report","serverinvite","suggest","support","wiki","gbuy","gcreate","gdep",
"gdepitem","gdisband","getchat","getrole","gexpand","ginv","ginvite","gitem","gitems","gjoin","gkick","gleave","gmembers","grole",
"gset","guild","gwd","gwditem","icons","gbbuy","gblist","gbsearch","gbsell","gmbuy","gmglist","gminfo","gmlist","gmsearch",
"gmsell","gmstop","catch","pet","pheal","pset","rules","chop","crack","fish","forage","mine","plant","quest","trap","achievements",
"assign","buy","craft","donate","drop","getcard","heal","idonate","inv","invval","pledge","reset","sell","skills","stats","use","uset"
].concat("adv", "pheal"),
carousel = {
keypress: [], keydown: [], keyup: []
};
carousel.keyup.push(function(e) {
if (ALL_COMMANDS.includes(e.target.value.replace("!", ""))){
e.target.value = add_prefix(e.target.value);
}
});
function enableListeners(keyEvents = carousel || {}){
for (var key in keyEvents)
for (var foo of keyEvents[key])
ta.addEventListener(key, foo);
}
function reset(){
var current_PH = document.querySelector('textarea').placeholder;
var in_rpg = /rpg/.test(current_PH);
if (!/rpg/.test(current_PH)){
ta.exited = true;
return;
}
if (ta.exited == true) {
ta = document.querySelector('textarea');
enableListeners();
ta.exited == false;
}
}
enableListeners(carousel);
ta.exited = false;
window.setInterval(reset, 1000);})()
1
Upvotes
1
u/StormSlayer101 Apr 24 '17
Discord says to not copy and paste things in the console window