BetterDiscordApp-v2/tests/csseditor/main.js

124 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-01-17 14:46:27 +01:00
const { remote, ipcRenderer } = require('electron');
const { BDIpc } = require('../frontend/main.js');
2018-01-17 14:46:27 +01:00
//Options
const options = {
alwaysOnTop: false,
liveUpdate: false
2018-01-17 14:46:27 +01:00
};
function sendToDiscord(channel, message) {
BDIpc.send('bd-sendToDiscord', {channel, message});
}
2018-01-17 14:46:27 +01:00
//Elements
const
$spinner = $('#spinner'),
$toggleaot = $('#toggleaot'),
$closeeditor = $('#closeeditor'),
$editor = $('#editor'),
$btnSave = $('#btnSave'),
$btnUpdate = $('#btnUpdate'),
$chkboxLiveUpdate = $("#chkboxLiveUpdate input");
2018-01-17 14:46:27 +01:00
$toggleaot.on('click', e => {
$toggleaot.toggleClass("active");
remote.getCurrentWindow().setAlwaysOnTop(options.alwaysOnTop = !options.alwaysOnTop);
});
2018-01-17 15:39:39 +01:00
$closeeditor.on('click', e => window.close());
$btnSave.on('click', () => sendToDiscord("save-css", codeMirror.getValue()));
$btnUpdate.on('click', () => sendToDiscord("update-css", codeMirror.getValue()));
$chkboxLiveUpdate.on('change', () => options.liveUpdate = $chkboxLiveUpdate[0].checked);
BDIpc.on("set-css", (_, data) => {
2018-01-17 14:46:27 +01:00
if (data.error) {
alert(data.error);
return;
}
setCss(data.css);
2018-01-17 14:46:27 +01:00
$spinner.hide();
});
function setCss(css) {
codeMirror.setValue(css);
}
2018-01-17 14:46:27 +01:00
function alert(message) {}
const codeMirror = CodeMirror($editor[0], {
lineNumbers: true,
mode: 'css',
indentUnit: 4,
theme: 'material',
scrollbarStyle: 'overlay',
extraKeys: { 'Ctrl-Space': 'autocomplete' },
dialog: { 'position': 'bottom' }
});
codeMirror.on('change', () => {
if (options.liveUpdate)
sendToDiscord("update-css", codeMirror.getValue());
});
2018-01-17 14:46:27 +01:00
codeMirror.on('keyup', function (editor, event) {
if (window.controlDown) return;
if (ExcludedIntelliSenseTriggerKeys[event.keyCode]) return;
CodeMirror.commands.autocomplete(editor, null, { completeSingle: false });
});
const ExcludedIntelliSenseTriggerKeys = {
'8': 'backspace',
'9': 'tab',
'13': 'enter',
'16': 'shift',
'17': 'ctrl',
'18': 'alt',
'19': 'pause',
'20': 'capslock',
'27': 'escape',
'33': 'pageup',
'34': 'pagedown',
'35': 'end',
'36': 'home',
'37': 'left',
'38': 'up',
'39': 'right',
'40': 'down',
'45': 'insert',
'46': 'delete',
'91': 'left window key',
'92': 'right window key',
'93': 'select',
'107': 'add',
'109': 'subtract',
'110': 'decimal point',
'111': 'divide',
'112': 'f1',
'113': 'f2',
'114': 'f3',
'115': 'f4',
'116': 'f5',
'117': 'f6',
'118': 'f7',
'119': 'f8',
'120': 'f9',
'121': 'f10',
'122': 'f11',
'123': 'f12',
'144': 'numlock',
'145': 'scrolllock',
'186': 'semicolon',
'187': 'equalsign',
'188': 'comma',
'189': 'dash',
'190': 'period',
'191': 'slash',
'192': 'graveaccent',
'220': 'backslash',
'222': 'quote'
};
BDIpc.send('bd-get-css');