STR v2.0.3

This commit is contained in:
_Lighty_ 2020-01-03 17:18:26 +01:00
parent 9bcfcfb2ee
commit a4ef267b4d
2 changed files with 123 additions and 113 deletions

View File

@ -1,4 +1,7 @@
# [SaveToRedux](https://1lighty.github.io/BetterDiscordStuff/?plugin=SaveToRedux "SaveToRedux") Changelog # [SaveToRedux](https://1lighty.github.io/BetterDiscordStuff/?plugin=SaveToRedux "SaveToRedux") Changelog
### 2.0.3
- Saving pictures from steam now works properly
### 2.0.2 ### 2.0.2
- Plugin has been renamed to SaveToRedux to avoid issues loading due to the original plugin, as well as to be able to distinguish between the two more easily. - Plugin has been renamed to SaveToRedux to avoid issues loading due to the original plugin, as well as to be able to distinguish between the two more easily.
- Changed update URL - Changed update URL

View File

@ -41,16 +41,16 @@ var SaveToRedux = (() => {
twitter_username: '' twitter_username: ''
} }
], ],
version: '2.0.2', version: '2.0.3',
description: 'Allows you to save images, videos, profile icons, server icons, reactions, emotes and custom status emotes to any folder quickly.', description: 'Allows you to save images, videos, profile icons, server icons, reactions, emotes and custom status emotes to any folder quickly.',
github: 'https://github.com/1Lighty', github: 'https://github.com/1Lighty',
github_raw: 'https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/SaveToRedux/SaveToRedux.plugin.js' github_raw: 'https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/SaveToRedux/SaveToRedux.plugin.js'
}, },
changelog: [ changelog: [
{ {
title: 'plugin rename', title: 'Fixed',
type: 'added', type: 'fixed',
items: ['Plugin has been renamed to SaveToRedux to avoid issues loading due to the original plugin, as well as to be able to distinguish between the two more easily.', 'Changed update URL'] items: ['Saving pictures from steam now works properly']
} }
], ],
defaultConfig: [ defaultConfig: [
@ -357,6 +357,7 @@ var SaveToRedux = (() => {
} }
formatURL(url, requiresSize, customName) { formatURL(url, requiresSize, customName) {
if (url.indexOf('//steamuserimages') !== -1) url = url.replace(/\/$/, '');
if (url.indexOf('/a_') !== -1) url = url.replace('.webp', '.gif').replace('.png', '.gif'); if (url.indexOf('/a_') !== -1) url = url.replace('.webp', '.gif').replace('.png', '.gif');
else url = url.replace('.webp', '.png'); else url = url.replace('.webp', '.png');
let fileName = url.substr(url.lastIndexOf('/') + 1); let fileName = url.substr(url.lastIndexOf('/') + 1);
@ -368,8 +369,14 @@ var SaveToRedux = (() => {
extension = name; extension = name;
name = url.match(/\/\/media.tenor.co\/[^\/]+\/([^\/]+)\//)[1]; name = url.match(/\/\/media.tenor.co\/[^\/]+\/([^\/]+)\//)[1];
} else if (url.indexOf('//i.giphy.com/media/') !== -1) name = url.match(/\/\/i\.giphy\.com\/media\/([^\/]+)\//)[1]; } else if (url.indexOf('//i.giphy.com/media/') !== -1) name = url.match(/\/\/i\.giphy\.com\/media\/([^\/]+)\//)[1];
else if (url.indexOf('//steamuserimages') !== -1) {
extension = 'png';
url += '/'; /* ??? */
}
name = this.formatFilename(name); name = this.formatFilename(name);
return { fileName: (extension && `${name}.${extension}`) || name, url: url, name, extension }; const ret = { fileName: (extension && `${name}.${extension}`) || name, url: url, name, extension };
// Logger.info(`[formatURL] url \`${url}\` requiresSize \`${requiresSize}\` customName \`${customName}\`, ret ${JSON.stringify(ret, '', 1)}`);
return ret;
} }
constructMenu(url, type, customName) { constructMenu(url, type, customName) {
@ -684,10 +691,10 @@ var SaveToRedux = (() => {
} }
url = src; url = src;
if (!url) return; if (!url) return;
if (/\.(png|jpe?g|webp|gif|svg)$/i.test(url)) saveType = 'Image'; if (/\.(png|jpe?g|webp|gif|svg)$/i.test(url) || url.indexOf('//steamuserimages') !== -1) saveType = 'Image';
if (/\.(mp4|webm|mov)$/i.test(url)) saveType = 'Video'; else if (/\.(mp4|webm|mov)$/i.test(url)) saveType = 'Video';
if (/\.(mp3|ogg|wav|flac)$/i.test(url)) saveType = 'Audio'; else if (/\.(mp3|ogg|wav|flac)$/i.test(url)) saveType = 'Audio';
if (url.indexOf('app.com/emojis/') !== -1) { else if (url.indexOf('app.com/emojis/') !== -1) {
saveType = 'Emoji'; saveType = 'Emoji';
const emojiId = url.split('emojis/')[1].split('.')[0]; const emojiId = url.split('emojis/')[1].split('.')[0];
const emoji = EmojiUtils.getDisambiguatedEmojiContext().getById(emojiId); const emoji = EmojiUtils.getDisambiguatedEmojiContext().getById(emojiId);
@ -768,112 +775,112 @@ var SaveToRedux = (() => {
return !global.ZeresPluginLibrary || !global.XenoLib return !global.ZeresPluginLibrary || !global.XenoLib
? class { ? class {
getName() { getName() {
return this.name.replace(/\s+/g, ''); return this.name.replace(/\s+/g, '');
} }
getAuthor() { getAuthor() {
return this.author; return this.author;
} }
getVersion() { getVersion() {
return this.version; return this.version;
} }
getDescription() { getDescription() {
return this.description; return this.description;
} }
stop() { } stop() {}
load() { load() {
const ezlibMissing = !global.XenoLib; const ezlibMissing = !global.XenoLib;
const zlibMissing = !global.ZeresPluginLibrary; const zlibMissing = !global.ZeresPluginLibrary;
const bothLibsMissing = ezlibMissing && zlibMissing; const bothLibsMissing = ezlibMissing && zlibMissing;
const header = `Missing ${(bothLibsMissing && 'Libraries') || 'Library'}`; const header = `Missing ${(bothLibsMissing && 'Libraries') || 'Library'}`;
const content = `The ${(bothLibsMissing && 'Libraries') || 'Library'} ${(zlibMissing && 'ZeresPluginLibrary') || ''} ${(ezlibMissing && (zlibMissing ? 'and XenoLib' : 'XenoLib')) || ''} required for ${this.name} ${(bothLibsMissing && 'are') || 'is'} missing.`; const content = `The ${(bothLibsMissing && 'Libraries') || 'Library'} ${(zlibMissing && 'ZeresPluginLibrary') || ''} ${(ezlibMissing && (zlibMissing ? 'and XenoLib' : 'XenoLib')) || ''} required for ${this.name} ${(bothLibsMissing && 'are') || 'is'} missing.`;
const ModalStack = BdApi.findModuleByProps('push', 'update', 'pop', 'popWithKey'); const ModalStack = BdApi.findModuleByProps('push', 'update', 'pop', 'popWithKey');
const TextElement = BdApi.findModuleByProps('Sizes', 'Weights'); const TextElement = BdApi.findModuleByProps('Sizes', 'Weights');
const ConfirmationModal = BdApi.findModule(m => m.defaultProps && m.key && m.key() === 'confirm-modal'); const ConfirmationModal = BdApi.findModule(m => m.defaultProps && m.key && m.key() === 'confirm-modal');
const onFail = () => BdApi.getCore().alert(header, `${content}<br/>Due to a slight mishap however, you'll have to download the libraries yourself. After opening the links, do CTRL + S to download the library.<br/>${(zlibMissing && '<br/><a href="https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js"target="_blank">Click here to download ZeresPluginLibrary</a>') || ''}${(zlibMissing && '<br/><a href="http://localhost:7474/XenoLib.js"target="_blank">Click here to download XenoLib</a>') || ''}`); const onFail = () => BdApi.getCore().alert(header, `${content}<br/>Due to a slight mishap however, you'll have to download the libraries yourself. After opening the links, do CTRL + S to download the library.<br/>${(zlibMissing && '<br/><a href="https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js"target="_blank">Click here to download ZeresPluginLibrary</a>') || ''}${(zlibMissing && '<br/><a href="http://localhost:7474/XenoLib.js"target="_blank">Click here to download XenoLib</a>') || ''}`);
if (!ModalStack || !ConfirmationModal || !TextElement) return onFail(); if (!ModalStack || !ConfirmationModal || !TextElement) return onFail();
ModalStack.push(props => { ModalStack.push(props => {
return BdApi.React.createElement( return BdApi.React.createElement(
ConfirmationModal, ConfirmationModal,
Object.assign( Object.assign(
{ {
header, header,
children: [TextElement({ color: TextElement.Colors.PRIMARY, children: [`${content} Please click Download Now to install ${(bothLibsMissing && 'them') || 'it'}.`] })], children: [TextElement({ color: TextElement.Colors.PRIMARY, children: [`${content} Please click Download Now to install ${(bothLibsMissing && 'them') || 'it'}.`] })],
red: false, red: false,
confirmText: 'Download Now', confirmText: 'Download Now',
cancelText: 'Cancel', cancelText: 'Cancel',
onConfirm: () => { onConfirm: () => {
const request = require('request'); const request = require('request');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const waitForLibLoad = callback => { const waitForLibLoad = callback => {
if (!global.BDEvents) return callback(); if (!global.BDEvents) return callback();
const onLoaded = e => { const onLoaded = e => {
if (e !== 'ZeresPluginLibrary') return; if (e !== 'ZeresPluginLibrary') return;
BDEvents.off('plugin-loaded', onLoaded); BDEvents.off('plugin-loaded', onLoaded);
callback(); callback();
}; };
BDEvents.on('plugin-loaded', onLoaded); BDEvents.on('plugin-loaded', onLoaded);
}; };
const onDone = () => { const onDone = () => {
if (!global.pluginModule || (!global.BDEvents && !global.XenoLib)) return; if (!global.pluginModule || (!global.BDEvents && !global.XenoLib)) return;
if (!global.BDEvents || global.XenoLib) pluginModule.reloadPlugin(this.name); if (!global.BDEvents || global.XenoLib) pluginModule.reloadPlugin(this.name);
else { else {
const listener = () => { const listener = () => {
pluginModule.reloadPlugin(this.name); pluginModule.reloadPlugin(this.name);
BDEvents.off('xenolib-loaded', listener); BDEvents.off('xenolib-loaded', listener);
}; };
BDEvents.on('xenolib-loaded', listener); BDEvents.on('xenolib-loaded', listener);
} }
}; };
const downloadXenoLib = () => { const downloadXenoLib = () => {
if (global.XenoLib) return onDone(); if (global.XenoLib) return onDone();
request('https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/1XenoLib.plugin.js', (error, response, body) => { request('https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/1XenoLib.plugin.js', (error, response, body) => {
if (error) return onFail(); if (error) return onFail();
onDone(); onDone();
fs.writeFile(path.join(window.ContentManager.pluginsFolder, '1XenoLib.plugin.js'), body, () => { }); fs.writeFile(path.join(window.ContentManager.pluginsFolder, '1XenoLib.plugin.js'), body, () => {});
}); });
}; };
if (!global.ZeresPluginLibrary) { if (!global.ZeresPluginLibrary) {
request('https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js', (error, response, body) => { request('https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js', (error, response, body) => {
if (error) return onFail(); if (error) return onFail();
waitForLibLoad(downloadXenoLib); waitForLibLoad(downloadXenoLib);
fs.writeFile(path.join(window.ContentManager.pluginsFolder, '0PluginLibrary.plugin.js'), body, () => { }); fs.writeFile(path.join(window.ContentManager.pluginsFolder, '0PluginLibrary.plugin.js'), body, () => {});
}); });
} else downloadXenoLib(); } else downloadXenoLib();
} }
}, },
props props
) )
); );
}); });
} }
start() { } start() {}
get [Symbol.toStringTag]() { get [Symbol.toStringTag]() {
return 'Plugin'; return 'Plugin';
} }
get name() { get name() {
return config.info.name; return config.info.name;
} }
get short() { get short() {
let string = ''; let string = '';
for (let i = 0, len = config.info.name.length; i < len; i++) { for (let i = 0, len = config.info.name.length; i < len; i++) {
const char = config.info.name[i]; const char = config.info.name[i];
if (char === char.toUpperCase()) string += char; if (char === char.toUpperCase()) string += char;
}
return string;
}
get author() {
return config.info.authors.map(author => author.name).join(', ');
}
get version() {
return config.info.version;
}
get description() {
return config.info.description;
} }
return string;
} }
get author() {
return config.info.authors.map(author => author.name).join(', ');
}
get version() {
return config.info.version;
}
get description() {
return config.info.description;
}
}
: buildPlugin(global.ZeresPluginLibrary.buildPlugin(config)); : buildPlugin(global.ZeresPluginLibrary.buildPlugin(config));
})(); })();