This repository has been archived by the owner on Aug 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
56 lines (52 loc) · 2.18 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
const { Plugin } = require('powercord/entities');
const { getModule, React } = require('powercord/webpack');
const { findInReactTree } = require('powercord/util');
const { inject, uninject } = require('powercord/injector');
const { open: openModal } = require('powercord/modal');
const Model = require('./Components/Model');
const Settings = require('./Components/Settings');
module.exports = class CoolMF extends Plugin {
startPlugin() {
this.loadStylesheet('style.scss');
powercord.api.settings.registerSettings(this.entityID, {
category: this.entityID,
label: 'Github in discord',
render: Settings,
});
const Menu = getModule(['MenuGroup', 'MenuItem'], false);
const MessageContextMenu = getModule(m => m.default?.displayName === 'MessageContextMenu', false);
inject('Gmodel-context-menu', MessageContextMenu, 'default', (args, res) => {
if (!args[0].message.content.includes('https://github.com/') && !args[0].message.content.includes('https://www.github.com/')) return res;
const githubURL = args[0].message.content
.replace('tree', 'blob')
.replace(/(?:\n|<|>|\*|_|`)/g, ' ')
.split(' ')
.filter(f => f.match(/^https?:\/\/(www.)?github.com\/[\w-]+\/[\w-]+\/?/));
if (githubURL[0].split('/').length < 5) return res;
const link = args[0].target.href?.match(/^https?:\/\/(www.)?github.com\/[\w-]+\/[\w-]+\/?/)[0].split('/') || githubURL[0].split('/');
const file =
[args[0].target.href]?.filter(f => f?.match(/^https?:\/\/(www.)?github.com\/[\w-]+\/[\w-]+\/?/))[0]?.split('blob/') ||
githubURL[0].split('blob/');
if (!findInReactTree(res, c => c.props?.id == 'githubModule'))
res.props.children.splice(
4,
0,
React.createElement(
Menu.MenuGroup,
null,
React.createElement(Menu.MenuItem, {
action: () => openModal(() => React.createElement(Model, { file: file ? file[1] : null, link, getSetting: this.settings.get })),
id: 'githubModule',
label: 'Open Repository',
})
)
);
return res;
});
MessageContextMenu.default.displayName = 'MessageContextMenu';
}
pluginWillUnload() {
uninject('Gmodel-context-menu');
powercord.api.settings.unregisterSettings(this.entityID);
}
};