Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 50 additions & 38 deletions v1/quoter.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@
"authors": [
"Samogot"
],
"version": "3.13",
"version": "3.14",
"description": "Add citation using embeds",
"repository": "https://github.com/samogot/betterdiscord-plugins.git",
"homepage": "https://github.com/samogot/betterdiscord-plugins/tree/master/v2/Quoter",
Expand Down Expand Up @@ -793,19 +793,19 @@
// Deffer module loading
let moment, Constants, GuildsStore, UsersStore, MembersStore, UserSettingsStore, MessageActions, MessageQueue,
MessageParser, HistoryUtils, PermissionUtils, ContextMenuActions, ModalsStack, ContextMenuItemsGroup,
ContextMenuItem, ExternalLink, ConfirmModal, MessageGroup, ChannelStore, SelectedChannelStore,
DraftStore, DraftActions;
function loadAllModules() {
ContextMenuItem, ExternalLink, ConfirmModal, MessageGroup, ChannelStore, SelectedChannelStore,
DraftStore, DraftActions;

function loadAllModules() {
moment = WebpackModules.findByUniqueProperties(['parseZone']);

Constants = WebpackModules.findByUniqueProperties(['Routes', 'ChannelTypes']);

GuildsStore = WebpackModules.findByUniqueProperties(['getGuild']);
ChannelStore = WebpackModules.findByUniqueProperties(['getChannel']);
DraftStore = WebpackModules.findByUniqueProperties(['getDraft']);
DraftActions = WebpackModules.findByUniqueProperties(['changeDraft']);
SelectedChannelStore = WebpackModules.findByUniqueProperties(['getChannelId']);
GuildsStore = WebpackModules.findByUniqueProperties(['getGuild']);
ChannelStore = WebpackModules.findByUniqueProperties(['getChannel']);
DraftStore = WebpackModules.findByUniqueProperties(['getDraft']);
DraftActions = WebpackModules.findByUniqueProperties(['changeDraft']);
SelectedChannelStore = WebpackModules.findByUniqueProperties(['getChannelId']);
UsersStore = WebpackModules.findByUniqueProperties(['getUser', 'getCurrentUser']);
MembersStore = WebpackModules.findByUniqueProperties(['getNick']);
UserSettingsStore = WebpackModules.findByUniqueProperties(['developerMode', 'locale']);
Expand All @@ -830,18 +830,19 @@
// TooltipWrapper.displayName = 'TooltipWrapper';
}

ReactComponents.setName('Message', Filters.byPrototypeFields(['renderCozy', 'renderCompact']));
ReactComponents.setName('MessageContent', m => m.defaultProps && m.defaultProps.hasOwnProperty("disableButtons"));
ReactComponents.setName('Message', Filters.byPrototypeFields(['renderCozy', 'renderCompact']));
ReactComponents.setName('MessageContent', m => m.defaultProps && m.defaultProps.hasOwnProperty("disableButtons"));
// ReactComponents.setName('ChannelTextAreaForm', Filters.byPrototypeFields(['handleTextareaChange', 'render']));
// ReactComponents.setName('OptionPopout', Filters.byPrototypeFields(['handleCopyId', 'handleEdit', 'handleRetry', 'handleDelete', 'handleReactions', '', '', '', '']));
ReactComponents.setName('Embed', Filters.byPrototypeFields(['renderProvider', 'renderAuthor', 'renderFooter', 'renderTitle', 'renderDescription', 'renderFields', 'renderImage', 'renderVideo']));
ReactComponents.setName('MessageContextMenu', Filters.byCode(/\.ContextMenuTypes\.MESSAGE_MAIN\b[\s\S]*\.ContextMenuTypes\.MESSAGE_SYSTEM\b/, c => c.prototype && c.prototype.render));
ReactComponents.setName('MessageResendItem', Filters.byPrototypeFields(['handleResendMessage', 'render']));
ReactComponents.setName('MessageGroup', m => m.defaultProps && m.defaultProps.disableManageMessages);
MessageGroup = WebpackModules.find(m => m.defaultProps && m.defaultProps.disableManageMessages);
if (MessageGroup) MessageGroup.displayName = 'MessageGroup';
MessageGroup = WebpackModules.find(m => m.defaultProps && m.defaultProps.disableManageMessages);
if (MessageGroup) MessageGroup.displayName = 'MessageGroup';

const BASE_JUMP_URL = 'https://github.com/samogot/betterdiscord-plugins/blob/master/v2/Quoter/link-stub.md';
const OLD_BASE_JUMP_URL = 'https://github.com/samogot/betterdiscord-plugins/blob/master/v2/Quoter/link-stub.md';
const BASE_JUMP_URL = 'https://discordapp.com/channels/';

class QuoterPlugin extends Plugin {

Expand All @@ -860,15 +861,15 @@
if (v1) {
$ = Vendor.$;
}
if (window.ZLibrary) {
const versioner = (content) => {
const remoteVersion = content.match(/['"][0-9]+\.[0-9]+['"]/i);
if (!remoteVersion) return "0.0";
return remoteVersion.toString().replace(/['"]/g, "");
};
const comparator = (current, remote) => remote > current;
window.ZLibrary.PluginUpdater.checkForUpdate("Quoter", this.version, "https://raw.githubusercontent.com/samogot/betterdiscord-plugins/master/v1/quoter.plugin.js", versioner, comparator);
}
if (window.ZLibrary) {
const versioner = (content) => {
const remoteVersion = content.match(/['"][0-9]+\.[0-9]+['"]/i);
if (!remoteVersion) return "0.0";
return remoteVersion.toString().replace(/['"]/g, "");
};
const comparator = (current, remote) => remote > current;
window.ZLibrary.PluginUpdater.checkForUpdate("Quoter", this.version, "https://raw.githubusercontent.com/samogot/betterdiscord-plugins/master/v1/quoter.plugin.js", versioner, comparator);
}
loadAllModules();
Api.injectStyle(QuoterPlugin.styleId, QuoterPlugin.style);
$(document).on("keydown.quoter", this.onCopyKeyPressed);
Expand Down Expand Up @@ -908,9 +909,17 @@
}

static getIdsFromLink(href) {
const regex = new RegExp('^' + BASE_JUMP_URL + '\\?guild_id=([^&]+)&channel_id=([^&]+)&message_id=([^&]+)(?:&author_id=([^&]+))?$');
const match = regex.exec(href);
if (!match) return null;
const sanitize = /[-\/\\^$*+?.()|[\]{}]/g;
const old_regex = new RegExp('^' + OLD_BASE_JUMP_URL.replace(sanitize, '\\$&') + '\\?guild_id=([^&]+)&channel_id=([^&]+)&message_id=([^&]+)(?:&author_id=([^&]+))?$');
const regex = new RegExp('^' + BASE_JUMP_URL.replace(sanitize, '\\$&') + '([0-9]+|@me)/([0-9]+)/([0-9]+)$');
let match = regex.exec(href);
if (match) {
// author_id will never be included
match[4] = undefined;
} else {
match = old_regex.exec(href);
if (!match) return null;
}
return {
guild_id: match[1],
channel_id: match[2],
Expand Down Expand Up @@ -1105,7 +1114,7 @@
id: quote.message.author.id,
name: quote.message.nick || quote.message.author.username,
icon_url: quote.message.author.avatar_url || new URL(quote.message.author.getAvatarURL(), location.href).href,
url: `${BASE_JUMP_URL}?guild_id=${quote.channel.guild_id || '@me'}&channel_id=${quote.channel.id}&message_id=${quote.message.id}&author_id=${quote.message.author.id}`
url: `${BASE_JUMP_URL}${quote.channel.guild_id || '@me'}/${quote.channel.id}/${quote.message.id}`
},
footer: {},
timestamp: quote.message.timestamp.toISOString(),
Expand Down Expand Up @@ -1180,7 +1189,7 @@
}

patchMessageRender() {
ReactComponents.get('MessageContent', MessageContent => {
ReactComponents.get('MessageContent', MessageContent => {
const cancel = Renderer.patchRender(MessageContent, [
{
selector: {
Expand All @@ -1203,7 +1212,7 @@

patchMessageContextMenuRender() {
ReactComponents.get('MessageContextMenu', MessageContextMenu => {
if (MessageContextMenu.prototype.render.__monkeyPatched) return;
if (MessageContextMenu.prototype.render.__monkeyPatched) return;
const cancel = Renderer.patchRender(MessageContextMenu, [
{
selector: {
Expand Down Expand Up @@ -1269,7 +1278,7 @@
newText = this.quoteMessageGroup(channel, [message]);
}
newText += this.getMentions(channel, oldText);

if (newText) {
if (channel.isPrivate() || PermissionUtils.can(0x800, channel)) {
const text = !oldText ? newText : /\n\s*$/.test(oldText) ? oldText + newText : oldText + '\n' + newText;
Expand Down Expand Up @@ -1355,6 +1364,7 @@

const $markupsAndAttachments = $('.markup-2BOw-j,.imageWrapper-2p5ogY,.embed-thumbnail-rich').filter((i, element) => range.intersectsNode(element));
const $markups = $markupsAndAttachments.filter('.markup-2BOw-j');

if ($markups.length === 0 && $markupsAndAttachments.length === 0) {
return '';
}
Expand Down Expand Up @@ -1452,7 +1462,9 @@
if ($(markup).parents(".content-3dzVd8").find('.embed-IeVjo6').length > 0) {
const $embed = $(markup).parents(".content-3dzVd8").find('.embedInner-1-fpTo');
const $embedAuthorName = $embed.find('.embedAuthorName-3mnTWj');
if ($embed.length > 0 && $embedAuthorName.attr('href') && $embedAuthorName.attr('href').indexOf(BASE_JUMP_URL) === 0) {
if ($embed.length > 0 && $embedAuthorName.attr('href') &&
($embedAuthorName.attr('href').indexOf(OLD_BASE_JUMP_URL) === 0 ||
$embedAuthorName.attr('href').indexOf(BASE_JUMP_URL) === 0)) {
const ids = QuoterPlugin.getIdsFromLink($embedAuthorName.attr('href'));
const embed = getOwnerInstance($embed[0], {include: ["Embed"]}).props.embed;
const attachments = Array.from($embed.find('.embedFieldValue-nELq2s a')).map(e => ({
Expand Down Expand Up @@ -1511,11 +1523,11 @@
user-select: none;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 33 25"><path fill="#99AAB5" d="M18 6.5c0-2 .7-3.5 2-4.7C21.3.6 23 0 25 0c2.5 0 4.4.8 6 2.4C32.2 4 33 6 33 8.8s-.4 5-1.3 7c-.8 1.8-1.8 3.4-3 4.7-1.2 1.2-2.5 2.2-3.8 3L21.4 25l-3.3-5.5c1.4-.6 2.5-1.4 3.5-2.6 1-1.4 1.5-2.7 1.6-4-1.3 0-2.6-.6-3.7-1.8-1-1.2-1.7-2.8-1.7-4.8zM.4 6.5c0-2 .6-3.5 2-4.7C3.6.6 5.4 0 7.4 0c2.3 0 4.3.8 5.7 2.4C14.7 4 15.5 6 15.5 8.8s-.5 5-1.3 7c-.7 1.8-1.7 3.4-3 4.7-1 1.2-2.3 2.2-3.6 3C6 24 5 24.5 4 25L.6 19.5C2 19 3.2 18 4 17c1-1.3 1.6-2.6 1.8-4-1.4 0-2.6-.5-3.8-1.7C1 10 .4 8.5.4 6.5z"/></svg>') 50% no-repeat;
margin-left: 6px;
}
.btn-reaction {
margin-left: 4px;
}
}
.btn-reaction {
margin-left: 4px;
}

.container-1YxwTf .btn-quote:hover {
opacity: 1;
Expand Down
3 changes: 3 additions & 0 deletions v2/Quoter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ There is [support server](https://discord.gg/MC5dJdE) for all my plugins includi

## Changelog

### 3.14
- Use Discord's new builtin message links

### 3.13
- Fix loading issues
- Fix external link module search
Expand Down
2 changes: 1 addition & 1 deletion v2/Quoter/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"authors": [
"Samogot"
],
"version": "3.13",
"version": "3.14",
"description": "Add citation using embeds",
"repository": "https://github.com/samogot/betterdiscord-plugins.git",
"homepage": "https://github.com/samogot/betterdiscord-plugins/tree/master/v2/Quoter",
Expand Down
29 changes: 20 additions & 9 deletions v2/Quoter/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = (Plugin, BD, Vendor, v1) => {
}

ReactComponents.setName('Message', Filters.byPrototypeFields(['renderCozy', 'renderCompact']));
ReactComponents.setName('MessageContent', m => m.defaultProps && m.defaultProps.hasOwnProperty("disableButtons"));
ReactComponents.setName('MessageContent', m => m.defaultProps && m.defaultProps.hasOwnProperty("disableButtons"));
// ReactComponents.setName('ChannelTextAreaForm', Filters.byPrototypeFields(['handleTextareaChange', 'render']));
// ReactComponents.setName('OptionPopout', Filters.byPrototypeFields(['handleCopyId', 'handleEdit', 'handleRetry', 'handleDelete', 'handleReactions', '', '', '', '']));
ReactComponents.setName('Embed', Filters.byPrototypeFields(['renderProvider', 'renderAuthor', 'renderFooter', 'renderTitle', 'renderDescription', 'renderFields', 'renderImage', 'renderVideo']));
Expand All @@ -74,7 +74,8 @@ module.exports = (Plugin, BD, Vendor, v1) => {
MessageGroup = WebpackModules.find(m => m.defaultProps && m.defaultProps.disableManageMessages);
if (MessageGroup) MessageGroup.displayName = 'MessageGroup';

const BASE_JUMP_URL = 'https://github.com/samogot/betterdiscord-plugins/blob/master/v2/Quoter/link-stub.md';
const OLD_BASE_JUMP_URL = 'https://github.com/samogot/betterdiscord-plugins/blob/master/v2/Quoter/link-stub.md';
const BASE_JUMP_URL = 'https://discordapp.com/channels/';

class QuoterPlugin extends Plugin {

Expand Down Expand Up @@ -141,9 +142,17 @@ module.exports = (Plugin, BD, Vendor, v1) => {
}

static getIdsFromLink(href) {
const regex = new RegExp('^' + BASE_JUMP_URL + '\\?guild_id=([^&]+)&channel_id=([^&]+)&message_id=([^&]+)(?:&author_id=([^&]+))?$');
const match = regex.exec(href);
if (!match) return null;
const sanitize = /[-\/\\^$*+?.()|[\]{}]/g;
const old_regex = new RegExp('^' + OLD_BASE_JUMP_URL.replace(sanitize, '\\$&') + '\\?guild_id=([^&]+)&channel_id=([^&]+)&message_id=([^&]+)(?:&author_id=([^&]+))?$');
const regex = new RegExp('^' + BASE_JUMP_URL.replace(sanitize, '\\$&') + '([0-9]+|@me)/([0-9]+)/([0-9]+)$');
let match = regex.exec(href);
if (match) {
// author_id will never be included
match[4] = undefined;
} else {
match = old_regex.exec(href);
if (!match) return null;
}
return {
guild_id: match[1],
channel_id: match[2],
Expand Down Expand Up @@ -338,7 +347,7 @@ module.exports = (Plugin, BD, Vendor, v1) => {
id: quote.message.author.id,
name: quote.message.nick || quote.message.author.username,
icon_url: quote.message.author.avatar_url || new URL(quote.message.author.getAvatarURL(), location.href).href,
url: `${BASE_JUMP_URL}?guild_id=${quote.channel.guild_id || '@me'}&channel_id=${quote.channel.id}&message_id=${quote.message.id}&author_id=${quote.message.author.id}`
url: `${BASE_JUMP_URL}${quote.channel.guild_id || '@me'}/${quote.channel.id}/${quote.message.id}`
},
footer: {},
timestamp: quote.message.timestamp.toISOString(),
Expand Down Expand Up @@ -436,7 +445,7 @@ module.exports = (Plugin, BD, Vendor, v1) => {

patchMessageContextMenuRender() {
ReactComponents.get('MessageContextMenu', MessageContextMenu => {
if (MessageContextMenu.prototype.render.__monkeyPatched) return;
if (MessageContextMenu.prototype.render.__monkeyPatched) return;
const cancel = Renderer.patchRender(MessageContextMenu, [
{
selector: {
Expand Down Expand Up @@ -587,7 +596,7 @@ module.exports = (Plugin, BD, Vendor, v1) => {
const $clone = $(range.cloneContents());

const $markupsAndAttachments = $('.markup-2BOw-j,.imageWrapper-2p5ogY,.embed-thumbnail-rich').filter((i, element) => range.intersectsNode(element));
const $markups = $markupsAndAttachments.filter('.markup-2BOw-j');
const $markups = $markupsAndAttachments.filter('.markup-2BOw-j');

if ($markups.length === 0 && $markupsAndAttachments.length === 0) {
return '';
Expand Down Expand Up @@ -686,7 +695,9 @@ module.exports = (Plugin, BD, Vendor, v1) => {
if ($(markup).parents(".content-3dzVd8").find('.embed-IeVjo6').length > 0) {
const $embed = $(markup).parents(".content-3dzVd8").find('.embedInner-1-fpTo');
const $embedAuthorName = $embed.find('.embedAuthorName-3mnTWj');
if ($embed.length > 0 && $embedAuthorName.attr('href') && $embedAuthorName.attr('href').indexOf(BASE_JUMP_URL) === 0) {
if ($embed.length > 0 && $embedAuthorName.attr('href') &&
($embedAuthorName.attr('href').indexOf(OLD_BASE_JUMP_URL) === 0 ||
$embedAuthorName.attr('href').indexOf(BASE_JUMP_URL) === 0)) {
const ids = QuoterPlugin.getIdsFromLink($embedAuthorName.attr('href'));
const embed = getOwnerInstance($embed[0], {include: ["Embed"]}).props.embed;
const attachments = Array.from($embed.find('.embedFieldValue-nELq2s a')).map(e => ({
Expand Down
Loading