Skip to content

Commit

Permalink
enable strict check
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenlx committed Apr 5, 2021
1 parent 7db1ed9 commit 56b9969
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const DEFAULT_SETTINGS: MxSettings = {
};

export default class MediaExtended extends Plugin {
settings: MxSettings;
settings: MxSettings = DEFAULT_SETTINGS;
// player = Plyr;

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
Object.assign(this.settings, await this.loadData());
}

async saveSettings() {
Expand Down
32 changes: 18 additions & 14 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,24 @@ export function processInternalEmbeds(el:HTMLElement, ctx:MarkdownPostProcessorC
case "VIDEO":
case "AUDIO":
const url = (m.target as HTMLSpanElement).getAttr("src")
const hash = url.split('#').last();
const hash = url?.split('#').last();
const params = new URLSearchParams(hash);
const paramT = params.get('t')
const player = m.addedNodes[0] as HME_TF;
if (paramT!==null) {
let rawTime = paramT.match(tFragRegex).groups
const timeSpan = getTimeSpan(
rawTime.start,
rawTime.end
);
// import timestamps to player
Object.assign(player,timeSpan);
const tFrag = `t=${paramT}`;
const url = new URL(player.src);
url.hash = tFrag;
player.src = url.toString();
let rawTime = paramT.match(tFragRegex)?.groups
if (rawTime){
const timeSpan = getTimeSpan(
rawTime.start,
rawTime.end
);
// import timestamps to player
Object.assign(player,timeSpan);
const tFrag = `t=${paramT}`;
const url = new URL(player.src);
url.hash = tFrag;
player.src = url.toString();
}
}
if (params.get('loop')===""){
player.loop=true;
Expand Down Expand Up @@ -126,22 +128,24 @@ export function processExternalEmbeds(el:HTMLElement, ctx:MarkdownPostProcessorC
const ext = new URL(srcEl.src).pathname.split(".").last();

let newEl: HTMLMediaElement;
let type: "audio" | "video";
let type: "audio" | "video" | null;
switch (ext) {
case "mp3": case "wav": case "m4a": case "ogg": case "3gp": case "flac":
type = "audio";
break;
case "mp4": case "webm": case "ogv":
type = "video";
break;
default:
type = null;
}
console.log(ext);
if (type) {
console.log('hello');
newEl = createEl(type);
newEl.src = srcEl.src;
newEl.controls = true;
srcEl.parentNode.replaceChild(newEl, srcEl);
srcEl.parentNode?.replaceChild(newEl, srcEl);
}
}
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"strict": true,
"allowSyntheticDefaultImports": true,
"lib": [
"dom",
Expand Down

0 comments on commit 56b9969

Please sign in to comment.