This commit is contained in:
Mirco Wittrien 2019-11-15 21:48:30 +01:00
parent 82da79aba8
commit 243fdc5396
3 changed files with 183 additions and 83 deletions

View File

@ -1373,7 +1373,10 @@ var BDFDB = {
LibraryModules.IconUtils = BDFDB.ModuleUtils.findByProperties("getGuildIconURL", "getGuildBannerURL");
LibraryModules.InviteUtils = BDFDB.ModuleUtils.findByProperties("acceptInvite", "createInvite");
LibraryModules.KeyCodeUtils = Object.assign({}, BDFDB.ModuleUtils.findByProperties("toCombo", "keyToCode"));
LibraryModules.KeyCodeUtils.getString = keyarray => {return LibraryModules.KeyCodeUtils.toString([keyarray].flat().filter(n => n).map(keycode => [BDFDB.DiscordConstants.KeyboardDeviceTypes.KEYBOARD_KEY, keycode, BDFDB.DiscordConstants.KeyboardEnvs.BROWSER]), true)};
LibraryModules.KeyCodeUtils.getString = keyarray => {
return LibraryModules.KeyCodeUtils.toString([keyarray].flat().filter(n => n).map(keycode => [BDFDB.DiscordConstants.KeyboardDeviceTypes.KEYBOARD_KEY, keycode, LibraryModules.KeyCodeUtils.getEnv()]), true)
};
LibraryModules.KeyEvents = BDFDB.ModuleUtils.findByProperties("aliases", "code", "codes");
LibraryModules.LanguageStore = BDFDB.ModuleUtils.findByProperties("getLanguages", "Messages");
LibraryModules.LastChannelStore = BDFDB.ModuleUtils.findByProperties("getLastSelectedChannelId");
LibraryModules.LastGuildStore = BDFDB.ModuleUtils.findByProperties("getLastSelectedGuildId");
@ -1389,6 +1392,7 @@ var BDFDB = {
LibraryModules.NoteStore = BDFDB.ModuleUtils.findByProperties("getNotes", "getNote");
LibraryModules.NotificationSettingsUtils = BDFDB.ModuleUtils.findByProperties("setDesktopType", "setTTSType");
LibraryModules.NotificationSettingsStore = BDFDB.ModuleUtils.findByProperties("getDesktopType", "getTTSType");
LibraryModules.PlatformUtils = BDFDB.ModuleUtils.findByProperties("isWindows", "isLinux");
LibraryModules.PermissionUtils = BDFDB.ModuleUtils.findByProperties("getChannelPermissions", "canUser");
LibraryModules.PermissionRoleUtils = BDFDB.ModuleUtils.findByProperties("getHighestRole", "can");
LibraryModules.ReactionUtils = BDFDB.ModuleUtils.findByProperties("addReaction", "removeReaction");
@ -4013,6 +4017,8 @@ var BDFDB = {
confirmModal: "confirmModal-t-WDWJ",
favButtonContainer: "favbutton-8Fzu45",
guild: "guild-r3yAE_",
hotkeyResetButton: "resetButton-hI9Ax7",
hotkeyWrapper: "recorder-can0vx",
inputNumberButton: "button-J9muv5",
inputNumberButtonDown: "down-cOY7Qp button-J9muv5",
inputNumberButtonUp: "up-mUs_72 button-J9muv5",
@ -4030,7 +4036,7 @@ var BDFDB = {
modalTabContent: "tab-content",
modalTabContentOpen: "open",
modalWrapper: "modal-6GHvdM",
selectWrapper: "selectWrapper-ToUmZ9",
selectWrapper: "selectWrapper-yPjeij",
settingsPanel: "settingsPanel-w2ySNR",
settingsPanelInner: "settingsInner-zw1xAY",
settingsPanelList: "settingsList-eZjkXj",
@ -4930,8 +4936,10 @@ var BDFDB = {
hotkeylayout: ["HotKeyRecorder", "layout"],
hotkeylayout2: ["HotKeyRecorder", "layout"],
hotkeyrecording: ["HotKeyRecorder", "recording"],
hotkeyresetbutton: ["BDFDB", "hotkeyResetButton"],
hotkeyshadowpulse: ["HotKeyRecorder", "shadowPulse"],
hotkeytext: ["HotKeyRecorder", "text"],
hotkeywrapper: ["BDFDB", "hotkeyWrapper"],
hovercard: ["HoverCard", "card"],
hovercardbutton: ["NotFound", "hoverCardButton"],
hovercardinner: ["BDFDB", "cardInner"],
@ -6719,13 +6727,34 @@ var BDFDB = {
LibraryComponents.KeybindRecorder = reactInitialized && class BDFDB_KeybindRecorder extends LibraryModules.React.Component {
handleChange(arrays) {
if (typeof this.props.onChange == "function") this.props.onChange(arrays.map(array => array[1]), this);
if (typeof this.props.onChange == "function") this.props.onChange(arrays.map(platformkey => LibraryModules.KeyEvents.codes[BDFDB.LibraryModules.KeyCodeUtils.codeToKey(platformkey)] || platformkey[1]), this);
}
handleReset() {
this.props.defaultValue = [];
let recorder = BDFDB.ReactUtils.findOwner(this, {name: "KeybindRecorder"});
if (recorder) recorder.setState({codes: []});
if (typeof this.props.onChange == "function") this.props.onChange([], this);
if (typeof this.props.onReset == "function") this.props.onReset(this);
}
render() {
return BDFDB.ReactUtils.createElement(NativeSubComponents.KeybindRecorder, Object.assign({}, this.props, {
defaultValue: [this.props.defaultValue].flat().filter(n => n).map(keycode => [BDFDB.DiscordConstants.KeyboardDeviceTypes.KEYBOARD_KEY, keycode, BDFDB.DiscordConstants.KeyboardEnvs.BROWSER]),
onChange: this.handleChange.bind(this)
}));
return BDFDB.ReactUtils.createElement(LibraryComponents.Flex, {
className: BDFDB.disCN.hotkeywrapper,
direction: LibraryComponents.Flex.Direction.HORIZONTAL,
align: LibraryComponents.Flex.Align.CENTER,
children: [
BDFDB.ReactUtils.createElement(NativeSubComponents.KeybindRecorder, BDFDB.ObjectUtils.exclude(Object.assign({}, this.props, {
defaultValue: [this.props.defaultValue].flat().filter(n => n).map(keycode => [BDFDB.DiscordConstants.KeyboardDeviceTypes.KEYBOARD_KEY, keycode, BDFDB.DiscordConstants.KeyboardEnvs.BROWSER]),
onChange: this.handleChange.bind(this)
}), "reset", "onReset")),
this.props.reset || this.props.onReset ? BDFDB.ReactUtils.createElement(LibraryComponents.Clickable, {
className: BDFDB.disCN.hotkeyresetbutton,
onClick: this.handleReset.bind(this),
children: BDFDB.ReactUtils.createElement(LibraryComponents.SvgIcon, {
iconSVG: `<svg height="20" width="20" viewBox="0 0 20 20"><path fill="currentColor" d="M 14.348 14.849 c -0.469 0.469 -1.229 0.469 -1.697 0 l -2.651 -3.030 -2.651 3.029 c -0.469 0.469 -1.229 0.469 -1.697 0 -0.469 -0.469 -0.469 -1.229 0 -1.697l2.758 -3.15 -2.759 -3.152 c -0.469 -0.469 -0.469 -1.228 0 -1.697 s 1.228 -0.469 1.697 0 l 2.652 3.031 2.651 -3.031 c 0.469 -0.469 1.228 -0.469 1.697 0 s 0.469 1.229 0 1.697l -2.758 3.152 2.758 3.15 c 0.469 0.469 0.469 1.229 0 1.698 z"></path></svg>`,
})
}) : null
].filter(n => n)
});
}
};
@ -7002,10 +7031,14 @@ var BDFDB = {
if (typeof this.props.onChange == "function") this.props.onChange(value, this);
}
render() {
return BDFDB.ReactUtils.createElement(NativeSubComponents.Select, Object.assign({}, this.props, {
className: BDFDB.DOMUtils.formatClassName(this.props.className, BDFDB.disCN.selectwrapper),
onChange: this.handleChange.bind(this)
}));
return BDFDB.ReactUtils.createElement(LibraryComponents.Flex, {
className: BDFDB.disCN.selectwrapper,
direction: LibraryComponents.Flex.Direction.HORIZONTAL,
align: LibraryComponents.Flex.Align.CENTER,
children: BDFDB.ReactUtils.createElement(NativeSubComponents.Select, Object.assign({}, this.props, {
onChange: this.handleChange.bind(this)
}))
});
}
};
@ -7503,14 +7536,24 @@ var BDFDB = {
cursor: pointer !important;
}
${BDFDB.dotCN.selectwrapper} {
${BDFDB.dotCNS.selectwrapper + BDFDB.dotCN.selectwrap} {
flex: 1 1 auto;
}
${BDFDB.dotCN.selectwrapper} > [class*="css-"][class*="-container"] > [class*="css-"][class*="-menu"] {
${BDFDB.dotCN.selectwrapper} [class*="css-"][class*="-container"] > [class*="css-"][class*="-menu"] {
z-index: 3;
}
${BDFDB.dotCNS.hotkeywrapper + BDFDB.dotCN.hotkeycontainer} {
flex: 1 1 auto;
}
${BDFDB.dotCN.hotkeyresetbutton} {
cursor: pointer;
margin-left: 5px;
}
${BDFDB.dotCNS.hotkeyresetbutton + BDFDB.dotCN.svgicon}:hover {
color: ${BDFDB.DiscordConstants.Colors.STATUS_RED};
}
${BDFDB.dotCNS.hovercardwrapper + BDFDB.dotCN.hovercardbutton} {
position: absolute;
top: -3px;

File diff suppressed because one or more lines are too long

View File

@ -3,16 +3,20 @@
class MessageUtilities {
getName () {return "MessageUtilities";}
getVersion () {return "1.5.9";}
getVersion () {return "1.6.0";}
getAuthor () {return "DevilBro";}
getDescription () {return "Offers a number of useful message options. Remap the keybindings in the settings.";}
constructor () {
this.changelog = {
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
};
this.patchedModules = {
after: {
"MessageContextMenu":["componentDidMount","componentDidUpdate"]
MessageContextMenu: ["componentDidMount","componentDidUpdate"]
}
};
}
@ -22,13 +26,8 @@ class MessageUtilities {
this.firedEvents = [];
this.clickMap = ["CLICK" /*[0]*/, "DBLCLICK" /*[1]*/];
this.clickMap = ["CLICK", "DBLCLICK"];
this.keyboardMap = [
"NONE" /*[0]*/, "" /*[1]*/, "" /*[2]*/, "CANCEL" /*[3]*/, "" /*[4]*/, "" /*[5]*/, "HELP" /*[6]*/, "" /*[7]*/, "BACK_SPACE" /*[8]*/, "TAB" /*[9]*/, "" /*[10]*/, "" /*[11]*/, "CLEAR" /*[12]*/, "ENTER" /*[13]*/, "ENTER_SPECIAL" /*[14]*/, "" /*[15]*/, "SHIFT" /*[16]*/, "CONTROL" /*[17]*/, "ALT" /*[18]*/, "PAUSE" /*[19]*/, "CAPS_LOCK" /*[20]*/, "KANA" /*[21]*/, "EISU" /*[22]*/, "JUNJA" /*[23]*/, "FINAL" /*[24]*/, "HANJA" /*[25]*/, "" /*[26]*/, "ESCAPE" /*[27]*/, "CONVERT" /*[28]*/, "NONCONVERT" /*[29]*/, "ACCEPT" /*[30]*/, "MODECHANGE" /*[31]*/, "SPACE" /*[32]*/, "PAGE_UP" /*[33]*/, "PAGE_DOWN" /*[34]*/, "END" /*[35]*/, "HOME" /*[36]*/, "LEFT" /*[37]*/, "UP" /*[38]*/, "RIGHT" /*[39]*/, "DOWN" /*[40]*/, "SELECT" /*[41]*/, "PRINT" /*[42]*/, "EXECUTE" /*[43]*/, "PRINTSCREEN" /*[44]*/, "INSERT" /*[45]*/, "DELETE" /*[46]*/, "" /*[47]*/,"0" /*[48]*/, "1" /*[49]*/, "2" /*[50]*/, "3" /*[51]*/, "4" /*[52]*/, "5" /*[53]*/, "6" /*[54]*/, "7" /*[55]*/, "8" /*[56]*/, "9" /*[57]*/, "COLON" /*[58]*/, "SEMICOLON" /*[59]*/, "LESS_THAN" /*[60]*/, "EQUALS" /*[61]*/, "GREATER_THAN" /*[62]*/, "QUESTION_MARK" /*[63]*/, "AT" /*[64]*/, "A" /*[65]*/, "B" /*[66]*/, "C" /*[67]*/, "D" /*[68]*/, "E" /*[69]*/, "F" /*[70]*/, "G" /*[71]*/, "H" /*[72]*/, "I" /*[73]*/, "J" /*[74]*/, "K" /*[75]*/, "L" /*[76]*/, "M" /*[77]*/, "N" /*[78]*/, "O" /*[79]*/, "P" /*[80]*/, "Q" /*[81]*/, "R" /*[82]*/, "S" /*[83]*/, "T" /*[84]*/, "U" /*[85]*/, "V" /*[86]*/, "W" /*[87]*/, "X" /*[88]*/, "Y" /*[89]*/, "Z" /*[90]*/, "OS_KEY" /*[91]*/, "" /*[92]*/, "CONTEXT_MENU" /*[93]*/, "" /*[94]*/, "SLEEP" /*[95]*/, "NUMPAD0" /*[96]*/, "NUMPAD1" /*[97]*/, "NUMPAD2" /*[98]*/, "NUMPAD3" /*[99]*/, "NUMPAD4" /*[100]*/, "NUMPAD5" /*[101]*/, "NUMPAD6" /*[102]*/, "NUMPAD7" /*[103]*/, "NUMPAD8" /*[104]*/, "NUMPAD9" /*[105]*/, "MULTIPLY" /*[106]*/, "ADD" /*[107]*/, "SEPARATOR" /*[108]*/, "SUBTRACT" /*[109]*/, "DECIMAL" /*[110]*/, "DIVIDE" /*[111]*/, "F1" /*[112]*/, "F2" /*[113]*/, "F3" /*[114]*/, "F4" /*[115]*/, "F5" /*[116]*/, "F6" /*[117]*/, "F7" /*[118]*/, "F8" /*[119]*/, "F9" /*[120]*/, "F10" /*[121]*/, "F11" /*[122]*/, "F12" /*[123]*/, "F13" /*[124]*/, "F14" /*[125]*/, "F15" /*[126]*/, "F16" /*[127]*/, "F17" /*[128]*/, "F18" /*[129]*/, "F19" /*[130]*/, "F20" /*[131]*/, "F21" /*[132]*/, "F22" /*[133]*/, "F23" /*[134]*/, "F24" /*[135]*/, "" /*[136]*/, "" /*[137]*/, "" /*[138]*/, "" /*[139]*/, "" /*[140]*/, "" /*[141]*/, "" /*[142]*/, "" /*[143]*/, "NUM_LOCK" /*[144]*/, "SCROLL_LOCK" /*[145]*/, "WIN_OEM_FJ_JISHO" /*[146]*/, "WIN_OEM_FJ_MASSHOU" /*[147]*/, "WIN_OEM_FJ_TOUROKU" /*[148]*/, "WIN_OEM_FJ_LOYA" /*[149]*/, "WIN_OEM_FJ_ROYA" /*[150]*/, "" /*[151]*/, "" /*[152]*/, "" /*[153]*/, "" /*[154]*/, "" /*[155]*/, "" /*[156]*/, "" /*[157]*/, "" /*[158]*/, "" /*[159]*/, "CIRCUMFLEX" /*[160]*/, "EXCLAMATION" /*[161]*/, "DOUBLE_QUOTE" /*[162]*/, "HASH" /*[163]*/, "DOLLAR" /*[164]*/, "PERCENT" /*[165]*/, "AMPERSAND" /*[166]*/, "UNDERSCORE" /*[167]*/, "OPEN_PAREN" /*[168]*/, "CLOSE_PAREN" /*[169]*/, "ASTERISK" /*[170]*/, "PLUS" /*[171]*/, "PIPE" /*[172]*/, "HYPHEN_MINUS" /*[173]*/, "OPEN_CURLY_BRACKET" /*[174]*/, "CLOSE_CURLY_BRACKET" /*[175]*/, "TILDE" /*[176]*/, "" /*[177]*/, "" /*[178]*/, "" /*[179]*/, "" /*[180]*/, "VOLUME_MUTE" /*[181]*/, "VOLUME_DOWN" /*[182]*/, "VOLUME_UP" /*[183]*/, "" /*[184]*/, "" /*[185]*/, "SEMICOLON" /*[186]*/, "EQUALS" /*[187]*/, "COMMA" /*[188]*/, "MINUS" /*[189]*/, "PERIOD" /*[190]*/, "SLASH" /*[191]*/, "BACK_QUOTE" /*[192]*/, "" /*[193]*/, "" /*[194]*/, "" /*[195]*/, "" /*[196]*/, "" /*[197]*/, "" /*[198]*/, "" /*[199]*/, "" /*[200]*/, "" /*[201]*/, "" /*[202]*/, "" /*[203]*/, "" /*[204]*/, "" /*[205]*/, "" /*[206]*/, "" /*[207]*/, "" /*[208]*/, "" /*[209]*/, "" /*[210]*/, "" /*[211]*/, "" /*[212]*/, "" /*[213]*/, "" /*[214]*/, "" /*[215]*/, "" /*[216]*/, "" /*[217]*/, "" /*[218]*/, "OPEN_BRACKET" /*[219]*/, "BACK_SLASH" /*[220]*/, "CLOSE_BRACKET" /*[221]*/, "QUOTE" /*[222]*/, "" /*[223]*/, "META" /*[224]*/, "ALTGR" /*[225]*/, "" /*[226]*/, "WIN_ICO_HELP" /*[227]*/, "WIN_ICO_00" /*[228]*/, "" /*[229]*/, "WIN_ICO_CLEAR" /*[230]*/, "" /*[231]*/,"" /*[232]*/, "WIN_OEM_RESET" /*[233]*/, "WIN_OEM_JUMP" /*[234]*/, "WIN_OEM_PA1" /*[235]*/, "WIN_OEM_PA2" /*[236]*/, "WIN_OEM_PA3" /*[237]*/, "WIN_OEM_WSCTRL" /*[238]*/,"WIN_OEM_CUSEL" /*[239]*/, "WIN_OEM_ATTN" /*[240]*/, "WIN_OEM_FINISH" /*[241]*/, "WIN_OEM_COPY" /*[242]*/, "WIN_OEM_AUTO" /*[243]*/, "WIN_OEM_ENLW" /*[244]*/, "WIN_OEM_BACKTAB" /*[245]*/, "ATTN" /*[246]*/, "CRSEL" /*[247]*/, "EXSEL" /*[248]*/, "EREOF" /*[249]*/, "PLAY" /*[250]*/, "ZOOM" /*[251]*/, "" /*[252]*/, "PA1" /*[253]*/, "WIN_OEM_CLEAR" /*[254]*/, "" /*[255]*/
];
this.keys = ["key1","key2"];
this.defaults = {
settings: {
"addHints": {value:true, description:"Add keycombo hints to contextmenus:"},
@ -36,17 +35,17 @@ class MessageUtilities {
},
toasts: {},
bindings: {
"Edit_Message": {name:"Edit Message", func:this.doEdit, value:{click:1, key1:0, key2:0}},
"Delete_Message": {name:"Delete Message", func:this.doDelete, value:{click:0, key1:46, key2:0}},
"Pin/Unpin_Message": {name:"Pin/Unpin Message", func:this.doPinUnPin, value:{click:0, key1:17, key2:0}},
"React_to_Message": {name:"React to Message", func:this.doOpenReact, value:{click:0, key1:17, key2:83}},
"Copy_Raw": {name:"Copy raw Message", func:this.doCopyRaw, value:{click:0, key1:17, key2:68}},
"Copy_Link": {name:"Copy Message Link", func:this.doCopyLink, value:{click:0, key1:17, key2:81}},
"__Note_Message": {name:"Note Message (Pesonal Pins)", func:this.doNote, value:{click:0, key1:16, key2:0}, plugin:"PersonalPins"},
"__Translate_Message": {name:"Translate Message (Google Translate Option)", func:this.doTranslate, value:{click:0, key1:20, key2:0}, plugin:"GoogleTranslateOption"},
"__Quote_Message": {name:"Quote Message (Quoter)", func:this.doQuote, value:{click:0, key1:17, key2:87}, plugin:"Quoter"},
"__Citate_Message": {name:"Quote Message (Citador)", func:this.doCitate, value:{click:0, key1:17, key2:78}, plugin:"Citador"},
"__Reveal_Spoilers": {name:"Reveal All Spoilers (RevealAllSpoilersOption)", func:this.doReveal, value:{click:0, key1:17, key2:74}, plugin:"RevealAllSpoilersOption"}
"Edit_Message": {name:"Edit Message", func:this.doEdit, value:{click:1, keycombo:[]} },
"Delete_Message": {name:"Delete Message", func:this.doDelete, value:{click:0, keycombo:[46]} },
"Pin/Unpin_Message": {name:"Pin/Unpin Message", func:this.doPinUnPin, value:{click:0, keycombo:[17]} },
"React_to_Message": {name:"React to Message", func:this.doOpenReact, value:{click:0, keycombo:[17,83]} },
"Copy_Raw": {name:"Copy raw Message", func:this.doCopyRaw, value:{click:0, keycombo:[17,68]} },
"Copy_Link": {name:"Copy Message Link", func:this.doCopyLink, value:{click:0, keycombo:[17,81]} },
"__Note_Message": {name:"Note Message (Pesonal Pins)", func:this.doNote, value:{click:0, keycombo:[16]}, plugin:"PersonalPins"},
"__Translate_Message": {name:"Translate Message (Google Translate Option)", func:this.doTranslate, value:{click:0, keycombo:[20]}, plugin:"GoogleTranslateOption"},
"__Quote_Message": {name:"Quote Message (Quoter)", func:this.doQuote, value:{click:0, keycombo:[17,87]}, plugin:"Quoter"},
"__Citate_Message": {name:"Quote Message (Citador)", func:this.doCitate, value:{click:0, keycombo:[17,78]}, plugin:"Citador"},
"__Reveal_Spoilers": {name:"Reveal All Spoilers (RevealAllSpoilersOption)", func:this.doReveal, value:{click:0, keycombo:[17,74]}, plugin:"RevealAllSpoilersOption"}
}
};
for (let type in this.defaults.bindings) {
@ -57,6 +56,92 @@ class MessageUtilities {
}
getSettingsPanel () {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
let settings = BDFDB.DataUtils.get(this, "settings");
let bindings = BDFDB.DataUtils.get(this, "bindings");
let toasts = BDFDB.DataUtils.get(this, "toasts");
let settingsitems = [];
for (let key in settings) if (this.defaults.settings[key].description) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
className: BDFDB.disCN.marginbottom8,
type: "Switch",
plugin: this,
keys: ["settings", key],
label: this.defaults.settings[key].description,
value: settings[key]
}));
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
className: BDFDB.disCN.marginbottom8
}));
for (let action in bindings) if (!this.defaults.bindings[action].plugin || BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings[action].plugin)) {
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
className: BDFDB.disCN.marginbottom8,
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsLabel, {
label: this.defaults.bindings[action].name
}),
toasts[action] != undefined ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
mini: true,
plugin: this,
keys: ["toasts", action],
grow: 0,
label: "Toast:",
value: toasts[action]
}) : null
].filter(n => n)
}));
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
className: BDFDB.disCN.marginbottom8,
type: "Switch",
dividerbottom: true,
mini: true,
plugin: this,
keys: ["settings", action],
value: settings[action],
labelchildren: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Select, {
value: bindings[action].click,
options: this.clickMap.map((label, i) => {return {value:i, label:label}}),
onChange: choice => {
bindings[action].click = choice.value;
BDFDB.DataUtils.save(bindings, this, "bindings");
}
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.KeybindRecorder, {
defaultValue: bindings[action].keycombo.filter(n => n),
reset: true,
onChange: keycombo => {
bindings[action].keycombo = keycombo;
BDFDB.DataUtils.save(bindings, this, "bindings");
}
})
]
})
}));
}
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button",
className: BDFDB.disCN.marginbottom8,
color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Reset all Key Bindings",
onClick: (e, instance) => {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all Key Bindings?", _ => {
BDFDB.DataUtils.remove(this, "bindings");
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(instance, {key: `${this.name}-settingspanel`, up: true}));
});
},
children: BDFDB.LanguageUtils.LanguageStrings.RESET
}));
return BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
}
getSettingsPanel2 () {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
let settings = BDFDB.DataUtils.get(this, "settings");
let toasts = BDFDB.DataUtils.get(this, "toasts");
@ -121,6 +206,13 @@ class MessageUtilities {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
BDFDB.PluginUtils.init(this);
// REMOVE 15.11.2019
let bindings = BDFDB.DataUtils.load(this, "bindings");
if (bindings[Object.keys(bindings)[0]].keycombo == undefined) {
for (let key in bindings) bindings[key] = {click: bindings[key].click, keycombo: [bindings[key].key1, bindings[key].key2].filter(n => n)};
BDFDB.DataUtils.save(bindings, this, "bindings");
}
BDFDB.ListenerUtils.add(this, document, "click", BDFDB.dotCN.messagegroup + "> [aria-disabled]," + BDFDB.dotCN.messagegroup + "> * > [aria-disabled]," + BDFDB.dotCN.messagesystem, e => {
this.onClick(e, 0, "onSglClick");
@ -146,12 +238,11 @@ class MessageUtilities {
//begin of own functions
processMessageContextMenu (instance, menu, returnvalue) {
if (instance.props.message && instance.props.channel && instance.props.target) {
let changed = false;
for (let itemlabel of menu.querySelectorAll(BDFDB.dotCN.contextmenulabel)) {
processMessageContextMenu (e) {
if (e.instance.props.message && e.instance.props.channel && e.instance.props.target) {
for (let itemlabel of e.node.querySelectorAll(BDFDB.dotCN.contextmenulabel)) {
let hint = itemlabel.parentElement.querySelector(BDFDB.dotCN.contextmenuhint);
if (hint && !BDFDB.DOMUtils.containsClass(hint, "BDFDB-contextMenuItemHint")) {
if (hint) {
let action = null;
switch (itemlabel.innerText) {
case BDFDB.LanguageUtils.LanguageStrings.COPY_MESSAGE_LINK:
@ -179,42 +270,9 @@ class MessageUtilities {
}
}
}
if (changed) BDFDB.initElements(menu);
}
}
resetAll (settingspanel) {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to delete all key bindings?", () => {
BDFDB.DataUtils.remove(this, "bindings");
let bindings = BDFDB.DataUtils.get(this, "bindings");
settingspanel.querySelectorAll(BDFDB.dotCN.select).forEach(wrap => {
let type = wrap.getAttribute("type").split(" ");
wrap.setAttribute("value", bindings[type[0]][type[1]]);
wrap.querySelector(BDFDB.dotCN.title).innerText = this.clickMap[bindings[type[0]][type[1]]];
});
settingspanel.querySelectorAll(BDFDB.dotCN.hotkeycontainer).forEach(wrap => {
let action = wrap.getAttribute("type");
let option = wrap.getAttribute("option");
wrap.setAttribute("value", bindings[action][option]);
wrap.querySelector("input").setAttribute("value", this.keyboardMap[bindings[action][option]]);
});
});
}
saveSelectChoice (selectWrap, type, choice) {
if (type && choice) {
selectWrap.querySelector(BDFDB.dotCN.title).innerText = this.clickMap[choice];
type = type.split(" ");
let binding = BDFDB.DataUtils.get(this, "bindings", type[0]);
binding[type[1]] = parseInt(choice);
BDFDB.DataUtils.save(binding, this, "bindings", type[0]);
}
}
createSelectChoice (key) {
return `<div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.primary + BDFDB.disCNS.weightnormal + BDFDB.disCN.cursorpointer}" style="padding: 0;">${this.clickMap[key]}</div>`;
}
startRecording (settingspanel, e) {
let recorderWrap = e.currentTarget;
if (BDFDB.DOMUtils.containsClass(recorderWrap, BDFDB.disCN.hotkeyrecording)) return;
@ -273,7 +331,7 @@ class MessageUtilities {
for (let action in bindings) {
let binding = bindings[action];
let prioritybinding = bindings[priorityaction];
if (this.checkIfBindingIsValid(binding, click) && (!bindings[priorityaction] || binding.click > prioritybinding.click || binding.key2 != 0 && prioritybinding.key2 == 0)) priorityaction = action;
if (this.checkIfBindingIsValid(binding, click) && (!bindings[priorityaction] || binding.click > prioritybinding.click || binding.keycombo.length > prioritybinding.keycombo.length)) priorityaction = action;
}
if (priorityaction) {
let {messagediv, pos, message} = this.getMessageData(e.currentTarget);
@ -281,10 +339,10 @@ class MessageUtilities {
BDFDB.ListenerUtils.stopEvent(e);
BDFDB.TimeUtils.clear(this.clickTimeout);
if (!this.hasDoubleClickOverwrite(bindings, bindings[priorityaction])) {
this.defaults.bindings[priorityaction].func.bind(this)({messagediv, pos, message}, priorityaction);
this.defaults.bindings[priorityaction].func.apply(this, [{messagediv, pos, message}, priorityaction]);
}
else this.clickTimeout = BDFDB.TimeUtils.timeout(() => {
this.defaults.bindings[priorityaction].func.bind(this)({messagediv, pos, message}, priorityaction);
this.defaults.bindings[priorityaction].func.apply(this, [{messagediv, pos, message}, priorityaction]);
}, 500);
}
}
@ -295,7 +353,7 @@ class MessageUtilities {
checkIfBindingIsValid (binding, doneclick) {
let valid = true;
if (binding.click != doneclick) valid = false;
for (let key of this.keys) if (!BDFDB.pressedKeys.includes(binding[key]) && binding[key] != 0) valid = false;
for (let key of binding.keycombo) if (!BDFDB.InternalData.pressedKeys.includes(key)) valid = false;
return valid;
}
@ -305,8 +363,7 @@ class MessageUtilities {
for (let dblaction in dblbindings) {
let dblbndg = dblbindings[dblaction];
let overwrite = true;
for (let key of this.keys) if (binding[key] != dblbndg[key]) overwrite = false;
if (overwrite) return true;
if (BDFDB.equals(binding.keycombo, dblbndg.keycombo)) return true;
}
return false;
}
@ -419,12 +476,12 @@ class MessageUtilities {
let str = "", settings = BDFDB.DataUtils.get(this, "settings");
if (settings.addHints && settings[action]) {
let binding = BDFDB.DataUtils.get(this, "bindings", action);
if (binding) for (let type in binding) {
let typename = type == "click" ? this.clickMap[binding[type]] : this.keyboardMap[binding[type]];
if (typename && typename != "NONE") str += typename + "+";
if (binding) {
str += this.clickMap(binding.click);
if (binding.keycombo.length) str += " + " + BDFDB.LibraryModules.KeyCodeUtils.getString(binding.keycombo);
}
}
return str ? str.slice(0,-1) : null;
return str.replace(/ /g, "");
}
getMessageData (target) {
@ -444,6 +501,6 @@ class MessageUtilities {
}
cancelEvent (name) {
BDFDB.TimeUtils.timeout(() => {BDFDB.ArrayUtils.remove(this.firedEvents, name)});
BDFDB.TimeUtils.timeout(_ => {BDFDB.ArrayUtils.remove(this.firedEvents, name)});
}
}