Last active
February 2, 2019 12:15
-
-
Save Cholik/534ace541aa253c8d6308997cb425db4 to your computer and use it in GitHub Desktop.
BetterDiscord - Prefill Image Upload Modal
This file contains 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
//META{"name":"ImageNamePrefill"}*// | |
class ImageNamePrefill { | |
getName() {return "ImageNamePrefill";} // Name of your plugin to show on the plugins page | |
getDescription() {return "Inserts the image file name as message in upload dialog.";} // Description to show on the plugins page | |
getVersion() {return "0.0.2";} // 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'); | |
} | |
stop() { | |
} | |
updateModal(modal) { | |
var name = modal.querySelector('.da-filename').innerText; | |
if(name.indexOf('[') > -1) { | |
name = name.substring(0, name.indexOf('[')).trim(); | |
} | |
document.execCommand("insertText", false, name); | |
} | |
observer(e) { | |
if(e.addedNodes.length > 0) { | |
if(e.addedNodes[0] instanceof HTMLElement) { | |
var className = e.addedNodes[0].getAttribute('class'); | |
if(className != null && className.indexOf('da-modal') > -1) { | |
var modal = e.addedNodes[0].querySelector('.da-uploadModal'); | |
if(modal !== null && modal.querySelector('.da-filename').innerText.startsWith('SPOILER_')) { | |
this.updateModal(modal); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment