This commit is contained in:
Mirco Wittrien 2019-11-03 18:31:51 +01:00
parent a02b76a765
commit 7ca490bc32
2 changed files with 61 additions and 66 deletions

View File

@ -23,16 +23,19 @@ var BDFDB = {
BDFDB.id = id; BDFDB.id = id;
BDFDB.LogUtils = {}; BDFDB.LogUtils = {};
BDFDB.LogUtils.log = function (string, name = "BDFDB") { BDFDB.LogUtils.log = function (string, name) {
if (typeof string != "string") string = ""; if (typeof string != "string") string = "";
if (typeof name != "string" || name == "$BDFDB") name = "BDFDB";
console.log(`%c[${name}]%c`, "color: #3a71c1; font-weight: 700;", "", string.trim()); console.log(`%c[${name}]%c`, "color: #3a71c1; font-weight: 700;", "", string.trim());
}; };
BDFDB.LogUtils.warn = function (string, name = "BDFDB") { BDFDB.LogUtils.warn = function (string, name) {
if (typeof string != "string") string = ""; if (typeof string != "string") string = "";
if (typeof name != "string" || name == "$BDFDB") name = "BDFDB";
console.warn(`%c[${name}]%c`, "color: #3a71c1; font-weight: 700;", "", string.trim()); console.warn(`%c[${name}]%c`, "color: #3a71c1; font-weight: 700;", "", string.trim());
}; };
BDFDB.LogUtils.error = function (string, name = "BDFDB") { BDFDB.LogUtils.error = function (string, name) {
if (typeof string != "string") string = ""; if (typeof string != "string") string = "";
if (typeof name != "string" || name == "$BDFDB") name = "BDFDB";
console.error(`%c[${name}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: " + string.trim()); console.error(`%c[${name}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: " + string.trim());
}; };
@ -102,7 +105,6 @@ var BDFDB = {
} }
delete window.PluginUpdates.plugins[url]; delete window.PluginUpdates.plugins[url];
if (BDFDB.ObjectUtils.isEmpty(window.PluginUpdates.plugins)) BDFDB.DOMUtils.remove("#bd-settingspane-container .bd-updatebtn" + BDFDB.dotCN._repofolderbutton);
delete plugin.started; delete plugin.started;
BDFDB.InternalData.cleanUps[plugin.name] = BDFDB.TimeUtils.timeout(() => { BDFDB.InternalData.cleanUps[plugin.name] = BDFDB.TimeUtils.timeout(() => {
@ -1407,9 +1409,9 @@ var BDFDB = {
return parent.props.children; return parent.props.children;
} }
BDFDB.ReactUtils.findChildren = function (nodeOrInstance, config) { BDFDB.ReactUtils.findChildren = function (nodeOrInstance, config) {
if (!nodeOrInstance || !BDFDB.ObjectUtils.is(config) || !config.name && !config.key && !config.props) return null; if (!nodeOrInstance || !BDFDB.ObjectUtils.is(config) || !config.name && !config.key && !config.props) return [null, -1];
var instance = Node.prototype.isPrototypeOf(nodeOrInstance) ? BDFDB.ReactUtils.getInstance(nodeOrInstance) : nodeOrInstance; var instance = Node.prototype.isPrototypeOf(nodeOrInstance) ? BDFDB.ReactUtils.getInstance(nodeOrInstance) : nodeOrInstance;
if (!BDFDB.ObjectUtils.is(instance)) return null; if (!BDFDB.ObjectUtils.is(instance)) return [null, -1];
config.name = config.name && !BDFDB.ArrayUtils.is(config.name) ? Array.of(config.name) : config.name; config.name = config.name && !BDFDB.ArrayUtils.is(config.name) ? Array.of(config.name) : config.name;
config.key = config.key && !BDFDB.ArrayUtils.is(config.key) ? Array.of(config.key) : config.key; config.key = config.key && !BDFDB.ArrayUtils.is(config.key) ? Array.of(config.key) : config.key;
config.props = config.props && !BDFDB.ArrayUtils.is(config.props) ? Array.of(config.props) : config.props; config.props = config.props && !BDFDB.ArrayUtils.is(config.props) ? Array.of(config.props) : config.props;
@ -1418,54 +1420,47 @@ var BDFDB = {
var parent = startchildren; var parent = startchildren;
return getChildren(startchildren); return getChildren(startchildren);
function getChildren (children) { function getChildren (children) {
while (children && !BDFDB.ArrayUtils.is(children) && children.props && children.props.children) { var result = [startchildren, -1];
parent = children; if (!children) return result;
children = children.props.children; if (!BDFDB.ArrayUtils.is(children)) {
} if (check(children)) result = found(children);
if (children && !BDFDB.ArrayUtils.is(children)) { else if (children.props && children.props.children) {
if (parent) { parent = children;
var child = children; result = getChildren(children.props.children);
if (check(child)) {
if (BDFDB.ArrayUtils.is(parent)) {
return [parent, parent.indexOf(child)];
}
else {
parent.props.children = [];
parent.props.children.push(child);
return [parent.props.children, 0];
}
}
else return [startchildren, -1];
} }
else return [startchildren, -1];
} }
else { else {
if (!startIsArray) { for (let i = 0; result[1] == -1 && i < children.length; i++) if (children[i]) {
startchildren = children; if (BDFDB.ArrayUtils.is(children[i])) {
startIsArray = true; parent = children;
} result = getChildren(children[i]);
var result = [startchildren, -1]; }
for (let i in children) if (children[i]) { else if (check(children[i])) {
if (check(children[i])) result = [children, i]; parent = children;
else if (children[i].props) { result = found(children[i]);
}
else if (children[i].props && children[i].props.children) {
parent = children[i]; parent = children[i];
result = getChildren(children[i].props.children); result = getChildren(children[i].props.children);
} }
else if (BDFDB.ArrayUtils.is(children[i])) for (let subchild of children[i]) if (subchild) {
parent = children[i];
result = getChildren(subchild);
}
if (result[1] > -1) break;
} }
return result; }
return result;
}
function found (child) {
if (BDFDB.ArrayUtils.is(parent)) return [parent, parent.indexOf(child)];
else {
parent.props.children = [];
parent.props.children.push(child);
return [parent.props.children, 0];
} }
} }
function check (instance) { function check (instance) {
if (!instance) return false; if (!instance) return false;
let props = instance.stateNode ? instance.stateNode.props : instance.props; let props = instance.stateNode ? instance.stateNode.props : instance.props;
return instance.type && config.name && config.name.some(name => ((instance.type.displayName || instance.type.name) === name)) || config.key && config.key.some(key => instance.key == key) || props && config.props && config.props.every(prop => BDFDB.ArrayUtils.is(prop) ? (BDFDB.ArrayUtils.is(prop[1]) ? prop[1].some(checkvalue => propcheck(props, prop[0], checkvalue)) : propcheck(props, prop[0], prop[1])) : props[prop] !== undefined); return instance.type && config.name && config.name.some(name => ((instance.type.displayName || instance.type.name) === name)) || config.key && config.key.some(key => instance.key == key) || props && config.props && config.props.every(prop => BDFDB.ArrayUtils.is(prop) ? (BDFDB.ArrayUtils.is(prop[1]) ? prop[1].some(checkvalue => propCheck(props, prop[0], checkvalue)) : propCheck(props, prop[0], prop[1])) : props[prop] !== undefined);
} }
function propcheck (props, key, value) { function propCheck (props, key, value) {
return key != null && props[key] != null && value != null && (key == "className" ? props[key].indexOf(value) > -1 : BDFDB.equals(props[key], value)); return key != null && props[key] != null && value != null && (key == "className" ? props[key].indexOf(value) > -1 : BDFDB.equals(props[key], value));
} }
}; };
@ -6962,7 +6957,7 @@ var BDFDB = {
display: inline-block; display: inline-block;
margin-left: 10px; margin-left: 10px;
} }
#bd-settingspane-container .bd-updatebtn ~ .bd-updatebtn { #bd-settingspane-container .bd-updatebtn[style] {
display: none !important; display: none !important;
} }
#bd-settingspane-container ${BDFDB.dotCN._repodescription} { #bd-settingspane-container ${BDFDB.dotCN._repodescription} {
@ -7758,7 +7753,7 @@ var BDFDB = {
}); });
BDFDB.patchModules = { BDFDB.patchModules = {
V2C_List: "componentDidMount", V2C_ContentColumn: "render",
V2C_PluginCard: ["componentDidMount","componentDidUpdate"], V2C_PluginCard: ["componentDidMount","componentDidUpdate"],
V2C_ThemeCard: ["componentDidMount","componentDidUpdate"], V2C_ThemeCard: ["componentDidMount","componentDidUpdate"],
UserPopout: "componentDidMount", UserPopout: "componentDidMount",
@ -7768,28 +7763,28 @@ var BDFDB = {
}; };
var BDFDBprocessFunctions = {}; var BDFDBprocessFunctions = {};
BDFDBprocessFunctions.processV2CList = function (e) { BDFDBprocessFunctions.processV2CContentColumn = function (e) {
if (window.PluginUpdates && window.PluginUpdates.plugins && e.instance._reactInternalFiber.key && e.instance._reactInternalFiber.key.split("-")[0] == "plugin") { if (window.PluginUpdates && window.PluginUpdates.plugins && e.instance.props && e.instance.props.title == "Plugins") {
var folderbutton = document.querySelector(BDFDB.dotCN._repofolderbutton); let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {key: "folder-button"});
if (folderbutton) { if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(LibraryComponents.TooltipContainer, {
var updatebutton = BDFDB.DOMUtils.create(`<button class="bd-updatebtn ${BDFDB.disCN._repofolderbutton}">Check for Updates</button>`); text: "Only checks for updates of plugins, which support the updatecheck. Rightclick for a list of supported plugins. (Listed ≠ outdated)",
updatebutton.addEventListener("click", _ => {BDFDB.PluginUtils.checkAllUpdates();}); tooltipConfig: {
updatebutton.addEventListener("mouseenter", _ => { selector: "update-button-tooltip",
BDFDB.TooltipUtils.create(updatebutton, "Only checks for updates of plugins, which support the updatecheck. Rightclick for a list of supported plugins.", {type: "top", selector: "update-button-tooltip", style: "max-width: 420px"}); style: "max-width: 420px"
}); },
updatebutton.addEventListener("contextmenu", _ => { children: BDFDB.ReactUtils.createElement("button", {
if (window.PluginUpdates && window.PluginUpdates.plugins && !document.querySelector(".update-list-tooltip")) { className: `${BDFDB.disCN._repofolderbutton} bd-updatebtn`,
var pluginnames = []; onClick: _ => {BDFDB.PluginUtils.checkAllUpdates();},
for (let url in window.PluginUpdates.plugins) pluginnames.push(window.PluginUpdates.plugins[url].name); onContextMenu: e => {
BDFDB.TooltipUtils.create(updatebutton, pluginnames.sort().join(", "), {type: "bottom", selector: "update-list-tooltip", style: "max-width: 420px"}); if (window.PluginUpdates && window.PluginUpdates.plugins && !document.querySelector(".update-list-tooltip")) {
} var pluginnames = [];
}); for (let url in window.PluginUpdates.plugins) pluginnames.push(window.PluginUpdates.plugins[url].name);
BDFDB.DOMUtils.remove("#bd-settingspane-container .bd-updatebtn" + BDFDB.dotCN._repofolderbutton); BDFDB.TooltipUtils.create(e.currentTarget, pluginnames.sort().join(", "), {type: "bottom", selector: "update-list-tooltip", style: "max-width: 420px"});
folderbutton.parentElement.insertBefore(updatebutton, folderbutton.nextSibling); }
new MutationObserver(changes => {changes.forEach(change => {change.addedNodes.forEach(node => { },
if (folderbutton.parentElement.querySelectorAll(".bd-updatebtn").length > 1 && BDFDB.DOMUtils.containsClass(node, "bd-updatebtn")) BDFDB.DOMUtils.remove(node); children: "Check for Updates"
});});}).observe(folderbutton.parentElement, {subtree:true, childList:true}); })
} }));
} }
}; };

File diff suppressed because one or more lines are too long