Skip to content

Commit

Permalink
feat: modify params for all windows
Browse files Browse the repository at this point in the history
  • Loading branch information
brckd committed Apr 13, 2024
1 parent 2c999ba commit 094d897
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 24 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## [1.0.1](https://github.com/brckd/fancade-plus/compare/v1.0.0...v1.0.1) (2024-04-13)


### Bug Fixes

* update dependenices ([fa0ee49](https://github.com/brckd/fancade-plus/commit/fa0ee491910c0705e032a168b528d23d3cb84dfa))
- update dependenices
([fa0ee49](https://github.com/brckd/fancade-plus/commit/fa0ee491910c0705e032a168b528d23d3cb84dfa))

# 1.0.0 (2024-04-13)

Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
A userscript to make [Fancade Web](https://play.fancade.com) more accessible on mobile.

## Features

- Install Fancade Web like a native app
- Always go full screen and play instantly on the installed app
- Instantly immerse into full-screen game play
- Physical keyboard support
- Increased feature parity

## Using

Install the [latest userscript](https://github.com/brckd/fancade-plus/releases/latest/download/fancade-plus.user.js) in a browser that supports doing so.
Install the
[latest userscript](https://github.com/brckd/fancade-plus/releases/latest/download/fancade-plus.user.js)
in a browser that supports doing so.

- [Cromite](https://github.com/uazo/cromite) and Bromite
[support userscripts natively](https://github.com/bromite/bromite/wiki/UserScripts).
Expand Down
19 changes: 8 additions & 11 deletions src/fancade-plus.user.ts
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);
3 changes: 3 additions & 0 deletions src/global.d.ts
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;
21 changes: 21 additions & 0 deletions src/location.ts
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);
}
24 changes: 15 additions & 9 deletions src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { JSONSchemaForWebApplicationManifestFiles as Manifest } from "@schemastore/web-manifest";

function getMetaContent(element: HTMLElement, name: string) {
return element.querySelector<HTMLMetaElement>(`meta[name~="${name}"], meta[property~="${name}"]`)
?.content;
export function createManifestLink(document: Document, data?: Manifest) {
if (!data) {
const url = new URL(document.location.href);
data = getManifestData(document.head, url);
}
const link = document.createElement("link");
link.rel = "manifest";
link.href = createDataURI(JSON.stringify(data), "application/json");
return link;
}

export function getManifestData(head: HTMLHeadElement, url: URL) {
const root = new URL("/", url);
const start = new URL(url);
if (!start.pathname.endsWith("/")) start.pathname += "/";
start.searchParams.set("istart", "1");
start.searchParams.set("max_w", "9999");
start.searchParams.set("max_h", "9999");
const color = "#00c9ff";

const manifest: Manifest = {
name: head.querySelector<HTMLTitleElement>("title")?.text,
description: getMetaContent(head, "description"),
start_url: start.href,
start_url: url.href,
scope: root.href,
display: "fullscreen",
theme_color: color,
Expand All @@ -33,6 +34,11 @@ export function getManifestData(head: HTMLHeadElement, url: URL) {
return manifest;
}

export function getMetaContent(element: HTMLElement, name: string) {
return element.querySelector<HTMLMetaElement>(`meta[name~="${name}"], meta[property~="${name}"]`)
?.content;
}

export function createDataURI(data: string, mediatype?: string, base64?: false): string;
export function createDataURI(data: Buffer, mediatype: string, base64: true): string;
export function createDataURI(data: string | Buffer, mediatype = "", base64 = false) {
Expand Down

0 comments on commit 094d897

Please sign in to comment.