Skip to content

Commit e684b6f

Browse files
committed
Fixed build
1 parent 2e6eee1 commit e684b6f

9 files changed

Lines changed: 151 additions & 68 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
export default {
23
cssFilter: 'cssFilter',
34
svgFilter: 'svgFilter',

src/ui/devtools/components/body.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import {m} from 'malevic';
33
import {getContext, tags} from 'malevic/dom';
44
import {withState, useState} from 'malevic/state';
5-
import {Button, MessageBox, Overlay as OverlayLegacy} from '../../controls';
5+
import Button from '../../controls/button';
6+
import MessageBox from '../../controls/message-box';
7+
import OverlayLegacy from '../../controls/overlay';
68
import ThemeEngines from '../../../generators/theme-engines';
79
import {DEVTOOLS_DOCS_URL} from '../../../utils/links';
810
import {getCurrentThemePreset} from '../../popup/theme/utils';

src/ui/devtools/index.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {m} from 'malevic';
1+
// @ts-check
22
import {sync} from 'malevic/dom';
33
import Body from './components/body';
44
import Connector from '../connect/connector';
@@ -12,7 +12,7 @@ import Connector from '../connect/connector';
1212
* @param {Connector} actions
1313
*/
1414
function renderBody(data, tab, actions) {
15-
sync(document.body, <Body data={data} tab={tab} actions={actions} />);
15+
sync(document.body, Body({data, tab, actions}));
1616
}
1717

1818
async function start() {
@@ -27,31 +27,31 @@ async function start() {
2727

2828
start();
2929

30-
// if (__DEBUG__) {
31-
// const socket = new WebSocket(`ws://localhost:8894`);
32-
// socket.onmessage = (e) => {
33-
// /** @type {(message: {type: string; id: number; data?: string}) => void} */
34-
// const respond = (message) => socket.send(JSON.stringify(message));
35-
// /** @type {{type: string; id: number; data: string}} */
36-
// const message = JSON.parse(e.data);
37-
// try {
38-
// /** @type {HTMLTextAreaElement} */
39-
// const textarea = document.querySelector('textarea#editor');
40-
// const [buttonReset, buttonApply] = document.querySelectorAll('button');
41-
// switch (message.type) {
42-
// case 'debug-devtools-paste':
43-
// textarea.value = message.data;
44-
// buttonApply.click();
45-
// respond({type: 'debug-devtools-paste-response', id: message.id});
46-
// break;
47-
// case 'debug-devtools-reset':
48-
// respond({type: 'debug-devtools-reset-response', id: message.id});
49-
// buttonReset.click();
50-
// /** @type {HTMLButtonElement} */(document.querySelector('button.message-box__button-ok')).click();
51-
// break;
52-
// }
53-
// } catch (err) {
54-
// respond({type: 'error', id: message.id, data: String(err)});
55-
// }
56-
// };
57-
// }
30+
if (__DEBUG__) {
31+
const socket = new WebSocket(`ws://localhost:8894`);
32+
socket.onmessage = (e) => {
33+
/** @type {(message: {type: string; id: number; data?: string}) => void} */
34+
const respond = (message) => socket.send(JSON.stringify(message));
35+
/** @type {{type: string; id: number; data: string}} */
36+
const message = JSON.parse(e.data);
37+
try {
38+
/** @type {HTMLTextAreaElement} */
39+
const textarea = document.querySelector('textarea#editor');
40+
const [buttonReset, buttonApply] = document.querySelectorAll('button');
41+
switch (message.type) {
42+
case 'debug-devtools-paste':
43+
textarea.value = message.data;
44+
buttonApply.click();
45+
respond({type: 'debug-devtools-paste-response', id: message.id});
46+
break;
47+
case 'debug-devtools-reset':
48+
respond({type: 'debug-devtools-reset-response', id: message.id});
49+
buttonReset.click();
50+
/** @type {HTMLButtonElement} */(document.querySelector('button.message-box__button-ok')).click();
51+
break;
52+
}
53+
} catch (err) {
54+
respond({type: 'error', id: message.id, data: String(err)});
55+
}
56+
};
57+
}
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import type {Theme} from '../../../definitions';
1+
// @ts-check
22
import {isURLInList} from '../../../utils/url';
3-
import type {ViewProps} from '../types';
43

5-
export function getCurrentThemePreset(props: ViewProps) {
4+
/** @typedef {import('../types').ViewProps} ViewProps */
5+
/** @typedef {import('../../../definitions').Theme} Theme */
6+
7+
/**
8+
* @param {ViewProps} props
9+
* @returns {{theme: Theme; change: (theme: Partial<Theme>) => void}}
10+
*/
11+
export function getCurrentThemePreset(props) {
612
const custom = props.data.settings.customThemes.find(
713
({url}) => isURLInList(props.tab.url, url)
814
);
@@ -15,7 +21,10 @@ export function getCurrentThemePreset(props: ViewProps) {
1521
preset.theme :
1622
props.data.settings.theme;
1723

18-
function setTheme(config: Partial<Theme>) {
24+
/**
25+
* @param {Partial<Theme>} config
26+
*/
27+
function setTheme(config) {
1928
if (custom) {
2029
custom.theme = {...custom.theme, ...config};
2130
props.actions.changeSettings({
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
export function isIPV6(url: string) {
1+
// @ts-check
2+
/**
3+
* @param {string} url
4+
* @returns {boolean}
5+
*/
6+
export function isIPV6(url) {
27
const openingBracketIndex = url.indexOf('[');
38
if (openingBracketIndex < 0) {
49
return false;
@@ -12,7 +17,12 @@ export function isIPV6(url: string) {
1217

1318
const ipV6HostRegex = /\[.*?\](\:\d+)?/;
1419

15-
export function compareIPV6(firstURL: string, secondURL: string) {
20+
/**
21+
* @param {string} firstURL
22+
* @param {string} secondURL
23+
* @returns {boolean}
24+
*/
25+
export function compareIPV6(firstURL, secondURL) {
1626
const firstHost = firstURL.match(ipV6HostRegex)[0];
1727
const secondHost = secondURL.match(ipV6HostRegex)[0];
1828
return firstHost === secondHost;
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
import {getUILanguage} from './locales';
23

34
export const BLOG_URL = 'https://darkreader.org/blog/';
@@ -30,6 +31,10 @@ export function getHelpURL() {
3031
return `https://darkreader.org/help/${matchLocale}/`;
3132
}
3233

33-
export function getBlogPostURL(postId: string) {
34+
/**
35+
* @param {string} postId
36+
* @returns {string}
37+
*/
38+
export function getBlogPostURL(postId) {
3439
return `${BLOG_URL}${postId}/`;
3540
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
export function getLocalMessage(messageName: string) {
1+
// @ts-check
2+
/**
3+
* @param {string} messageName
4+
* @returns {string}
5+
*/
6+
export function getLocalMessage(messageName) {
27
return chrome.i18n.getMessage(messageName);
38
}
49

510
export function getUILanguage() {
6-
let code: string;
11+
/** @type {string} */
12+
let code;
713
if ('i18n' in chrome && 'getUILanguage' in chrome.i18n && typeof chrome.i18n.getUILanguage === 'function') {
814
code = chrome.i18n.getUILanguage();
915
} else {

src/utils/url.ts renamed to src/utils/url.js

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1-
import type {UserSettings} from '../definitions';
1+
// @ts-check
22
import {isIPV6, compareIPV6} from './ipv6';
33
import {isThunderbird} from './platform';
44

5-
let anchor: HTMLAnchorElement;
5+
/** @typedef {import('../definitions').UserSettings} UserSettings */
66

7-
export const parsedURLCache = new Map<string, URL>();
7+
/** @type {HTMLAnchorElement} */
8+
let anchor;
89

9-
function fixBaseURL($url: string) {
10+
/** @type {Map<string, URL>} */
11+
export const parsedURLCache = new Map();
12+
13+
function fixBaseURL(/** @type {string} */$url) {
1014
if (!anchor) {
1115
anchor = document.createElement('a');
1216
}
1317
anchor.href = $url;
1418
return anchor.href;
1519
}
1620

17-
export function parseURL($url: string, $base: string = null) {
18-
const key = `${$url}${$base ? `;${ $base}` : ''}`;
21+
/**
22+
* @param {string} $url
23+
* @param {string} [$base]
24+
* @returns {URL}
25+
*/
26+
export function parseURL($url, $base = null) {
27+
const key = `${$url}${$base ? `;${$base}` : ''}`;
1928
if (parsedURLCache.has(key)) {
2029
return parsedURLCache.get(key);
2130
}
@@ -29,7 +38,12 @@ export function parseURL($url: string, $base: string = null) {
2938
return parsedURL;
3039
}
3140

32-
export function getAbsoluteURL($base: string, $relative: string) {
41+
/**
42+
* @param {string} $base
43+
* @param {string} $relative
44+
* @returns {string}
45+
*/
46+
export function getAbsoluteURL($base, $relative) {
3347
if ($relative.match(/^data\\?\:/)) {
3448
return $relative;
3549
}
@@ -48,7 +62,11 @@ export function getAbsoluteURL($base: string, $relative: string) {
4862
// But https://duck.com/styles/ext.css would return false on https://duck.com/
4963
// Visa versa https://duck.com/ext.css should return fasle on https://duck.com/search/
5064
// We're checking if any relative value within ext.css could potentially not be on the same path.
51-
export function isRelativeHrefOnAbsolutePath(href: string): boolean {
65+
/**
66+
* @param {string} href
67+
* @returns {boolean}
68+
*/
69+
export function isRelativeHrefOnAbsolutePath(href) {
5270
if (href.startsWith('data:')) {
5371
return true;
5472
}
@@ -68,7 +86,11 @@ export function isRelativeHrefOnAbsolutePath(href: string): boolean {
6886
return url.pathname === location.pathname;
6987
}
7088

71-
export function getURLHostOrProtocol($url: string) {
89+
/**
90+
* @param {string} $url
91+
* @returns {string}
92+
*/
93+
export function getURLHostOrProtocol($url) {
7294
const url = new URL($url);
7395
if (url.host) {
7496
return url.host;
@@ -78,16 +100,22 @@ export function getURLHostOrProtocol($url: string) {
78100
return url.protocol;
79101
}
80102

81-
export function compareURLPatterns(a: string, b: string) {
103+
/**
104+
* @param {string} a
105+
* @param {string} b
106+
* @returns {number}
107+
*/
108+
export function compareURLPatterns(a, b) {
82109
return a.localeCompare(b);
83110
}
84111

85112
/**
86113
* Determines whether URL has a match in URL template list.
87-
* @param url Site URL.
88-
* @paramlist List to search into.
114+
* @param {string} url Site URL.
115+
* @param {string[]} list List to search into.
116+
* @returns {boolean}
89117
*/
90-
export function isURLInList(url: string, list: string[]) {
118+
export function isURLInList(url, list) {
91119
for (let i = 0; i < list.length; i++) {
92120
if (isURLMatched(url, list[i])) {
93121
return true;
@@ -98,10 +126,11 @@ export function isURLInList(url: string, list: string[]) {
98126

99127
/**
100128
* Determines whether URL matches the template.
101-
* @param url URL.
102-
* @param urlTemplate URL template ("google.*", "youtube.com" etc).
129+
* @param {string} url URL.
130+
* @param {string} urlTemplate URL template ("google.*", "youtube.com" etc).
131+
* @returns {boolean}
103132
*/
104-
export function isURLMatched(url: string, urlTemplate: string): boolean {
133+
export function isURLMatched(url, urlTemplate) {
105134
const isFirstIPV6 = isIPV6(url);
106135
const isSecondIPV6 = isIPV6(urlTemplate);
107136
if (isFirstIPV6 && isSecondIPV6) {
@@ -113,7 +142,11 @@ export function isURLMatched(url: string, urlTemplate: string): boolean {
113142
return false;
114143
}
115144

116-
function createUrlRegex(urlTemplate: string): RegExp {
145+
/**
146+
* @param {string} urlTemplate
147+
* @returns {RegExp}
148+
*/
149+
function createUrlRegex(urlTemplate) {
117150
urlTemplate = urlTemplate.trim();
118151
const exactBeginning = (urlTemplate[0] === '^');
119152
const exactEnding = (urlTemplate[urlTemplate.length - 1] === '$');
@@ -126,9 +159,12 @@ function createUrlRegex(urlTemplate: string): RegExp {
126159
.replace(/\/$/, '') // Remove last slash
127160
);
128161

129-
let slashIndex: number;
130-
let beforeSlash: string;
131-
let afterSlash: string;
162+
/** @type {number} */
163+
let slashIndex;
164+
/** @type {string} */
165+
let beforeSlash;
166+
/** @type {string} */
167+
let afterSlash;
132168
if ((slashIndex = urlTemplate.indexOf('/')) >= 0) {
133169
beforeSlash = urlTemplate.substring(0, slashIndex); // google.*
134170
afterSlash = urlTemplate.replace(/\$/g, '').substring(slashIndex); // /login/abc
@@ -177,7 +213,11 @@ function createUrlRegex(urlTemplate: string): RegExp {
177213
return new RegExp(result, 'i');
178214
}
179215

180-
export function isPDF(url: string) {
216+
/**
217+
* @param {string} url
218+
* @returns {boolean}
219+
*/
220+
export function isPDF(url) {
181221
if (url.includes('.pdf')) {
182222
if (url.includes('?')) {
183223
url = url.substring(0, url.lastIndexOf('?'));
@@ -206,7 +246,13 @@ export function isPDF(url: string) {
206246
return false;
207247
}
208248

209-
export function isURLEnabled(url: string, userSettings: UserSettings, {isProtected, isInDarkList}: {isProtected: boolean; isInDarkList: boolean}) {
249+
/**
250+
* @param {string} url
251+
* @param {UserSettings} userSettings
252+
* @param {{isProtected: boolean; isInDarkList: boolean}} urlInfo
253+
* @returns {boolean}
254+
*/
255+
export function isURLEnabled(url, userSettings, {isProtected, isInDarkList}) {
210256
if (isProtected && !userSettings.enableForProtectedPages) {
211257
return false;
212258
}
@@ -231,6 +277,10 @@ export function isURLEnabled(url: string, userSettings: UserSettings, {isProtect
231277
return (!isInDarkList && !isURLInUserList);
232278
}
233279

234-
export function isFullyQualifiedDomain(candidate: string) {
280+
/**
281+
* @param {string} candidate
282+
* @returns {boolean}
283+
*/
284+
export function isFullyQualifiedDomain(candidate) {
235285
return /^[a-z0-9.-]+$/.test(candidate);
236286
}

tasks/build.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const buildTask = [
2929

3030
async function build({debug, watch}) {
3131
log.ok('BUILD');
32-
try {
32+
// try {
3333
await runTasks(debug ? standardTask : buildTask, {debug, watch});
3434
if (watch) {
3535
standardTask.forEach((task) => task.watch());
@@ -38,10 +38,10 @@ async function build({debug, watch}) {
3838
} else {
3939
log.ok('MISSION PASSED! RESPECT +');
4040
}
41-
} catch (err) {
42-
log.error(`MISSION FAILED!`);
43-
process.exit(13);
44-
}
41+
// } catch (err) {
42+
// log.error(`MISSION FAILED!`);
43+
// process.exit(13);
44+
// }
4545
}
4646

4747
async function api() {

0 commit comments

Comments
 (0)