This commit is contained in:
Mirco Wittrien 2022-10-14 09:01:48 +02:00
parent d298e9191b
commit 1323c482e6
6 changed files with 29 additions and 45 deletions

View File

@ -82,31 +82,28 @@ module.exports = (_ => {
hint: hint && (_ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuHint, {
hint: hint
})),
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN.menuicon,
name: BDFDB.LibraryComponents.SvgIcon.Names.RAW_TEXT
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuIcon, {
icon: BDFDB.LibraryComponents.SvgIcon.Names.RAW_TEXT
}),
action: _ => BDFDB.LibraryRequires.electron.clipboard.write({text: messageString})
action: _ => BDFDB.LibraryModules.WindowUtils.copy(messageString)
}),
embedString && BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw Embed)",
id: BDFDB.ContextMenuUtils.createItemId(this.name, "copy-embed"),
type: "Embed",
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN.menuicon,
name: BDFDB.LibraryComponents.SvgIcon.Names.RAW_TEXT
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuIcon, {
icon: BDFDB.LibraryComponents.SvgIcon.Names.RAW_TEXT
}),
action: _ => BDFDB.LibraryRequires.electron.clipboard.write({text: embedString})
action: _ => BDFDB.LibraryModules.WindowUtils.copy(embedString)
}),
embedData && BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Embed JSON)",
type: "Embed JSON",
id: BDFDB.ContextMenuUtils.createItemId(this.name, "copy-embed-json"),
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN.menuicon,
name: BDFDB.LibraryComponents.SvgIcon.Names.RAW_TEXT
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuIcon, {
icon: BDFDB.LibraryComponents.SvgIcon.Names.RAW_TEXT
}),
action: _ => BDFDB.LibraryRequires.electron.clipboard.write({text: JSON.stringify(embedData)})
action: _ => BDFDB.LibraryModules.WindowUtils.copy(JSON.stringify(embedData))
})
].filter(n => n);
if (entries.length) {
@ -134,11 +131,10 @@ module.exports = (_ => {
children.splice(index + 1, 0, BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LanguageStrings.COPY_TEXT + " (Raw)",
id: BDFDB.ContextMenuUtils.createItemId(this.name, "copy-message-raw"),
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN.menuicon,
name: BDFDB.LibraryComponents.SvgIcon.Names.RAW_TEXT
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuIcon, {
icon: BDFDB.LibraryComponents.SvgIcon.Names.RAW_TEXT
}),
action: _ => BDFDB.LibraryRequires.electron.clipboard.write({text: e.instance.props.message.content})
action: _ => BDFDB.LibraryModules.WindowUtils.copy(e.instance.props.message.content)
}));
}
}
@ -151,7 +147,7 @@ module.exports = (_ => {
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
className: BDFDB.disCN.messagetoolbarbutton,
onClick: _ => {
BDFDB.LibraryRequires.electron.clipboard.write({text: e.instance.props.message.content});
BDFDB.LibraryModules.WindowUtils.copy(e.instance.props.message.content);
},
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN.messagetoolbaricon,

View File

@ -364,7 +364,7 @@ module.exports = (_ => {
let text = this.parseQuote(message, channel);
if (text && text.length) {
if (shift && !this.settings.general.alwaysCopy || !shift && this.settings.general.alwaysCopy || !(BDFDB.DMUtils.isDMChannel(channel.id) || BDFDB.UserUtils.can("SEND_MESSAGES"))) {
BDFDB.LibraryRequires.electron.clipboard.write({text: text});
BDFDB.LibraryModules.WindowUtils.copy(text);
BDFDB.NotificationUtils.toast(this.labels.toast_quotecopied, {type: "success"});
}
else BDFDB.LibraryModules.DispatchUtils.ComponentDispatch.dispatchToLastSubscribed(BDFDB.DiscordConstants.ComponentActions.INSERT_TEXT, {

View File

@ -2,7 +2,7 @@
* @name ImageUtilities
* @author DevilBro
* @authorId 278543574059057154
* @version 4.8.8
* @version 4.8.9
* @description Adds several Utilities for Images/Videos (Gallery, Download, Reverse Search, Zoom, Copy, etc.)
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -14,6 +14,7 @@
module.exports = (_ => {
const changeLog = {
};
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
@ -789,7 +790,7 @@ module.exports = (_ => {
label: BDFDB.LanguageUtils.LanguageStrings.COPY_LINK,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "copy-link"),
action: _ => {
BDFDB.LibraryRequires.electron.clipboard.write({text: urlData.original});
BDFDB.LibraryModules.WindowUtils.copy(urlData.original);
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LanguageStrings.LINK_COPIED, {type: "success"});
}
}),
@ -797,7 +798,7 @@ module.exports = (_ => {
label: BDFDB.LanguageUtils.LanguageStrings.COPY_MEDIA_LINK,
id: BDFDB.ContextMenuUtils.createItemId(this.name, "copy-media-link"),
action: _ => {
BDFDB.LibraryRequires.electron.clipboard.write({text: urlData.file});
BDFDB.LibraryModules.WindowUtils.copy(urlData.file);
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LanguageStrings.LINK_COPIED, {type: "success"});
}
}),
@ -1456,22 +1457,9 @@ module.exports = (_ => {
}
copyFile (url) {
BDFDB.LibraryRequires.request(url, {agentOptions: {rejectUnauthorized: false}, encoding: null}, (error, response, body) => {
let type = this.isValid(url, "video") ? BDFDB.LanguageUtils.LanguageStrings.VIDEO : BDFDB.LanguageUtils.LanguageStrings.IMAGE;
if (error) BDFDB.NotificationUtils.toast(this.labels.toast_copy_failed.replace("{{var0}}", type), {type: "danger"});
else if (body) {
if (BDFDB.LibraryRequires.process.platform === "win32" || BDFDB.LibraryRequires.process.platform === "darwin") {
BDFDB.LibraryRequires.electron.clipboard.write({image: BDFDB.LibraryRequires.electron.nativeImage.createFromBuffer(body)});
}
else {
let file = BDFDB.LibraryRequires.path.join(BDFDB.LibraryRequires.process.env.USERPROFILE || BDFDB.LibraryRequires.process.env.HOMEPATH || BDFDB.LibraryRequires.process.env.HOME, "imageutilstempimg.png");
BDFDB.LibraryRequires.fs.writeFileSync(file, body, {encoding: null});
BDFDB.LibraryRequires.electron.clipboard.write({image: file});
BDFDB.LibraryRequires.fs.unlinkSync(file);
}
BDFDB.NotificationUtils.toast(this.labels.toast_copy_success.replace("{{var0}}", type), {type: "success"});
}
});
let type = this.isValid(url, "video") ? BDFDB.LanguageUtils.LanguageStrings.VIDEO : BDFDB.LanguageUtils.LanguageStrings.IMAGE;
BDFDB.LibraryModules.WindowUtils.copyImage(url);
BDFDB.NotificationUtils.toast(this.labels.toast_copy_success.replace("{{var0}}", type), {type: "success"});
}
getDownloadLocation () {

View File

@ -407,7 +407,7 @@ module.exports = (_ => {
doCopyRaw ({messageDiv, message}, action, event) {
if (message.content) {
BDFDB.LibraryRequires.electron.clipboard.write({text: message.content});
BDFDB.LibraryModules.WindowUtils.copy(message.content);
if (this.settings.toasts[action]) BDFDB.NotificationUtils.toast(this.formatToast(BDFDB.LanguageUtils.LanguageStrings.COPIED_TEXT), {type: "success"});
}
}

View File

@ -188,18 +188,18 @@ module.exports = (_ => {
if (message.content || message.attachments.length > 1) {
let text = message.content || "";
for (let attachment of message.attachments) if (attachment.url) text += ((text ? "\n" : "") + attachment.url);
BDFDB.LibraryRequires.electron.clipboard.write({text});
BDFDB.LibraryModules.WindowUtils.copy(text);
}
else if (message.attachments.length == 1 && message.attachments[0].url) {
BDFDB.LibraryRequires.request(message.attachments[0].url, {encoding: null}, (error, response, body) => {
if (body) {
if (BDFDB.LibraryRequires.process.platform === "win32" || BDFDB.LibraryRequires.process.platform === "darwin") {
BDFDB.LibraryRequires.electron.clipboard.write({image: BDFDB.LibraryRequires.electron.nativeImage.createFromBuffer(body)});
BDFDB.LibraryModules.WindowUtils.copyImage(BDFDB.LibraryRequires.electron.nativeImage.createFromBuffer(body));
}
else {
let file = BDFDB.LibraryRequires.path.join(BDFDB.LibraryRequires.process.env.USERPROFILE || BDFDB.LibraryRequires.process.env.HOMEPATH || BDFDB.LibraryRequires.process.env.HOME, "personalpinstemp.png");
BDFDB.LibraryRequires.fs.writeFileSync(file, body, {encoding: null});
BDFDB.LibraryRequires.electron.clipboard.write({image: file});
BDFDB.LibraryModules.WindowUtils.copyImage(file);
BDFDB.LibraryRequires.fs.unlinkSync(file);
}
}

View File

@ -207,12 +207,12 @@ module.exports = (_ => {
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LibraryStringsFormat("copy", BDFDB.LanguageUtils.LanguageStrings.USER_SETTINGS_LABEL_USERNAME),
id: BDFDB.ContextMenuUtils.createItemId(_this.name, "copy-name"),
action: _ => BDFDB.LibraryRequires.electron.clipboard.write({text: c.name})
action: _ => BDFDB.LibraryModules.WindowUtils.copy(c.name)
}),
url && BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LibraryStringsFormat("copy", BDFDB.LanguageUtils.LanguageStrings.SEARCH_ANSWER_HAS_LINK),
id: BDFDB.ContextMenuUtils.createItemId(_this.name, "copy-url"),
action: _ => BDFDB.LibraryRequires.electron.clipboard.write({text: url})
action: _ => BDFDB.LibraryModules.WindowUtils.copy(url)
})
]
}));
@ -293,12 +293,12 @@ module.exports = (_ => {
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LibraryStringsFormat("copy", BDFDB.LanguageUtils.LanguageStrings.USER_SETTINGS_LABEL_USERNAME),
id: BDFDB.ContextMenuUtils.createItemId(_this.name, "copy-name"),
action: _ => BDFDB.LibraryRequires.electron.clipboard.write({text: c.name})
action: _ => BDFDB.LibraryModules.WindowUtils.copy(c.name)
}),
url && BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
label: BDFDB.LanguageUtils.LibraryStringsFormat("copy", BDFDB.LanguageUtils.LanguageStrings.SEARCH_ANSWER_HAS_LINK),
id: BDFDB.ContextMenuUtils.createItemId(_this.name, "copy-url"),
action: _ => BDFDB.LibraryRequires.electron.clipboard.write({text: url})
action: _ => BDFDB.LibraryModules.WindowUtils.copy(url)
})
]
}));