|
|
@ -1,80 +1,78 @@ |
|
|
|
function PleromaModLoader () { |
|
|
|
this.config = { |
|
|
|
"modDirectory": "/instance/pleroma-mods/", |
|
|
|
"mods": [] |
|
|
|
}; |
|
|
|
this.loadConfig(); |
|
|
|
this.loadedMods = {}; |
|
|
|
this.classes = {}; |
|
|
|
} |
|
|
|
[ |
|
|
|
function loadMods () { |
|
|
|
for (const mod of this.config.mods) { |
|
|
|
const modObject = new PleromaMod(mod); |
|
|
|
modObject.enabled = true; |
|
|
|
if (localStorage.getItem("pleroma_mod_" + mod + "_enabled") === "false") { |
|
|
|
modObject.enabled = false; |
|
|
|
} |
|
|
|
localStorage.setItem("pleroma_mod_" + mod + "_enabled", modObject.enabled); |
|
|
|
modObject.include(); |
|
|
|
this.loadedMods[mod] = modObject; |
|
|
|
} |
|
|
|
}, |
|
|
|
class PleromaModLoader { |
|
|
|
constructor () { |
|
|
|
this.config = { |
|
|
|
"modDirectory": "/instance/pleroma-mods/", |
|
|
|
"mods": [] |
|
|
|
}; |
|
|
|
this.loadConfig(); |
|
|
|
this.loadedMods = {}; |
|
|
|
this.classes = {}; |
|
|
|
} |
|
|
|
|
|
|
|
loadMods () { |
|
|
|
this.config.mods.forEach((mod) => { |
|
|
|
this.loadMod(mod); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
loadMod (modName) { |
|
|
|
return PleromaModLoader.includeScript( |
|
|
|
this.config.modDirectory + "pleroma-mod-" + modName + "/mod.js" |
|
|
|
).then(() => { |
|
|
|
this.loadedMods[modName] = new this.classes[PleromaModLoader.getClassName(modName)](); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function loadConfig () { |
|
|
|
loadConfig () { |
|
|
|
window.fetch("/instance/pleroma-mod-config.json").then((response) => { |
|
|
|
if (response.ok) { |
|
|
|
response.json().then((json) => { |
|
|
|
for (const key in json) { |
|
|
|
this.config[key] = json[key]; |
|
|
|
} |
|
|
|
this.loadMods(); |
|
|
|
}).catch((error) => { |
|
|
|
console.error("can't parse loader config"); |
|
|
|
console.error(error); |
|
|
|
}); |
|
|
|
} |
|
|
|
return response.json(); |
|
|
|
}).then((json) => { |
|
|
|
Object.keys(json).forEach((key) => { |
|
|
|
this.config[key] = json[key]; |
|
|
|
}); |
|
|
|
this.loadMods(); |
|
|
|
}).catch((error) => { |
|
|
|
console.warn("can't load mod loader config"); |
|
|
|
console.warn(error); |
|
|
|
console.error("can't load loader config"); |
|
|
|
console.error(error); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
function registerClass (className, object) { |
|
|
|
registerClass (className, object) { |
|
|
|
this.classes[className] = object; |
|
|
|
}, |
|
|
|
|
|
|
|
function waitUntilReady () { |
|
|
|
const postPanel = document.getElementsByClassName("post-status-form"); |
|
|
|
const loginPanel = document.getElementsByClassName("login-form"); |
|
|
|
if (postPanel.length > 0 || loginPanel.length > 0) { |
|
|
|
for (var modName in this.loadedMods) { |
|
|
|
const settings = document.querySelector(".settings div[label]:first-child"); |
|
|
|
} |
|
|
|
|
|
|
|
waitUntilReady () { |
|
|
|
const postPanel = document.querySelector(".status-container"); |
|
|
|
const loginPanel = document.querySelector(".login-form"); |
|
|
|
if (postPanel || loginPanel) { |
|
|
|
Object.keys(this.loadedMods).forEach((modName) => { |
|
|
|
const settings = document.querySelector(".settings-modal div[label]:first-child"); |
|
|
|
if (settings) { |
|
|
|
if (!settings.querySelector(".mod-settings")) { |
|
|
|
this.appendModSettings(settings); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const mod = this.loadedMods[modName]; |
|
|
|
if (mod.enabled && mod.instance) { |
|
|
|
if (mod.instance.onReady) { |
|
|
|
mod.instance.onReady(); |
|
|
|
} |
|
|
|
if (mod.isEnabled) { |
|
|
|
mod.ready(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
this.createObserver(); |
|
|
|
} else { |
|
|
|
console.warn("not ready, trying again in 1s"); |
|
|
|
window.setTimeout(() => { this.waitUntilReady(); }, 1000); |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
function createCheckbox (label, mod) { |
|
|
|
createCheckbox (label, mod) { |
|
|
|
const labelElement = document.createElement("label"); |
|
|
|
labelElement.classList.add("checkbox"); |
|
|
|
|
|
|
|
const input = document.createElement("input"); |
|
|
|
input.setAttribute("type", "checkbox"); |
|
|
|
input.checked = mod.enabled; |
|
|
|
input.checked = mod.isEnabled; |
|
|
|
input.addEventListener("change", (event) => { |
|
|
|
if (event.target.checked) { |
|
|
|
mod.enable(); |
|
|
@ -91,41 +89,51 @@ function PleromaModLoader () { |
|
|
|
const text = document.createElement("span"); |
|
|
|
text.classList.add("label"); |
|
|
|
text.innerText = label; |
|
|
|
|
|
|
|
labelElement.appendChild(text); |
|
|
|
|
|
|
|
return labelElement; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
function appendModSettings (element) { |
|
|
|
appendModSettings (element) { |
|
|
|
const container = document.createElement("div"); |
|
|
|
container.classList.add("setting-item"); |
|
|
|
container.classList.add("mod-settings"); |
|
|
|
|
|
|
|
const title = document.createElement("h2"); |
|
|
|
title.innerText = "Mods"; |
|
|
|
title.innerText = "Pleroma Mods"; |
|
|
|
container.appendChild(title); |
|
|
|
|
|
|
|
const optionList = document.createElement("ul"); |
|
|
|
optionList.classList.add("setting-list"); |
|
|
|
|
|
|
|
const modNames = Object.keys(this.loadedMods).sort(); |
|
|
|
for (const mod of modNames) { |
|
|
|
Object.keys(this.loadedMods).sort().forEach((modName) => { |
|
|
|
const li = document.createElement("li"); |
|
|
|
|
|
|
|
const enable = this.createCheckbox("enable " + mod, this.loadedMods[mod]); |
|
|
|
|
|
|
|
const enable = this.createCheckbox("enable " + modName, this.loadedMods[modName]); |
|
|
|
li.appendChild(enable); |
|
|
|
|
|
|
|
const ulConfig = document.createElement("ul"); |
|
|
|
ulConfig.classList.add("setting-list"); |
|
|
|
|
|
|
|
Object.keys(this.loadedMods[modName].config).forEach((key) => { |
|
|
|
if (key === "includes" || key === "filter") { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.loadedMods[modName].onSettingInit(key, ulConfig, document.createElement("li")); |
|
|
|
}); |
|
|
|
|
|
|
|
li.appendChild(ulConfig); |
|
|
|
|
|
|
|
optionList.appendChild(li); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
container.appendChild(optionList); |
|
|
|
|
|
|
|
element.appendChild(container); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
function createObserver () { |
|
|
|
createObserver () { |
|
|
|
this.containers = { |
|
|
|
main: document.querySelector(".main"), |
|
|
|
notifications: document.querySelector(".notifications"), |
|
|
@ -133,33 +141,26 @@ function PleromaModLoader () { |
|
|
|
settingsModal: document.querySelector(".settings-modal") |
|
|
|
}; |
|
|
|
|
|
|
|
const observerConfig = { subtree: true, childList: true }; |
|
|
|
const observerConfig = { |
|
|
|
subtree: true, |
|
|
|
childList: true |
|
|
|
}; |
|
|
|
|
|
|
|
this.observer = new MutationObserver((mutations, observer) => { |
|
|
|
if ( |
|
|
|
mutations.length > 0 && |
|
|
|
mutations[0].addedNodes.length > 0 && |
|
|
|
mutations[0].addedNodes[0].classList && |
|
|
|
mutations[0].addedNodes[0].classList.contains("settings_tab-switcher") |
|
|
|
) { |
|
|
|
this.appendModSettings(mutations[0].addedNodes[0].querySelector("div[label]:first-child")); |
|
|
|
const modal = document.querySelector(".settings-modal div[label]:first-child"); |
|
|
|
if (modal && !modal.querySelector(".mod-settings")) { |
|
|
|
this.appendModSettings(modal); |
|
|
|
} |
|
|
|
for (var modName in this.loadedMods) { |
|
|
|
const mod = this.loadedMods[modName]; |
|
|
|
if (mod.instance && mod.enabled) { |
|
|
|
if (mod.instance.onMutation) { |
|
|
|
for (const mutation of mutations) { |
|
|
|
let filter = null; |
|
|
|
if (mod.instance.config.filter) { |
|
|
|
filter = new RegExp(mod.instance.config.filter.join("|")); |
|
|
|
} |
|
|
|
if (!filter || filter.test(mutation.target.className)) { |
|
|
|
mod.instance.onMutation(mutation, observer); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Object.values(this.loadedMods).forEach((mod) => { |
|
|
|
if (mod.isEnabled) { |
|
|
|
mutations.forEach((mutation) => { |
|
|
|
mod.mutate(mutation, observer); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
this.observer.observe(this.containers.main, observerConfig); |
|
|
|
if (this.containers.notifications) { |
|
|
|
this.observer.observe(this.containers.notifications, observerConfig); |
|
|
@ -171,155 +172,306 @@ function PleromaModLoader () { |
|
|
|
this.observer.observe(this.containers.settingsModal, observerConfig); |
|
|
|
} |
|
|
|
} |
|
|
|
].forEach((fn) => { PleromaModLoader.prototype[fn.name] = fn; }); |
|
|
|
[ |
|
|
|
function registerMod (mod) { |
|
|
|
window.__pleromaModLoader.registerClass(mod.name, mod); |
|
|
|
}, |
|
|
|
|
|
|
|
function includeModScript (src) { |
|
|
|
return PleromaModLoader.includeScript(window.__pleromaModLoader.config.modDirectory + src); |
|
|
|
}, |
|
|
|
|
|
|
|
function includeModCss (src) { |
|
|
|
return PleromaModLoader.includeCss(window.__pleromaModLoader.config.modDirectory + src); |
|
|
|
}, |
|
|
|
|
|
|
|
function excludeModScript (src) { |
|
|
|
return PleromaModLoader.excludeScript(window.__pleromaModLoader.config.modDirectory + src); |
|
|
|
}, |
|
|
|
|
|
|
|
function excludeModCss (src) { |
|
|
|
return PleromaModLoader.excludeCss(window.__pleromaModLoader.config.modDirectory + src); |
|
|
|
}, |
|
|
|
static registerMod (mod) { |
|
|
|
window.__pleromaModLoader.registerClass(mod.name, mod); |
|
|
|
} |
|
|
|
|
|
|
|
function includeScript (src) { |
|
|
|
static includeScript (src) { |
|
|
|
console.log("include " + src); |
|
|
|
return new Promise((resolve) => { |
|
|
|
const body = document.getElementsByTagName("body")[0]; |
|
|
|
const script = document.createElement("script"); |
|
|
|
script.setAttribute("src", src); |
|
|
|
script.setAttribute("type", "text/javascript"); |
|
|
|
script.onload = () => { resolve(); }; |
|
|
|
body.appendChild(script); |
|
|
|
script.onload = () => { |
|
|
|
resolve(); |
|
|
|
}; |
|
|
|
document.querySelector("body").appendChild(script); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
function getVueScope (element) { |
|
|
|
if (!element) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
if (element.__vue__) { |
|
|
|
return element.__vue__; |
|
|
|
} |
|
|
|
if (element.parentNode) { |
|
|
|
return PleromaModLoader.getVueScope(element.parentNode); |
|
|
|
} |
|
|
|
return null; |
|
|
|
}, |
|
|
|
|
|
|
|
function getRootVueScope () { |
|
|
|
return document.querySelector("#app").__vue__; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
function includeCss (src) { |
|
|
|
static includeCss (src) { |
|
|
|
console.log("include " + src); |
|
|
|
return new Promise((resolve) => { |
|
|
|
const head = document.getElementsByTagName("head")[0]; |
|
|
|
const link = document.createElement("link"); |
|
|
|
link.setAttribute("href", src); |
|
|
|
link.setAttribute("rel", "stylesheet"); |
|
|
|
link.setAttribute("type", "text/css"); |
|
|
|
link.onload = () => { resolve(); }; |
|
|
|
head.appendChild(link); |
|
|
|
link.onload = () => { |
|
|
|
resolve(); |
|
|
|
}; |
|
|
|
document.querySelector("head").appendChild(link); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
function excludeScript (src) { |
|
|
|
static excludeScript (src) { |
|
|
|
return new Promise((resolve) => { |
|
|
|
const script = document.querySelector('script[src="' + src + '"]'); |
|
|
|
if(script) { |
|
|
|
const script = document.querySelector("script[src=\"" + src + "\"]"); |
|
|
|
if (script) { |
|
|
|
script.remove(); |
|
|
|
} |
|
|
|
resolve(); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
function excludeCss (src) { |
|
|
|
static excludeCss (src) { |
|
|
|
return new Promise((resolve) => { |
|
|
|
const link = document.querySelector('link[href="' + src + '"]'); |
|
|
|
if(link) { |
|
|
|
const link = document.querySelector("link[href=\"" + src + "\"]"); |
|
|
|
if (link) { |
|
|
|
link.remove(); |
|
|
|
} |
|
|
|
resolve(); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
function getToken () { |
|
|
|
return PleromaModLoader.getRootVueScope().$store._vm.getUserToken(); |
|
|
|
}, |
|
|
|
static getVueScope (element) { |
|
|
|
if (!element) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
if (element.__vue__) { |
|
|
|
console.warn("old vue version, please update pleroma-fe"); |
|
|
|
return element.__vue__; |
|
|
|
} |
|
|
|
if (element._vnode) { |
|
|
|
return element._vnode; |
|
|
|
} |
|
|
|
if (element.__vnode) { |
|
|
|
return element.__vnode; |
|
|
|
} |
|
|
|
if (element.parentNode) { |
|
|
|
return PleromaModLoader.getVueScope(element.parentNode); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
function getModDir () { |
|
|
|
static getVueComponent (element) { |
|
|
|
if (!element) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
if (element.__vnode && element.__vnode.component) { |
|
|
|
return element.__vnode.component; |
|
|
|
} |
|
|
|
if (element.__vueParentComponent) { |
|
|
|
return element.__vueParentComponent.ctx; |
|
|
|
} |
|
|
|
if (element.__vueComponent__) { |
|
|
|
return element.__vueComponent__; |
|
|
|
} |
|
|
|
if (element.parentNode) { |
|
|
|
return PleromaModLoader.getVueComponent(element.parentNode); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
static getRootVueScope () { |
|
|
|
return PleromaModLoader.getVueScope(document.querySelector("#app")); |
|
|
|
} |
|
|
|
|
|
|
|
static getToken () { |
|
|
|
return PleromaModLoader.getRootVueScope().appContext.provides.store.getters.getUserToken(); |
|
|
|
} |
|
|
|
|
|
|
|
static getModDir () { |
|
|
|
return window.__pleromaModLoader.config.modDirectory; |
|
|
|
} |
|
|
|
].forEach((fn) => { PleromaModLoader[fn.name] = fn; }); |
|
|
|
|
|
|
|
function PleromaMod (name) { |
|
|
|
this.name = name; |
|
|
|
this.instance = null; |
|
|
|
this.enabled = localStorage.getItem("pleroma_mod_" + this.name + "_enabled") !== "false"; |
|
|
|
} |
|
|
|
[ |
|
|
|
function getClassName () { |
|
|
|
static getClassName (name) { |
|
|
|
let className = "PleromaMod"; |
|
|
|
const nameParts = this.name.split("-"); |
|
|
|
for (const namePart of nameParts) { |
|
|
|
name.split("-").forEach((namePart) => { |
|
|
|
className += namePart.substring(0, 1).toUpperCase(); |
|
|
|
className += namePart.substring(1); |
|
|
|
} |
|
|
|
}); |
|
|
|
return className; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
function enable () { |
|
|
|
this.enabled = true; |
|
|
|
this.modLoaded(); |
|
|
|
if (this.instance.onReady) { |
|
|
|
this.instance.onReady(); |
|
|
|
static api (method, path, params) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
const token = PleromaModLoader.getToken(); |
|
|
|
const xhr = new XMLHttpRequest(); |
|
|
|
xhr.responseType = "json"; |
|
|
|
xhr.open(method, path); |
|
|
|
xhr.setRequestHeader("Content-Type", "application/json"); |
|
|
|
xhr.setRequestHeader("Authorization", "Bearer " + token); |
|
|
|
xhr.onreadstatechange = () => { |
|
|
|
if (xhr.readyState === 4) { |
|
|
|
if (xhr.status !== 200) { |
|
|
|
reject(new Error({ |
|
|
|
status: xhr.status, |
|
|
|
response: xhr.response, |
|
|
|
xhr: xhr |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
xhr.onload = () => { |
|
|
|
resolve(xhr.response); |
|
|
|
}; |
|
|
|
xhr.send(JSON.stringify(params)); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class PleromaMod { // eslint-disable-line no-unused-vars
|
|
|
|
constructor (name) { |
|
|
|
this.name = name; |
|
|
|
this.config = {}; |
|
|
|
this.isRunning = false; |
|
|
|
} |
|
|
|
|
|
|
|
get isEnabled () { |
|
|
|
return localStorage.getItem("pleroma_mod_" + this.name + "_enabled") !== "false" || true; |
|
|
|
} |
|
|
|
|
|
|
|
getClassName () { |
|
|
|
return PleromaModLoader.getClassName(this.name); |
|
|
|
} |
|
|
|
|
|
|
|
getModDir () { |
|
|
|
return PleromaModLoader.getModDir() + this.name + "/"; |
|
|
|
} |
|
|
|
|
|
|
|
ready () { |
|
|
|
this.onReady(); |
|
|
|
this.run(); |
|
|
|
} |
|
|
|
|
|
|
|
destroy () { |
|
|
|
this.isRunning = false; |
|
|
|
if (this.config.includes) { |
|
|
|
const styles = this.config.includes.css || []; |
|
|
|
const scripts = this.config.includes.js || []; |
|
|
|
|
|
|
|
Promise.all(styles.map((style) => { |
|
|
|
return this.excludeCss(style); |
|
|
|
}).concat(scripts.map((script) => { |
|
|
|
return this.excludeScript(script); |
|
|
|
}))).then(() => { |
|
|
|
this.onDestroy(); |
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
localStorage.setItem("pleroma_mod_" + this.name + "_enabled", this.enabled); |
|
|
|
}, |
|
|
|
|
|
|
|
function disable () { |
|
|
|
this.enabled = false; |
|
|
|
if (this.instance.onDestroy) { |
|
|
|
this.instance.onDestroy(); |
|
|
|
this.onDestroy(); |
|
|
|
} |
|
|
|
|
|
|
|
run () { |
|
|
|
if (this.config.includes) { |
|
|
|
const styles = this.config.includes.css || []; |
|
|
|
const scripts = this.config.includes.js || []; |
|
|
|
|
|
|
|
Promise.all(styles.map((style) => { |
|
|
|
return this.includeCss(style); |
|
|
|
}).concat(scripts.map((script) => { |
|
|
|
return this.includeScript(script); |
|
|
|
})).concat([ |
|
|
|
this.loadConfig(), |
|
|
|
this.onCreate() |
|
|
|
])).then(() => { |
|
|
|
this.isRunning = true; |
|
|
|
this.onRun(); |
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
console.log(this.name + " unloaded"); |
|
|
|
this.instance = null; |
|
|
|
localStorage.setItem("pleroma_mod_" + this.name + "_enabled", this.enabled); |
|
|
|
}, |
|
|
|
|
|
|
|
function include () { |
|
|
|
console.log("loading " + this.name); |
|
|
|
PleromaModLoader.includeScript( |
|
|
|
PleromaModLoader.getModDir() + "pleroma-mod-" + this.name + "/mod.js" |
|
|
|
).then(() => { |
|
|
|
if (this.enabled) { |
|
|
|
this.modLoaded(); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
function modLoaded () { |
|
|
|
console.log(this.name + " loaded"); |
|
|
|
this.instance = new window.__pleromaModLoader.classes[this.getClassName()](); |
|
|
|
this.run(); |
|
|
|
}, |
|
|
|
this.isRunning = true; |
|
|
|
this.onRun(); |
|
|
|
} |
|
|
|
|
|
|
|
function run () { |
|
|
|
if (this.instance) { |
|
|
|
this.instance.run(); |
|
|
|
mutate (mutation, observer) { |
|
|
|
if (this.isRunning) { |
|
|
|
this.onMutation(mutation, observer); |
|
|
|
} |
|
|
|
} |
|
|
|
].forEach((fn) => { PleromaMod.prototype[fn.name] = fn; }); |
|
|
|
|
|
|
|
saveConfig () { |
|
|
|
const storedConfig = {}; |
|
|
|
Object.keys(this.config).filter((key) => { |
|
|
|
return key !== "includes" && key !== "filter"; |
|
|
|
}).forEach((key) => { |
|
|
|
storedConfig[key] = this.config[key]; |
|
|
|
}); |
|
|
|
localStorage.setItem(this.name + "_config", JSON.stringify(storedConfig)); |
|
|
|
} |
|
|
|
|
|
|
|
mergeConfig (newConfig) { |
|
|
|
Object.keys(newConfig).forEach((key) => { |
|
|
|
this.config[key] = JSON.parse(JSON.stringify(newConfig[key])); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
loadConfig () { |
|
|
|
return new Promise((resolve) => { |
|
|
|
// TODO: use structuredClone when its more supported
|
|
|
|
this.defaultConfig = JSON.parse(JSON.stringify(this.config)); |
|
|
|
|
|
|
|
const storedConfig = JSON.parse(localStorage.getItem(this.name + "_config")); |
|
|
|
|
|
|
|
this.onConfigLoad().then((json) => { |
|
|
|
this.mergeConfig(json); |
|
|
|
if (storedConfig) { |
|
|
|
this.mergeConfig(storedConfig); |
|
|
|
} |
|
|
|
this.saveConfig(); |
|
|
|
resolve(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
onReady () {} |
|
|
|
onCreate () { |
|
|
|
return new Promise((resolve) => { |
|
|
|
resolve(); |
|
|
|
}); |
|
|
|
} |
|
|
|
onDestroy () {} |
|
|
|
onRun () {} |
|
|
|
onMutation (mutation, observer) {} |
|
|
|
onConfigLoad () { |
|
|
|
return new Promise((resolve) => { |
|
|
|
resolve({}); |
|
|
|
}); |
|
|
|
} |
|
|
|
onSettingInit (key, ul, li) {} |
|
|
|
|
|
|
|
includeCss (src) { |
|
|
|
return PleromaModLoader.includeCss(PleromaModLoader.getModDir() + this.name + "/" + src); |
|
|
|
} |
|
|
|
|
|
|
|
includeScript (src) { |
|
|
|
return PleromaModLoader.includeScript(PleromaModLoader.getModDir() + this.name + "/" + src); |
|
|
|
} |
|
|
|
|
|
|
|
excludeCss (src) { |
|
|
|
return PleromaModLoader.excludeCss(PleromaModLoader.getModDir() + this.name + "/" + src); |
|
|
|
} |
|
|
|
|
|
|
|
excludeScript (src) { |
|
|
|
return PleromaModLoader.excludeScript(PleromaModLoader.getModDir() + this.name + "/" + src); |
|
|
|
} |
|
|
|
|
|
|
|
fetchJson (src) { |
|
|
|
console.log("loading " + src); |
|
|
|
return window.fetch(PleromaModLoader.getModDir() + this.name + "/" + src).then((response) => { |
|
|
|
return response.json(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
api (method, path, params) { |
|
|
|
return PleromaModLoader.api(method, path, params); |
|
|
|
} |
|
|
|
|
|
|
|
enable () { |
|
|
|
this.ready(); |
|
|
|
localStorage.setItem("pleroma_mod_" + this.name + "_enabled", true); |
|
|
|
} |
|
|
|
|
|
|
|
disable () { |
|
|
|
this.destroy(); |
|
|
|
localStorage.setItem("pleroma_mod_" + this.name + "_enabled", false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
window.__pleromaModLoader = new PleromaModLoader(); |
|
|
|
window.__pleromaModLoader.waitUntilReady(); |
|
|
|