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-05-26 13:55:26 +02:00
|
|
|
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
|
|
|
|
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
2019-02-01 12:37:27 +01:00
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
libraryScript = document.createElement("script");
|
2019-05-26 13:55:26 +02:00
|
|
|
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
2019-02-01 12:37:27 +01:00
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
|
|
|
|
libraryScript.setAttribute("date", performance.now());
|
2019-05-26 13:55:26 +02:00
|
|
|
libraryScript.addEventListener("load", () => {this.initialize();});
|
2019-02-01 12:37:27 +01:00
|
|
|
document.head.appendChild(libraryScript);
|
2019-05-26 13:55:26 +02:00
|
|
|
this.libLoadTimeout = setTimeout(() => {
|
|
|
|
libraryScript.remove();
|
|
|
|
require("request")("https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js", (error, response, body) => {
|
|
|
|
if (body) {
|
|
|
|
libraryScript = document.createElement("script");
|
|
|
|
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
libraryScript.setAttribute("date", performance.now());
|
|
|
|
libraryScript.innerText = body;
|
|
|
|
document.head.appendChild(libraryScript);
|
|
|
|
}
|
|
|
|
this.initialize();
|
|
|
|
});
|
|
|
|
}, 15000);
|
2019-02-01 12:37:27 +01:00
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|