Skip to content

Commit

Permalink
Refactor to make use of util getMetaContent() throughout the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Jul 16, 2022
1 parent 8c954a2 commit 33d80ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/core/drive/form_submission.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FetchRequest, FetchMethod, fetchMethodFromString, FetchRequestHeaders } from "../../http/fetch_request"
import { FetchResponse } from "../../http/fetch_response"
import { expandURL } from "../url"
import { attributeTrue, dispatch } from "../../util"
import { attributeTrue, dispatch, getMetaContent } from "../../util"
import { StreamMessage } from "../streams/stream_message"

export interface FormSubmissionDelegate {
Expand Down Expand Up @@ -246,11 +246,6 @@ function getCookieValue(cookieName: string | null) {
}
}

function getMetaContent(name: string) {
const element: HTMLMetaElement | null = document.querySelector(`meta[name="${name}"]`)
return element && element.content
}

function responseSucceededWithoutRedirect(response: FetchResponse) {
return response.statusCode == 200 && !response.redirected
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/drive/progress_bar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unindent } from "../../util"
import { unindent, getMetaContent } from "../../util"

export class ProgressBar {
static animationDuration = 300 /*ms*/
Expand Down Expand Up @@ -123,6 +123,6 @@ export class ProgressBar {
}

get cspNonce() {
return document.head.querySelector('meta[name="csp-nonce"]')?.getAttribute("content")
return getMetaContent("csp-nonce")
}
}
3 changes: 2 additions & 1 deletion src/core/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Bardo, BardoDelegate } from "./bardo"
import { Snapshot } from "./snapshot"
import { ReloadReason } from "./native/browser_adapter"
import { getMetaContent } from "../util"

type ResolvingFunctions<T = unknown> = {
resolve(value: T | PromiseLike<T>): void
Expand Down Expand Up @@ -106,7 +107,7 @@ export abstract class Renderer<E extends Element, S extends Snapshot<E> = Snapsh
}

get cspNonce() {
return document.head.querySelector('meta[name="csp-nonce"]')?.getAttribute("content")
return getMetaContent("csp-nonce")
}
}

Expand Down

0 comments on commit 33d80ff

Please sign in to comment.