BetterDiscordAddons/Plugins/RevealAllSpoilersOption/RevealAllSpoilersOption.plu...

86 lines
3.8 KiB
JavaScript
Raw Normal View History

2019-02-01 12:37:27 +01:00
//META{"name":"RevealAllSpoilersOption","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/RevealAllSpoilersOption","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/RevealAllSpoilersOption/RevealAllSpoilersOption.plugin.js"}*//
class RevealAllSpoilersOption {
getName () {return "RevealAllSpoilersOption";}
getVersion () {return "1.0.0";}
getAuthor () {return "DevilBro";}
getDescription () {return "Adds an entry to the message contextmenu to reveal all spoilers within a messageblock.";}
initConstructor () {
this.messageContextEntryMarkup =
`<div class="${BDFDB.disCN.contextmenuitemgroup}">
<div class="${BDFDB.disCN.contextmenuitem} revealspoilers-item">
2019-04-18 09:28:20 +02:00
<span class="BDFDB-textscrollwrapper" speed=3><div class="BDFDB-textscroll">Reveal all Spoilers</div></span>
2019-02-01 12:37:27 +01:00
<div class="${BDFDB.disCN.contextmenuhint}"></div>
</div>
</div>`;
}
//legacy
load () {}
start () {
2019-02-04 09:13:15 +01:00
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
2019-02-01 12:37:27 +01:00
var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
if (!libraryScript || performance.now() - libraryScript.getAttribute("date") > 600000) {
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
libraryScript.setAttribute("date", performance.now());
libraryScript.addEventListener("load", () => {if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();});
document.head.appendChild(libraryScript);
}
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
}
initialize () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
BDFDB.loadMessage(this);
}
else {
2019-02-12 21:56:34 +01:00
console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
2019-02-01 12:37:27 +01:00
}
}
stop () {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
BDFDB.unloadMessage(this);
}
}
// begin of own functions
onMessageContextMenu (instance, menu) {
if (instance.props && instance.props.message && instance.props.target && !menu.querySelector(".revealspoilers-item")) {
let messagediv = BDFDB.getParentEle(BDFDB.dotCN.message, instance.props.target);
if (!messagediv || !messagediv.querySelector(BDFDB.dotCN.spoilerhidden)) return;
2019-03-08 14:26:00 +01:00
let devgroup = BDFDB.React.findDOMNodeSafe(BDFDB.getOwnerInstance({node:menu,name:["DeveloperModeGroup","MessageDeveloperModeGroup"]}));
2019-02-01 12:37:27 +01:00
let messageContextEntry = BDFDB.htmlToElement(this.messageContextEntryMarkup);
if (devgroup) devgroup.parentElement.insertBefore(messageContextEntry, devgroup);
else menu.appendChild(messageContextEntry, menu);
let revealitem = messageContextEntry.querySelector(".revealspoilers-item");
revealitem.addEventListener("click", () => {
instance._reactInternalFiber.return.memoizedProps.closeContextMenu();
this.revealAllSpoilers(messagediv);
});
if (BDFDB.isPluginEnabled("MessageUtilities")) {
BDFDB.setContextHint(revealitem, bdplugins.MessageUtilities.plugin.getActiveShortcutString("__Reveal_Spoilers"));
}
}
}
revealAllSpoilers (target) {
let messagediv = BDFDB.getParentEle(BDFDB.dotCN.message, target);
if (!messagediv) return;
for (let spoiler of messagediv.querySelectorAll(BDFDB.dotCN.spoilerhidden)) spoiler.click();
}
}