62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
//@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;
|
|
}
|
|
|
|
async initStyle() {
|
|
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;
|