generated from brckd/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
56 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import { getManifestData, createDataURI } from "./manifest"; | ||
import { createManifestLink } from "./manifest"; | ||
import { updateLocation, sanitizePath, setFullscreen, setInstantStart } from "./location"; | ||
|
||
try { | ||
const url = new URL(document.location.href); | ||
const manifestData = getManifestData(document.head, url); | ||
document.head.append(createManifestLink(document)); | ||
|
||
const manifestLink = document.createElement("link"); | ||
manifestLink.rel = "manifest"; | ||
manifestLink.href = createDataURI(JSON.stringify(manifestData), "application/json"); | ||
document.head.append(manifestLink); | ||
} catch (err) { | ||
alert(err); | ||
} | ||
const url = new URL(document.location.href); | ||
sanitizePath(url); | ||
setInstantStart(url); | ||
setFullscreen(url); | ||
updateLocation(document.location, url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare let stretchMode: boolean; | ||
declare let resizeCanvas: (informC?: boolean) => void; | ||
declare let getStartInstantly: () => boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export function updateLocation(location: Location, url: URL) { | ||
if (url.href != location.href) location.replace(url); | ||
} | ||
|
||
export function sanitizePath(url: URL) { | ||
if (!url.pathname.endsWith("/")) url.pathname += "/"; | ||
} | ||
|
||
export function setSearchParam(url: URL, param: string, value: string | number, enable: boolean) { | ||
if (enable) url.searchParams.set(param, value.toString()); | ||
else url.searchParams.delete(param); | ||
} | ||
|
||
export function setFullscreen(url: URL, enable = true) { | ||
setSearchParam(url, "max_w", 9999, enable); | ||
setSearchParam(url, "max_h", 9999, enable); | ||
} | ||
|
||
export function setInstantStart(url: URL, enable = true) { | ||
setSearchParam(url, "istart", 1, enable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters