diff options
| author | Joel Klinghed <the_jk@opera.com> | 2024-12-18 11:38:27 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@opera.com> | 2024-12-18 11:38:27 +0100 |
| commit | f241b0e54515ac9e0b373cdf23d875649e52ba94 (patch) | |
| tree | 9200be0c59826a0968c85be754680fae014f65b7 | |
| parent | 176fb28c24dae4ba07123f20867435a71bf3e8ed (diff) | |
Make lint and format happy
| -rw-r--r-- | src/clicks.ts | 6 | ||||
| -rw-r--r-- | src/clicks_display.ts | 68 |
2 files changed, 36 insertions, 38 deletions
diff --git a/src/clicks.ts b/src/clicks.ts index 35471f5..6d35dbb 100644 --- a/src/clicks.ts +++ b/src/clicks.ts @@ -1,4 +1,8 @@ -const CLICKS_WSURL: string | undefined = (window as any).clicksWsUrl +interface ClicksWindow extends Window { + clicksWsUrl?: string +} + +const CLICKS_WSURL: string | undefined = (<ClicksWindow>window).clicksWsUrl class Session { private wss: WebSocketStream diff --git a/src/clicks_display.ts b/src/clicks_display.ts index d13d790..faf9ce0 100644 --- a/src/clicks_display.ts +++ b/src/clicks_display.ts @@ -1,26 +1,24 @@ import h337 from "heatmap.js" -namespace Clicks { - export type ClickEvent = { - x: number - y: number - tag: string - } +type ClickEvent = { + x: number + y: number + tag: string +} - export type UrlEvent = { - url: string - } +type UrlEvent = { + url: string +} - export type Event = ClickEvent | UrlEvent +type ClicksBaseEvent = ClickEvent | UrlEvent - export interface Format { - format: string - version: string - width: number - height: number - brands: string - events: Event[] - } +interface Format { + format: string + version: string + width: number + height: number + brands: string + events: ClicksBaseEvent[] } class PageData { @@ -54,16 +52,16 @@ class Display { private current: PageData | undefined constructor() { - this.status = document.getElementById("status")!! - this.frame_container = document.getElementById("frame_container")!! - this.frame = document.getElementById("frame")!! as HTMLIFrameElement - this.heatmap = document.getElementById("heatmap")!! - this.url = document.getElementById("url")!! as HTMLSelectElement + this.status = document.getElementById("status")! + this.frame_container = document.getElementById("frame_container")! + this.frame = document.getElementById("frame")! as HTMLIFrameElement + this.heatmap = document.getElementById("heatmap")! + this.url = document.getElementById("url")! as HTMLSelectElement this.map = h337.create({ container: this.heatmap, }) - this.url.addEventListener("change", (e) => { + this.url.addEventListener("change", () => { if (this.data === undefined) return this.show(this.data[this.url.selectedIndex]) }) @@ -73,7 +71,7 @@ class Display { this.setStatus("Loading...") const reader = new FileReader() reader.addEventListener("load", () => { - const data = JSON.parse(reader.result as string) as Clicks.Format + const data = JSON.parse(reader.result as string) as Format if (data.format !== "clicks" || data.version !== "1.0") { this.setStatus("Unknown format") return @@ -83,24 +81,22 @@ class Display { const scaleY = data.width let url: string | undefined let clicks: h337.DataPoint[] = [] - let map = new Map<string, number>() + const map = new Map<string, number>() for (const event of data.events) { if ("url" in event) { if (url !== undefined) { - console.log(clicks) this.data.push(new PageData(url, data.width, clicks)) } url = event.url clicks = [] map.clear() } else { - const ce = event as Clicks.ClickEvent - const x = Math.round(ce.x * scaleX) - const y = Math.round(ce.y * scaleY) + const x = Math.round(event.x * scaleX) + const y = Math.round(event.y * scaleY) const pos = `${x}x${y}` const index = map.get(pos) if (index === undefined) { - map.set(pos, clicks!!.length) + map.set(pos, clicks.length) clicks.push({ x: x, y: y, value: 1 }) } else { clicks[index].value++ @@ -108,15 +104,13 @@ class Display { } } if (url !== undefined) { - console.log(clicks) this.data.push(new PageData(url, data.width, clicks)) } - while (this.url.options.length > 0) - this.url.options.remove(0) + while (this.url.options.length > 0) this.url.options.remove(0) for (let i = 0; i < this.data.length; i++) { - const option = document.createElement("option") as HTMLOptionElement + const option = document.createElement("option") option.value = `${i}` option.innerText = this.data[i].url this.url.options.add(option) @@ -143,7 +137,7 @@ class Display { this.heatmap.style.transform = "translateY(0px)" this.frame.addEventListener("load", () => { this.frame.contentDocument?.addEventListener("scroll", () => { - const y = this.frame.contentDocument!!.documentElement.scrollTop + const y = this.frame.contentDocument!.documentElement.scrollTop this.heatmap.style.transform = `translateY(${-y}px)` }) }) @@ -155,7 +149,7 @@ document.addEventListener("DOMContentLoaded", () => { const file = document.getElementById("file") const display = new Display() file?.addEventListener("change", (event: Event) => { - const files = (event.target as HTMLInputElement | null)!!.files + const files = (event.target as HTMLInputElement | null)!.files if (files === null) return if (files.length > 0) { display.loadFile(files[0]) |
