update
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
/**
|
||||
* @name BlurNSFW
|
||||
* @version 0.2.5
|
||||
* @authorLink https://twitter.com/IAmZerebos
|
||||
* @donate https://paypal.me/ZackRauen
|
||||
* @patreon https://patreon.com/Zerebos
|
||||
* @description Blurs images and videos until you hover over them.
|
||||
* @version 1.0.1
|
||||
* @author Zerebos
|
||||
* @authorId 249746236008169473
|
||||
* @website https://github.com/rauenzi/BetterDiscordAddons/tree/master/Plugins/BlurNSFW
|
||||
* @source https://raw.githubusercontent.com/rauenzi/BetterDiscordAddons/master/Plugins/BlurNSFW/BlurNSFW.plugin.js
|
||||
* @updateUrl https://raw.githubusercontent.com/rauenzi/BetterDiscordAddons/master/Plugins/BlurNSFW/BlurNSFW.plugin.js
|
||||
*/
|
||||
/*@cc_on
|
||||
@if (@_jscript)
|
||||
@@ -31,100 +30,243 @@
|
||||
WScript.Quit();
|
||||
|
||||
@else@*/
|
||||
|
||||
module.exports = (() => {
|
||||
const config = {info:{name:"BlurNSFW",authors:[{name:"Zerebos",discord_id:"249746236008169473",github_username:"rauenzi",twitter_username:"ZackRauen"}],version:"0.2.5",description:"Blurs images in NSFW channels until you hover over it.",github:"https://github.com/rauenzi/BetterDiscordAddons/tree/master/Plugins/BlurNSFW",github_raw:"https://raw.githubusercontent.com/rauenzi/BetterDiscordAddons/master/Plugins/BlurNSFW/BlurNSFW.plugin.js"},changelog:[{title:"New Option",items:["An option to stop blurring a picture when clicking on it/expanding it was added to settings."]}],defaultConfig:[{type:"slider",id:"blurSize",name:"Blur Size",note:"The size (in px) of the blurred pixels.",value:10,min:0,max:50,units:"px"},{type:"slider",id:"blurTime",name:"Blur Time",note:"The time (in ms) it takes for the blur to disappear and reappear.",value:200,min:0,max:5000,units:"ms"},{type:"switch",id:"blurOnFocus",name:"Blur When Focused",note:"This setting keeps the blur when clicking on/expanding an image.",value:true}],main:"index.js"};
|
||||
|
||||
return !global.ZeresPluginLibrary ? class {
|
||||
constructor() {this._config = config;}
|
||||
getName() {return config.info.name;}
|
||||
getAuthor() {return config.info.authors.map(a => a.name).join(", ");}
|
||||
getDescription() {return config.info.description;}
|
||||
getVersion() {return config.info.version;}
|
||||
load() {
|
||||
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click Download Now to install it.`, {
|
||||
confirmText: "Download Now",
|
||||
cancelText: "Cancel",
|
||||
onConfirm: () => {
|
||||
require("request").get("https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js", async (error, response, body) => {
|
||||
if (error) return require("electron").shell.openExternal("https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js");
|
||||
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
|
||||
const config = {
|
||||
info: {
|
||||
name: "BlurNSFW",
|
||||
authors: [
|
||||
{
|
||||
name: "Zerebos",
|
||||
discord_id: "249746236008169473",
|
||||
github_username: "rauenzi",
|
||||
twitter_username: "ZackRauen"
|
||||
}
|
||||
],
|
||||
version: "1.0.1",
|
||||
description: "Blurs images and videos until you hover over them.",
|
||||
github: "https://github.com/rauenzi/BetterDiscordAddons/tree/master/Plugins/BlurNSFW",
|
||||
github_raw: "https://raw.githubusercontent.com/rauenzi/BetterDiscordAddons/master/Plugins/BlurNSFW/BlurNSFW.plugin.js"
|
||||
},
|
||||
changelog: [
|
||||
{
|
||||
title: "What's New?",
|
||||
type: "fixed",
|
||||
items: [
|
||||
"Context menu and blurring should work again!",
|
||||
"Blurring and unblurring happen quicker and using less resources now!"
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "Known Issues",
|
||||
items: [
|
||||
"The checkbox in the context menu won't update after clicking.",
|
||||
"This is just a visual issue, the functionality is fine."
|
||||
]
|
||||
}
|
||||
],
|
||||
defaultConfig: [
|
||||
{
|
||||
type: "switch",
|
||||
id: "blurNSFW",
|
||||
name: "Blur NSFW Channels",
|
||||
note: "This setting automatically blurs media in channels marked NSFW.",
|
||||
value: true
|
||||
},
|
||||
{
|
||||
type: "slider",
|
||||
id: "blurSize",
|
||||
name: "Blur Size",
|
||||
note: "The size (in px) of the blurred pixels.",
|
||||
value: 10,
|
||||
min: 0,
|
||||
max: 50,
|
||||
units: "px"
|
||||
},
|
||||
{
|
||||
type: "slider",
|
||||
id: "blurTime",
|
||||
name: "Blur Time",
|
||||
note: "The time (in ms) it takes for the blur to disappear and reappear.",
|
||||
value: 200,
|
||||
min: 0,
|
||||
max: 5000,
|
||||
units: "ms"
|
||||
},
|
||||
{
|
||||
type: "switch",
|
||||
id: "blurOnFocus",
|
||||
name: "Blur When Focused",
|
||||
note: "This setting keeps the blur when clicking on/expanding an image.",
|
||||
value: true
|
||||
}
|
||||
],
|
||||
main: "index.js"
|
||||
};
|
||||
class Dummy {
|
||||
constructor() {this._config = config;}
|
||||
start() {}
|
||||
stop() {}
|
||||
}
|
||||
|
||||
if (!global.ZeresPluginLibrary) {
|
||||
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.name ?? config.info.name} is missing. Please click Download Now to install it.`, {
|
||||
confirmText: "Download Now",
|
||||
cancelText: "Cancel",
|
||||
onConfirm: () => {
|
||||
require("request").get("https://betterdiscord.app/gh-redirect?id=9", async (err, resp, body) => {
|
||||
if (err) return require("electron").shell.openExternal("https://betterdiscord.app/Download?id=9");
|
||||
if (resp.statusCode === 302) {
|
||||
require("request").get(resp.headers.location, async (error, response, content) => {
|
||||
if (error) return require("electron").shell.openExternal("https://betterdiscord.app/Download?id=9");
|
||||
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), content, r));
|
||||
});
|
||||
}
|
||||
else {
|
||||
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
|
||||
}
|
||||
});
|
||||
}
|
||||
start() {}
|
||||
stop() {}
|
||||
} : (([Plugin, Api]) => {
|
||||
const plugin = (Plugin, Api) => {
|
||||
const {Patcher, WebpackModules, DiscordModules, PluginUtilities, Utilities} = Api;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = !global.ZeresPluginLibrary ? Dummy : (([Plugin, Api]) => {
|
||||
const plugin = (Plugin, Api) => {
|
||||
const {ContextMenu, DOM, Webpack, Patcher} = window.BdApi;
|
||||
|
||||
const SelectedChannelStore = DiscordModules.SelectedChannelStore;
|
||||
const ChannelStore = DiscordModules.ChannelStore;
|
||||
const ReactDOM = DiscordModules.ReactDOM;
|
||||
const InlineMediaWrapper = WebpackModules.getByProps("ImageReadyStates").default;
|
||||
const SelectedChannelStore = Webpack.getModule(m => m.getCurrentlySelectedChannelId);
|
||||
const ChannelStore = Webpack.getModule(m => m.getDMFromUserId);
|
||||
const InlineMediaWrapper = Webpack.getModule(m => m.toString().includes("renderAccessory"));
|
||||
const WrapperClasses = Webpack.getModule(m => m.wrapperPlaying);
|
||||
const Events = require("events");
|
||||
const Dispatcher = new Events();
|
||||
|
||||
return class BlurNSFW extends Plugin {
|
||||
constructor() {
|
||||
const formatString = (string, values) => {
|
||||
for (const val in values) {
|
||||
let replacement = values[val];
|
||||
if (Array.isArray(replacement)) replacement = JSON.stringify(replacement);
|
||||
if (typeof(replacement) === "object" && replacement !== null) replacement = replacement.toString();
|
||||
string = string.replace(new RegExp(`{{${val}}}`, "g"), replacement);
|
||||
}
|
||||
return string;
|
||||
};
|
||||
|
||||
/* globals BdApi:false */
|
||||
return class BlurMedia extends Plugin {
|
||||
constructor(meta) {
|
||||
super();
|
||||
this.meta = meta;
|
||||
this.styleTemplate = `
|
||||
{{blurOnFocus}}
|
||||
img.blur:hover,
|
||||
video.blur:hover {
|
||||
.${WrapperClasses.wrapperPlaying.split(" ").join(".")} video,
|
||||
.${WrapperClasses.wrapperControlsHidden.split(" ").join(".")} video,
|
||||
.blur:hover img,
|
||||
.blur:hover video,
|
||||
a:hover + div > .blur {
|
||||
transition: {{time}}ms cubic-bezier(.2, .11, 0, 1) !important;
|
||||
filter: blur(0px) !important;
|
||||
}
|
||||
|
||||
img.blur,
|
||||
video.blur {
|
||||
.blur img,
|
||||
.blur video {
|
||||
filter: blur({{size}}px) !important;
|
||||
transition: {{time}}ms cubic-bezier(.2, .11, 0, 1) !important;
|
||||
}`;
|
||||
|
||||
this.channelChange = this.channelChange.bind(this);
|
||||
}
|
||||
|
||||
onStart() {
|
||||
const blurAccessory = (thisObject) => {
|
||||
/** @type {Set<string>} */
|
||||
this.blurredChannels = new Set(BdApi.loadData(this.meta.name, "blurred") ?? []);
|
||||
|
||||
/** @type {Set<string>} */
|
||||
this.seenChannels = new Set(BdApi.loadData(this.meta.name, "seen") ?? []);
|
||||
|
||||
Patcher.after(this.meta.name, InlineMediaWrapper.prototype, "render", (thisObject, _, retVal) => {
|
||||
const channel = ChannelStore.getChannel(SelectedChannelStore.getChannelId());
|
||||
if (!channel || !channel.isNSFW || !channel.isNSFW()) return;
|
||||
const element = ReactDOM.findDOMNode(thisObject);
|
||||
const mediaElement = element.querySelector("img") || element.querySelector("video");
|
||||
if (!mediaElement) return;
|
||||
|
||||
mediaElement.classList.add("blur");
|
||||
|
||||
if (mediaElement.tagName !== "VIDEO") return;
|
||||
mediaElement.addEventListener("play", () => {
|
||||
if (mediaElement.autoplay) return;
|
||||
mediaElement.classList.remove("blur");
|
||||
});
|
||||
mediaElement.addEventListener("pause", () => {
|
||||
if (mediaElement.autoplay) return;
|
||||
mediaElement.classList.add("blur");
|
||||
});
|
||||
};
|
||||
|
||||
Patcher.after(InlineMediaWrapper.prototype, "componentDidMount", blurAccessory);
|
||||
Patcher.after(InlineMediaWrapper.prototype, "componentDidUpdate", blurAccessory);
|
||||
if (!this.hasBlur(channel)) return;
|
||||
if (retVal.props.className) retVal.props.className = retVal.props.className + " blur";
|
||||
else retVal.props.className = "blur";
|
||||
});
|
||||
|
||||
Patcher.after(this.meta.name, InlineMediaWrapper.prototype, "componentDidMount", (thisObject) => {
|
||||
if (thisObject.cancelBlurListener) return;
|
||||
const listener = () => thisObject.forceUpdate();
|
||||
Dispatcher.on("blur", listener);
|
||||
thisObject.cancelBlurListener = () => Dispatcher.off("blur", listener);
|
||||
});
|
||||
|
||||
Patcher.after(this.meta.name, InlineMediaWrapper.prototype, "componentWillUnmount", (thisObject) => {
|
||||
if (!thisObject.cancelBlurListener) return;
|
||||
thisObject.cancelBlurListener();
|
||||
delete thisObject.cancelBlurListener;
|
||||
});
|
||||
|
||||
this.addStyle();
|
||||
|
||||
SelectedChannelStore.addChangeListener(this.channelChange);
|
||||
|
||||
this.promises = {state: {cancelled: false}, cancel() {this.state.cancelled = true;}};
|
||||
this.patchChannelContextMenu();
|
||||
}
|
||||
|
||||
onStop() {
|
||||
Patcher.unpatchAll();
|
||||
BdApi.saveData(this.meta.name, "blurred", this.blurredChannels);
|
||||
BdApi.saveData(this.meta.name, "seen", this.seenChannels);
|
||||
this.contextMenuPatch?.();
|
||||
this.removeStyle();
|
||||
SelectedChannelStore.removeChangeListener(this.channelChange);
|
||||
}
|
||||
|
||||
hasBlur(channel) {
|
||||
return this.blurredChannels.has(channel.id);
|
||||
}
|
||||
|
||||
addBlur(channel) {
|
||||
this.blurredChannels.add(channel.id);
|
||||
Dispatcher.emit("blur");
|
||||
}
|
||||
|
||||
removeBlur(channel) {
|
||||
this.blurredChannels.delete(channel.id);
|
||||
Dispatcher.emit("blur");
|
||||
}
|
||||
|
||||
channelChange() {
|
||||
Dispatcher?.removeAllListeners();
|
||||
const channel = ChannelStore.getChannel(SelectedChannelStore.getChannelId());
|
||||
if (this.seenChannels.has(channel.id)) return;
|
||||
|
||||
this.seenChannels.add(channel.id);
|
||||
if (this.settings.blurNSFW && channel.nsfw) this.addBlur(channel);
|
||||
}
|
||||
|
||||
patchChannelContextMenu() {
|
||||
this.contextMenuPatch = ContextMenu.patch("channel-context", (retVal, props) => {
|
||||
const newItem = ContextMenu.buildItem({
|
||||
type: "toggle",
|
||||
label: "Blur Media",
|
||||
active: this.hasBlur(props.channel),
|
||||
action: () => {
|
||||
if (this.hasBlur(props.channel)) this.removeBlur(props.channel);
|
||||
else this.addBlur(props.channel);
|
||||
}
|
||||
});
|
||||
|
||||
retVal.props.children.splice(1, 0, newItem);
|
||||
});
|
||||
}
|
||||
|
||||
addStyle() {
|
||||
const styleString = Utilities.formatString(this.styleTemplate, {
|
||||
const styleString = formatString(this.styleTemplate, {
|
||||
size: Math.round(this.settings.blurSize),
|
||||
time: Math.round(this.settings.blurTime),
|
||||
blurOnFocus: this.settings.blurOnFocus ? "" : ".layer-2KE1M9 img.blur,"
|
||||
blurOnFocus: this.settings.blurOnFocus ? "" : ".layer-1Ixpg3 .blur img,"
|
||||
});
|
||||
PluginUtilities.addStyle(this.getName(), styleString);
|
||||
DOM.addStyle(this.meta.name, styleString);
|
||||
}
|
||||
|
||||
removeStyle() {
|
||||
PluginUtilities.removeStyle(this.getName());
|
||||
DOM.removeStyle(this.meta.name);
|
||||
}
|
||||
|
||||
getSettingsPanel() {
|
||||
@@ -138,7 +280,6 @@ module.exports = (() => {
|
||||
|
||||
};
|
||||
};
|
||||
return plugin(Plugin, Api);
|
||||
})(global.ZeresPluginLibrary.buildPlugin(config));
|
||||
})();
|
||||
return plugin(Plugin, Api);
|
||||
})(global.ZeresPluginLibrary.buildPlugin(config));
|
||||
/*@end@*/
|
||||
Reference in New Issue
Block a user