13 Commits

Author SHA1 Message Date
William Oldham
86a659f478 Add explicit support for Firefox Android 2024-04-05 21:24:00 +01:00
William Oldham
dbdbf10c5d Close the prompt popup when clicking the button 2024-04-05 21:23:49 +01:00
William Oldham
6fca55a6c3 Bump version 2024-03-28 20:33:47 +00:00
William Oldham
50eadd3a14 Merge pull request #28 from movie-web/fix/#1047
fix ts error, fix styling on PermissionRequest
2024-03-28 20:33:24 +00:00
Jorrin
b2ba74bd97 fix ts error, fix styling on PermissionRequest 2024-03-28 20:26:09 +01:00
William Oldham
bb61fef30a Merge pull request #25 from movie-web/remove-lonelil
Remove Lonelil, fix centering and enable strict mode
2024-03-15 19:44:19 +00:00
William Oldham
8e179e4455 Remove any in error handling 2024-03-15 19:42:51 +00:00
William Oldham
327f175241 Do safe checking on exception message 2024-03-15 19:39:03 +00:00
William Oldham
c72ec41228 Bump version 2024-03-15 19:24:07 +00:00
William Oldham
0bd1a39b53 Remove react import 2024-03-15 19:24:03 +00:00
William Oldham
de0a1b3849 Fix centering of permission grant page 2024-03-15 18:53:44 +00:00
William Oldham
8ba0544468 Enable TS strict mode and fix all associated errors 2024-03-15 18:49:12 +00:00
William Oldham
a884c785f0 Remove lonelil as a redirect, Firefox didn't like 2024-03-15 18:48:46 +00:00
15 changed files with 59 additions and 28 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "@movie-web/extension", "name": "@movie-web/extension",
"displayName": "movie-web extension", "displayName": "movie-web extension",
"version": "1.1.2", "version": "1.1.4",
"description": "Enhance your movie-web experience with just one click", "description": "Enhance your movie-web experience with just one click",
"author": "movie-web", "author": "movie-web",
"scripts": { "scripts": {
@@ -53,6 +53,9 @@
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
"id": "{3fd86354-c73f-4395-9e26-2c5c984579bf}" "id": "{3fd86354-c73f-4395-9e26-2c5c984579bf}"
},
"gecko_android": {
"id": "{3fd86354-c73f-4395-9e26-2c5c984579bf}"
} }
}, },
"web_accessible_resources": [ "web_accessible_resources": [

View File

@@ -14,6 +14,8 @@ type Response = BaseResponse<{
const handler: PlasmoMessaging.MessageHandler<BaseRequest, Response> = async (req, res) => { const handler: PlasmoMessaging.MessageHandler<BaseRequest, Response> = async (req, res) => {
try { try {
if (!req.sender?.tab?.url) throw new Error('No tab URL found in the request.');
const version = getVersion(); const version = getVersion();
res.send({ res.send({
success: true, success: true,
@@ -24,7 +26,7 @@ const handler: PlasmoMessaging.MessageHandler<BaseRequest, Response> = async (re
} catch (err) { } catch (err) {
res.send({ res.send({
success: false, success: false,
error: err.message, error: err instanceof Error ? err.message : String(err),
}); });
} }
}; };

View File

@@ -32,7 +32,7 @@ type Response<T> = BaseResponse<{
const mapBodyToFetchBody = (body: Request['body'], bodyType: Request['bodyType']): BodyInit => { const mapBodyToFetchBody = (body: Request['body'], bodyType: Request['bodyType']): BodyInit => {
if (bodyType === 'FormData') { if (bodyType === 'FormData') {
const formData = new FormData(); const formData = new FormData();
body.forEach(([key, value]) => { body.forEach(([key, value]: [any, any]) => {
formData.append(key, value.toString()); formData.append(key, value.toString());
}); });
} }
@@ -50,6 +50,9 @@ const mapBodyToFetchBody = (body: Request['body'], bodyType: Request['bodyType']
const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (req, res) => { const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (req, res) => {
try { try {
if (!req.sender?.tab?.url) throw new Error('No tab URL found in the request.');
if (!req.body) throw new Error('No request body found in the request.');
const url = makeFullUrl(req.body.url, req.body); const url = makeFullUrl(req.body.url, req.body);
await assertDomainWhitelist(req.sender.tab.url); await assertDomainWhitelist(req.sender.tab.url);
@@ -91,7 +94,7 @@ const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (r
console.error('failed request', err); console.error('failed request', err);
res.send({ res.send({
success: false, success: false,
error: err.message, error: err instanceof Error ? err.message : String(err),
}); });
} }
}; };

View File

@@ -11,6 +11,9 @@ type Request = BaseRequest & {
const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (req, res) => { const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (req, res) => {
try { try {
if (!req.sender?.tab?.id) throw new Error('No tab ID found in the request.');
if (!req.body) throw new Error('No body found in the request.');
const searchParams = new URLSearchParams(); const searchParams = new URLSearchParams();
searchParams.set('redirectUrl', req.body.redirectUrl); searchParams.set('redirectUrl', req.body.redirectUrl);
const url = (chrome || browser).runtime.getURL(`/tabs/${req.body.page}.html?${searchParams.toString()}`); const url = (chrome || browser).runtime.getURL(`/tabs/${req.body.page}.html?${searchParams.toString()}`);
@@ -29,7 +32,7 @@ const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (re
} catch (err) { } catch (err) {
res.send({ res.send({
success: false, success: false,
error: err.message, error: err instanceof Error ? err.message : String(err),
}); });
} }
}; };

View File

@@ -15,6 +15,9 @@ interface Request extends BaseRequest {
const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (req, res) => { const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (req, res) => {
try { try {
if (!req.sender?.tab?.url) throw new Error('No tab URL found in the request.');
if (!req.body) throw new Error('No request body found in the request.');
await assertDomainWhitelist(req.sender.tab.url); await assertDomainWhitelist(req.sender.tab.url);
await setDynamicRules(req.body); await setDynamicRules(req.body);
res.send({ res.send({
@@ -23,7 +26,7 @@ const handler: PlasmoMessaging.MessageHandler<Request, BaseResponse> = async (re
} catch (err) { } catch (err) {
res.send({ res.send({
success: false, success: false,
error: err.message, error: err instanceof Error ? err.message : String(err),
}); });
} }
}; };

View File

@@ -9,6 +9,7 @@ export function SetupScreen() {
const open = useCallback(() => { const open = useCallback(() => {
const url = (chrome || browser).runtime.getURL(`/tabs/PermissionRequest.html`); const url = (chrome || browser).runtime.getURL(`/tabs/PermissionRequest.html`);
(chrome || browser).tabs.create({ url }); (chrome || browser).tabs.create({ url });
window.close();
}, []); }, []);
return ( return (

View File

@@ -15,5 +15,5 @@ export function useDomain(): null | string {
}; };
}, []); }, []);
return makeUrlIntoDomain(domain); return domain ? makeUrlIntoDomain(domain) : null;
} }

View File

@@ -8,12 +8,12 @@ export function useDomainWhitelist() {
const removeDomain = useCallback((domain: string | null) => { const removeDomain = useCallback((domain: string | null) => {
if (!domain) return; if (!domain) return;
setDomainWhitelist((s) => [...s.filter((v) => v !== domain)]); setDomainWhitelist((s) => [...(s ?? []).filter((v) => v !== domain)]);
}, []); }, []);
const addDomain = useCallback((domain: string | null) => { const addDomain = useCallback((domain: string | null) => {
if (!domain) return; if (!domain) return;
setDomainWhitelist((s) => [...s.filter((v) => v !== domain), domain]); setDomainWhitelist((s) => [...(s ?? []).filter((v) => v !== domain), domain]);
}, []); }, []);
return { return {
@@ -23,9 +23,9 @@ export function useDomainWhitelist() {
}; };
} }
export function useToggleWhitelistDomain(domain: string) { export function useToggleWhitelistDomain(domain: string | null) {
const { domainWhitelist, addDomain, removeDomain } = useDomainWhitelist(); const { domainWhitelist, addDomain, removeDomain } = useDomainWhitelist();
const isWhitelisted = domainWhitelist.includes(domain); const isWhitelisted = domainWhitelist.includes(domain ?? '');
const { grantPermission } = usePermission(); const { grantPermission } = usePermission();
const iconPath = (chrome || browser).runtime.getURL(isWhitelisted ? 'assets/active.png' : 'assets/inactive.png'); const iconPath = (chrome || browser).runtime.getURL(isWhitelisted ? 'assets/active.png' : 'assets/inactive.png');

View File

@@ -28,7 +28,7 @@ function IndexPopup() {
) : ( ) : (
<Frame> <Frame>
<div className="popup"> <div className="popup">
{page === 'toggle' ? <ToggleButton active={isWhitelisted} onClick={toggle} domain={domain} /> : null} {page === 'toggle' && domain ? <ToggleButton active={isWhitelisted} onClick={toggle} domain={domain} /> : null}
{page === 'disabled' ? <DisabledScreen /> : null} {page === 'disabled' ? <DisabledScreen /> : null}
<BottomLabel /> <BottomLabel />
</div> </div>

View File

@@ -13,7 +13,7 @@ body {
#__plasmo { #__plasmo {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-height: 100%; height: 100%;
background-color: #0A0A10; background-color: #0A0A10;
} }

View File

@@ -8,11 +8,27 @@ export default function PermissionGrant() {
const { grantPermission } = usePermission(); const { grantPermission } = usePermission();
const queryParams = new URLSearchParams(window.location.search); const queryParams = new URLSearchParams(window.location.search);
const redirectUrl = queryParams.get('redirectUrl') ?? 'https://mw.lonelil.ru'; const redirectUrl = queryParams.get('redirectUrl') ?? undefined;
const domain = makeUrlIntoDomain(redirectUrl); const domain = redirectUrl ? makeUrlIntoDomain(redirectUrl) : undefined;
if (!domain) {
return (
<div className="permission-grant container">
<div className="inner-container">
<div className="permission-card">
<h1 className="color-white">Permission</h1>
<p className="text-color" style={{ textAlign: 'center' }}>
No domain found to grant permission to.
</p>
</div>
</div>
</div>
);
}
const redirectBack = () => { const redirectBack = () => {
chrome.tabs.getCurrent((tab) => { chrome.tabs.getCurrent((tab) => {
if (!tab?.id) return;
chrome.tabs.update(tab.id, { url: redirectUrl }); chrome.tabs.update(tab.id, { url: redirectUrl });
}); });
}; };

View File

@@ -10,6 +10,10 @@ body {
padding-bottom: 50px; padding-bottom: 50px;
} }
#__plasmo {
height: unset;
}
.permission-request.container { .permission-request.container {
width: 90%; width: 90%;
margin: 100px auto; margin: 100px auto;

View File

@@ -123,5 +123,6 @@ export const removeDynamicRules = async (ruleIds: number[]) => {
await (chrome || browser).declarativeNetRequest.updateDynamicRules({ await (chrome || browser).declarativeNetRequest.updateDynamicRules({
removeRuleIds: ruleIds, removeRuleIds: ruleIds,
}); });
if ((chrome || browser).runtime.lastError?.message) throw new Error((chrome || browser).runtime.lastError.message); if ((chrome || browser).runtime.lastError?.message)
throw new Error((chrome || browser).runtime.lastError?.message ?? 'Unknown error');
}; };

View File

@@ -1,7 +1,7 @@
import { isChrome } from './extension'; import { isChrome } from './extension';
export function queryCurrentDomain(cb: (domain: string | null) => void) { export function queryCurrentDomain(cb: (domain: string | null) => void) {
const handle = (tabUrl: string | null) => { const handle = (tabUrl: string | undefined) => {
if (!tabUrl) cb(null); if (!tabUrl) cb(null);
else cb(tabUrl); else cb(tabUrl);
}; };

View File

@@ -1,18 +1,13 @@
{ {
"extends": "plasmo/templates/tsconfig.base", "extends": "plasmo/templates/tsconfig.base",
"exclude": [ "exclude": ["node_modules"],
"node_modules" "include": [".plasmo/index.d.ts", "./**/*.ts", "./**/*.tsx"],
],
"include": [
".plasmo/index.d.ts",
"./**/*.ts",
"./**/*.tsx"
],
"compilerOptions": { "compilerOptions": {
"jsx": "react-jsx",
"strict": true,
"paths": { "paths": {
"~*": [ "~*": ["./src/*"]
"./src/*"
]
}, },
"baseUrl": "." "baseUrl": "."
} }