Skip to content

Instantly share code, notes, and snippets.

@Cholik
Last active July 24, 2019 15:43
Show Gist options
  • Save Cholik/1faa61880dc751250aaca4028eb555fe to your computer and use it in GitHub Desktop.
Save Cholik/1faa61880dc751250aaca4028eb555fe to your computer and use it in GitHub Desktop.
BetterDiscord - QuoteOnClick Plugin
//META{"name":"QuoteOnClickPlugin"}*//
class QuoteOnClickPlugin {
getName() {return "QuoteOnClick";} // Name of your plugin to show on the plugins page
getDescription() {return "Quote a message by simply double clicking it";} // Description to show on the plugins page
getVersion() {return "0.0.5";} // Current version. I recommend following semantic versioning <http://semver.org/> (e.g. 0.0.1)
getAuthor() {return "Cholik";} // Your name
debugOut(msg) {
if(this.DEBUG) {
console.log('[' + this.getName() + '] :: ' + msg);
}
}
load() {
this.DEBUG = true;
this.debugOut('Load - ' + this.getVersion());
}
start() {
this.debugOut('Start');
document.addEventListener('dblclick', this.handler.bind(this));
}
stop() {
document.removeEventListener('dblclick', this.handler);
}
createQuote(input) {
var output = "";
input.split('\n').forEach(function(text, index){
output += '\\>' + text + '\n';
});
return output;
}
handler(e) {
try {
var el = e.target || e.srcElement;
var input = document.querySelector('textarea');
if(el.getAttribute('class').indexOf('da-markup') > -1) {
input.focus();
input.selectionStart = 0;
input.selectionEnd = input.value.length;
document.execCommand("insertText", false, input.value + this.createQuote(el.textContent));
input.selectionStart = input.value.length;
input.selectionEnd = input.value.length;
}
}
catch(err) {
console.log(err);
}
}
observer(changes) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment