Skip to content

Commit

Permalink
feat: channel playlists, history page headers, many fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Saghen committed Mar 7, 2024
1 parent 4d9889a commit 5247f5a
Show file tree
Hide file tree
Showing 45 changed files with 1,978 additions and 1,920 deletions.
24 changes: 12 additions & 12 deletions extension/src/manifest.chrome.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"manifest_version": 3,
"action": {},
"background": {
"service_worker": "service-worker.js"
},
"permissions": ["cookies", "storage", "declarativeNetRequest"],
"host_permissions": [
"https://*.youtube.com/*",
"https://returnyoutubedislikeapi.com/*",
"https://yt3.ggpht.com/*",
"https://i.ytimg.com/*"
]
"manifest_version": 3,
"action": {},
"background": {
"service_worker": "service-worker.js"
},
"permissions": ["cookies", "storage", "declarativeNetRequest"],
"host_permissions": [
"https://*.youtube.com/*",
"https://returnyoutubedislikeapi.com/*",
"https://yt3.ggpht.com/*",
"https://i.ytimg.com/*"
]
}
46 changes: 23 additions & 23 deletions extension/src/manifest.firefox.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"browser_specific_settings": {
"gecko": {
"id": "[email protected]"
}
},
"action": {},
"manifest_version": 3,
"background": {
"scripts": ["service-worker.js"]
},
"permissions": [
"cookies",
"storage",
"contextualIdentities",
"declarativeNetRequest",
"declarativeNetRequestFeedback"
],
"host_permissions": [
"https://*.youtube.com/*",
"https://returnyoutubedislikeapi.com/*",
"https://yt3.ggpht.com/*",
"https://i.ytimg.com/*"
]
"browser_specific_settings": {
"gecko": {
"id": "[email protected]"
}
},
"action": {},
"manifest_version": 3,
"background": {
"scripts": ["service-worker.js"]
},
"permissions": [
"cookies",
"storage",
"contextualIdentities",
"declarativeNetRequest",
"declarativeNetRequestFeedback"
],
"host_permissions": [
"https://*.youtube.com/*",
"https://returnyoutubedislikeapi.com/*",
"https://yt3.ggpht.com/*",
"https://i.ytimg.com/*"
]
}
156 changes: 76 additions & 80 deletions extension/src/routes/proxy/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,98 +6,94 @@

/// RequestInit
export interface TransferableRequestInit {
/** A Base64 string or null to set request's body. */
body?: string | null;
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
cache?: RequestCache;
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */
credentials?: RequestCredentials;
/** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
headers?: [string, string][] | Record<string, string>;
/** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
integrity?: string;
/** A boolean to set request's keepalive. */
keepalive?: boolean;
/** A string to set request's method. */
method?: string;
/** A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. */
mode?: RequestMode;
/** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */
redirect?: RequestRedirect;
/** A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer. */
referrer?: string;
/** A referrer policy to set request's referrerPolicy. */
referrerPolicy?: ReferrerPolicy;
/** A Base64 string or null to set request's body. */
body?: string | null
/** A string indicating how the request will interact with the browser's cache to set request's cache. */
cache?: RequestCache
/** A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. */
credentials?: RequestCredentials
/** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
headers?: [string, string][] | Record<string, string>
/** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
integrity?: string
/** A boolean to set request's keepalive. */
keepalive?: boolean
/** A string to set request's method. */
method?: string
/** A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. */
mode?: RequestMode
/** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */
redirect?: RequestRedirect
/** A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer. */
referrer?: string
/** A referrer policy to set request's referrerPolicy. */
referrerPolicy?: ReferrerPolicy
}

export const transferableRequestInitToRequestInit = (
transferableRequest: TransferableRequestInit,
transferableRequest: TransferableRequestInit,
): RequestInit => ({
body:
transferableRequest.body && stringToArrayBuffer(transferableRequest.body),
cache: transferableRequest.cache,
credentials: transferableRequest.credentials,
headers: new Headers(transferableRequest.headers),
integrity: transferableRequest.integrity,
method: transferableRequest.method,
mode: transferableRequest.mode,
redirect: transferableRequest.redirect,
referrer: transferableRequest.referrer,
referrerPolicy: transferableRequest.referrerPolicy,
});
body: transferableRequest.body && stringToArrayBuffer(transferableRequest.body),
cache: transferableRequest.cache,
credentials: transferableRequest.credentials,
headers: new Headers(transferableRequest.headers),
integrity: transferableRequest.integrity,
method: transferableRequest.method,
mode: transferableRequest.mode,
redirect: transferableRequest.redirect,
referrer: transferableRequest.referrer,
referrerPolicy: transferableRequest.referrerPolicy,
})

export const requestInitToTransferableRequestInit = async (
requestInit: RequestInit,
requestInit: RequestInit,
): Promise<TransferableRequestInit> => ({
...requestInit,
body: requestInit.body && (await new Response(requestInit.body).text()),
// @ts-expect-error Valid but Typescript doesn't recognize it
headers:
requestInit.headers instanceof Headers
? requestInit.headers.entries()
: requestInit.headers,
});
...requestInit,
body: requestInit.body && (await new Response(requestInit.body).text()),
// @ts-expect-error Valid but Typescript doesn't recognize it
headers: requestInit.headers instanceof Headers ? requestInit.headers.entries() : requestInit.headers,
})

/// Response
type TransferableResponse = {
/** Base64 encoded */
body: null | string;
headers: Record<string, string>;
status: number;
statusText: string;
};
export const responseToTransferableResponse = async (
response: Response,
): Promise<TransferableResponse> => ({
body: response.body && (await response.text()),
headers: headersToObject(response.headers),
status: response.status,
statusText: response.statusText,
});
/** Base64 encoded */
body: null | string
headers: Record<string, string>
status: number
statusText: string
}
export const responseToTransferableResponse = async (response: Response): Promise<TransferableResponse> => ({
body: response.body && (await response.text()),
headers: headersToObject(response.headers),
status: response.status,
statusText: response.statusText,
})

export const transferableResponseToResponse = (
transferableResponse: TransferableResponse,
): Response =>
new Response(
transferableResponse.body && stringToArrayBuffer(transferableResponse.body),
{
headers: new Headers(transferableResponse.headers),
status: transferableResponse.status,
statusText: transferableResponse.statusText,
},
);
export const transferableResponseToResponse = (transferableResponse: TransferableResponse): Response =>
new Response(
[101, 204, 205, 304].includes(transferableResponse.status)
? null
: transferableResponse.body
? stringToArrayBuffer(transferableResponse.body)
: undefined,
{
headers: new Headers(transferableResponse.headers),
status: transferableResponse.status,
statusText: transferableResponse.statusText,
},
)

/// Helpers
const stringToArrayBuffer = (str: string) => {
const encoder = new TextEncoder();
return encoder.encode(str);
};
const encoder = new TextEncoder()
return encoder.encode(str)
}
const headersToObject = (headers: Headers) => {
const headersObject: Record<string, string> = {};
// no type-safe way to do it with for of that I know of
// biome-ignore lint/complexity/noForEach:
headers.forEach((value, key) => {
headersObject[key] = value;
});
return headersObject;
};
const headersObject: Record<string, string> = {}
// no type-safe way to do it with for of that I know of
// biome-ignore lint/complexity/noForEach:
headers.forEach((value, key) => {
headersObject[key] = value
})
return headersObject
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
"react-dom": "^18.2.0",
"styled-components": "^6.1.8",
"vite-tsconfig-paths": "^4.3.1",
"wouter": "^3.0.1"
"wouter": "^3.0.2"
},
"devDependencies": {
"@biomejs/biome": "^1.5.3",
"@preact/preset-vite": "^2.8.1",
"@styled/typescript-styled-plugin": "^1.0.1",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.20",
"@types/webextension-polyfill": "^0.10.7",
"@vitejs/plugin-react": "^4.2.1",
"husky": "^9.0.11",
Expand All @@ -48,8 +48,8 @@
"postcss-preset-mantine": "^1.13.0",
"postcss-simple-vars": "^7.0.1",
"prettier": "^3.2.5",
"typescript": "^5.3.3",
"vite": "^5.1.4",
"typescript": "^5.4.2",
"vite": "^5.1.5",
"vite-bundle-visualizer": "^1.0.1",
"vite-plugin-preload": "^0.3.1"
},
Expand Down
Loading

0 comments on commit 5247f5a

Please sign in to comment.