Use time element
This commit is contained in:
@ -59,13 +59,13 @@ function getRemainingTime(remaining: number): string {
|
||||
return "Just now"
|
||||
}
|
||||
|
||||
export function displayAiringDate(element: HTMLElement, now: Date) {
|
||||
if(!element.dataset.startDate || !element.dataset.endDate) {
|
||||
export function displayAiringDate(element: HTMLTimeElement, now: Date) {
|
||||
if(!element.dateTime || !element.dataset.endDate) {
|
||||
element.textContent = ""
|
||||
return
|
||||
}
|
||||
|
||||
const startDate = new Date(element.dataset.startDate)
|
||||
const startDate = new Date(element.dateTime)
|
||||
const endDate = new Date(element.dataset.endDate)
|
||||
|
||||
let h = startDate.getHours()
|
||||
@ -102,13 +102,13 @@ export function displayAiringDate(element: HTMLElement, now: Date) {
|
||||
}
|
||||
}
|
||||
|
||||
export function displayDate(element: HTMLElement, now: Date) {
|
||||
if(!element.dataset.date) {
|
||||
export function displayDate(element: HTMLTimeElement, now: Date) {
|
||||
if(!element.dateTime) {
|
||||
element.textContent = ""
|
||||
return
|
||||
}
|
||||
|
||||
const startDate = new Date(element.dataset.date)
|
||||
const startDate = new Date(element.dateTime)
|
||||
|
||||
const h = startDate.getHours()
|
||||
const m = startDate.getMinutes()
|
||||
@ -133,13 +133,13 @@ export function displayDate(element: HTMLElement, now: Date) {
|
||||
}
|
||||
}
|
||||
|
||||
export function displayTime(element: HTMLElement) {
|
||||
if(!element.dataset.date) {
|
||||
export function displayTime(element: HTMLTimeElement) {
|
||||
if(!element.dateTime) {
|
||||
element.textContent = ""
|
||||
return
|
||||
}
|
||||
|
||||
const startDate = new Date(element.dataset.date)
|
||||
const startDate = new Date(element.dateTime)
|
||||
|
||||
const h = startDate.getHours()
|
||||
const m = startDate.getMinutes()
|
||||
|
@ -17,13 +17,16 @@ export default class Diff {
|
||||
static mutations: MutationQueue = new MutationQueue()
|
||||
|
||||
// innerHTML will diff the element with the given HTML string and apply DOM mutations.
|
||||
static innerHTML(aRoot: HTMLElement, html: string): Promise<void> {
|
||||
static innerHTML(aRoot: HTMLElement, html: string) {
|
||||
const container = document.createElement("main")
|
||||
container.innerHTML = html
|
||||
|
||||
return new Promise((resolve, _) => {
|
||||
Diff.childNodes(aRoot, container)
|
||||
this.mutations.wait(resolve)
|
||||
|
||||
this.mutations.wait(() => {
|
||||
resolve(null)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -34,7 +37,10 @@ export default class Diff {
|
||||
rootContainer.innerHTML = html.replace("<!DOCTYPE html>", "")
|
||||
|
||||
Diff.childNodes(aRoot.getElementsByTagName("body")[0], rootContainer.getElementsByTagName("body")[0])
|
||||
this.mutations.wait(resolve)
|
||||
|
||||
this.mutations.wait(() => {
|
||||
resolve(null)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -82,9 +88,7 @@ export default class Diff {
|
||||
|
||||
const removeAttributes: Attr[] = []
|
||||
|
||||
for(let x = 0; x < elemA.attributes.length; x++) {
|
||||
const attrib = elemA.attributes[x]
|
||||
|
||||
for(const attrib of elemA.attributes) {
|
||||
if(attrib.specified) {
|
||||
if(!elemB.hasAttribute(attrib.name) && !Diff.persistentAttributes.has(attrib.name)) {
|
||||
removeAttributes.push(attrib)
|
||||
@ -98,9 +102,7 @@ export default class Diff {
|
||||
}
|
||||
})
|
||||
|
||||
for(let x = 0; x < elemB.attributes.length; x++) {
|
||||
const attrib = elemB.attributes[x]
|
||||
|
||||
for(const attrib of elemB.attributes) {
|
||||
if(!attrib.specified) {
|
||||
continue
|
||||
}
|
||||
|
@ -39,10 +39,10 @@ export default class MutationQueue {
|
||||
}
|
||||
|
||||
private mutateAll() {
|
||||
const start = performance.now()
|
||||
const start = Date.now()
|
||||
|
||||
for(let i = 0; i < this.mutations.length; i++) {
|
||||
if(performance.now() - start > timeCapacity) {
|
||||
if(Date.now() - start > timeCapacity) {
|
||||
this.mutations = this.mutations.slice(i)
|
||||
window.requestAnimationFrame(() => this.mutateAll())
|
||||
return
|
||||
|
Reference in New Issue
Block a user