dots-of-war/files/.config/EnhancedDiscord/plugins/quick_save.js

40 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-06-21 10:41:26 +00:00
const Plugin = require('../plugin');
module.exports = new Plugin({
name: 'Quick Save',
author: 'Joe 🎸#7070',
description: 'Use Ctrl+S or Cmd+S to save server, channel, or account settings.',
color: 'salmon',
load: async function() {
const hcModules = window.EDApi.findAllModules('hasChanges');
this._listener = function(e) {
if ((window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && e.keyCode == 83) {
e.preventDefault();
const types = ['GUILD', 'CHANNEL', 'ACCOUNT', 'GUILD ROLES', 'CHANNEL OVERWRITES'];
let hasChanges = false;
for (const i in types) {
if (hcModules[i] && hcModules[i].hasChanges()) {
hasChanges = true;
//module.exports.log(`saving ${types[i]} settings`);
break;
}
}
if (!hasChanges) {
//module.exports.log('No setting changes detected. Aborting.');
return;
}
const saveButton = document.querySelector('[class*="lookFilled-"][class*="colorGreen-"]');
if (saveButton)
try { saveButton.click(); } catch(err) { module.exports.error(err); }
return;
}
}
document.addEventListener("keydown", this._listener, false);
},
unload: function() {
document.removeEventListener("keydown", this._listener);
delete this._listener;
}
});