2024-03-01 21:01:22 +01:00
|
|
|
//@ts-check
|
|
|
|
|
|
|
|
import JadefinIntegrity from "./JadefinIntegrity.js";
|
|
|
|
|
|
|
|
import JadefinLog from "./JadefinLog.js";
|
|
|
|
import JadefinStorage from "./JadefinStorage.js";
|
|
|
|
|
|
|
|
import { rd, rdom, rd$, RDOMListHelper } from "./utils/rdom.js";
|
|
|
|
|
|
|
|
class JadefinMod {
|
|
|
|
log = new JadefinLog(this.constructor.name);
|
|
|
|
storage = new JadefinStorage(name => `jadefin.${this.modName}.${name}`);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
* @param {string} url
|
|
|
|
*/
|
|
|
|
async init(name, url) {
|
|
|
|
this.modName = name;
|
|
|
|
this.modUrl = url;
|
|
|
|
}
|
|
|
|
|
2024-10-19 02:40:36 +02:00
|
|
|
async initStyle() {
|
2024-03-01 21:01:22 +01:00
|
|
|
document.head.appendChild(rd$()`<link rel="stylesheet" type="text/css" href=${this.getUrl(".css")}>`);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
*/
|
|
|
|
isMod(name) {
|
|
|
|
return this.modName == name || this.constructor.name == name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} name
|
|
|
|
*/
|
|
|
|
getUrl(name) {
|
|
|
|
if (!this.modUrl) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const base = this.modUrl.substring(0, this.modUrl.lastIndexOf("/") + 1);
|
|
|
|
let ext = "";
|
|
|
|
|
|
|
|
let split = this.modUrl.indexOf("?");
|
|
|
|
if (split != -1) {
|
|
|
|
ext = this.modUrl.substring(split);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name.startsWith(".")) {
|
|
|
|
return `${base}${this.modName}${name}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${base}${name}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
JadefinMod = JadefinIntegrity("JadefinMod", import.meta.url, () => JadefinMod);
|
|
|
|
export default JadefinMod;
|