mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-09 06:33:03 -04:00
add ViewRaw plugin & MiniPopover API (#275)
Co-authored-by: Vendicated <vendicated@riseup.net>
This commit is contained in:
parent
06d32ae414
commit
4760af7f0e
9 changed files with 318 additions and 56 deletions
|
@ -16,7 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { React } from "@webpack/common";
|
||||
import { Clipboard, React, Toasts } from "@webpack/common";
|
||||
|
||||
/**
|
||||
* Makes a lazy function. On first call, the value is computed.
|
||||
|
@ -175,5 +175,25 @@ export function suppressErrors<F extends Function>(name: string, func: F, thisOb
|
|||
*/
|
||||
export function makeCodeblock(text: string, language?: string) {
|
||||
const chars = "```";
|
||||
return `${chars}${language || ""}\n${text}\n${chars}`;
|
||||
return `${chars}${language || ""}\n${text.replaceAll("```", "\\`\\`\\`")}\n${chars}`;
|
||||
}
|
||||
|
||||
export function copyWithToast(text: string, toastMessage = "Copied to clipboard!") {
|
||||
if (Clipboard.SUPPORTS_COPY) {
|
||||
Clipboard.copy(text);
|
||||
} else {
|
||||
toastMessage = "Your browser does not support copying to clipboard";
|
||||
}
|
||||
Toasts.show({
|
||||
message: toastMessage,
|
||||
id: Toasts.genId(),
|
||||
type: Toasts.Type.SUCCESS
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if obj is a true object: of type "object" and not null or array
|
||||
*/
|
||||
export function isObject(obj: unknown): obj is object {
|
||||
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue