-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (68 loc) · 1.72 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const {
Plugin
} = require("powercord/entities");
const {
clipboard
} = require("electron");
const {
getModule,
React
} = require("powercord/webpack");
const {
inject,
uninject
} = require('powercord/injector');
const {
getOwnerInstance
} = require('powercord/util');
const {
ContextMenu: {
Button
}
} = require("powercord/components");
const settings = require("./components/settings");
module.exports = class Upload extends Plugin {
startPlugin() {
this.registerSettings("shorten-url", "Shorten URL", settings);
this._injectContextMenu();
}
pluginWillUnload() {
uninject("shorten-url")
}
async upload(url) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = (() => {
if (xhr.readyState == 4 && xhr.status == 200) {
if (this.settings.get("copy")) {
clipboard.writeText(xhr.response)
}
}
})
xhr.open("POST", "https://" + this.settings.get("domain"))
xhr.setRequestHeader("Content-Type", "application/json")
xhr.send(JSON.stringify({
url: url
}))
}
async _injectContextMenu() {
const menu = await getModule(["MenuItem"])
const mdl = await getModule(m => m.default && m.default.displayName === 'MessageContextMenu');
inject('shorten-url', mdl, 'default', ([{
target
}], res) => {
if (target.tagName.toLowerCase() === 'img') {
res.props.children.splice(4, 0,
React.createElement(menu.MenuItem, {
name: "Shorten URL",
separate: false,
id: "shorten-url",
label: "Shorten URL",
action: () => this.upload(target.src)
})
);
}
return res;
});
mdl.default.displayName = 'MessageContextMenu';
}
};