Skip to content

Commit 730083a

Browse files
committed
make linter happy
1 parent 6d3be48 commit 730083a

File tree

5 files changed

+20
-34
lines changed

5 files changed

+20
-34
lines changed

addon/[email protected]

5.01 KB
Loading

lib/runOnPage.js

+7-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import _ from 'lodash';
2-
3-
const makeIdent = () => _.times(20, () => _.random(35).toString(36)).join('');
1+
const makeIdent = () => Math.random().toString(36).substring(2, 10);
42

53
export default function runOnPage(func) {
64
return (...args) => new Promise((resolve, reject) => {
@@ -22,15 +20,15 @@ export default function runOnPage(func) {
2220
const serializedArgs = args.map(x => {
2321
if (x instanceof Element) {
2422
if (x.id) {
25-
return { id: x.id };
23+
return `document.getElementById(${JSON.stringify(x.id)})`;
2624
} else {
2725
x.id = makeIdent();
28-
return { tempId: x.id };
26+
return `(() => { const elem = document.getElementById(${JSON.stringify(x.id)}); elem.id = ''; return elem; })()`;
2927
}
3028
} else if (typeof x === 'function') {
31-
return { func: x.toString() };
29+
return `(() => ${x.toString()})()`;
3230
} else {
33-
return { val: x };
31+
return JSON.stringify(x);
3432
}
3533
});
3634

@@ -41,21 +39,7 @@ export default function runOnPage(func) {
4139
const scriptContent = `
4240
(async () => {
4341
try {
44-
const serializedArgs = ${JSON.stringify(serializedArgs)};
45-
const args = serializedArgs.map(x => {
46-
if ('id' in x) {
47-
return document.getElementById(x.id);
48-
} else if ('tempId' in x) {
49-
const elem = document.getElementById(x.tempId);
50-
elem.id = '';
51-
return elem;
52-
} else if ('func' in x) {
53-
const generate = new Function('return ' + x.func);
54-
return generate();
55-
} else {
56-
return x.val;
57-
}
58-
});
42+
const args = [${serializedArgs.join(',')}];
5943
const ret = await (${serialized})(...args);
6044
window.postMessage({ ident: ${JSON.stringify(ident)}, ret });
6145
} catch (err) {
@@ -67,7 +51,7 @@ export default function runOnPage(func) {
6751
`;
6852

6953
const script = document.createElement('script');
70-
script.innerHTML = scriptContent;
54+
script.text = scriptContent;
7155
document.documentElement.prepend(script);
7256
});
7357
}

package.json

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"build:dev:js": "webpack",
9-
"build:prod:js": "webpack --env production",
10-
"build:unsigned:ext": "cd addon && web-ext build --overwrite-dest",
11-
"build:signed:ext": "cd addon && web-ext sign",
12-
"build:unsigned": "yarn run build:dev:js && yarn run build:unsigned:ext",
13-
"build:signed": "yarn run build:prod:js && yarn run build:signed:ext",
14-
"build": "yarn run build:unsigned",
8+
"build:js:dev": "webpack",
9+
"build:js:prod": "webpack --env production",
10+
"build:ext:unsigned": "cd addon && web-ext build --overwrite-dest",
11+
"build:ext:signed": "cd addon && web-ext sign",
12+
"build:dev": "yarn run build:js:dev && yarn run build:ext:unsigned",
13+
"build:prod:unsigned": "yarn run build:js:prod && yarn run build:ext:unsigned",
14+
"build:prod:signed": "yarn run build:js:prod && yarn run build:ext:signed",
15+
"build": "yarn run build:dev",
1516
"start:firefox": "webpack watch",
1617
"start:chromium": "webpack watch --env chromium",
1718
"start": "yarn run start:firefox"
@@ -25,8 +26,6 @@
2526
"webpack": "^5.23.0",
2627
"webpack-cli": "^4.5.0"
2728
},
28-
"dependencies": {
29-
"lodash": "^4.17.20"
30-
},
29+
"dependencies": {},
3130
"type": "module"
3231
}

screenshots/ollie.png

93 KB
Loading

webpack.config.mjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ const config = env => ({
2626
profileCreateIfMissing: true,
2727
keepProfileChanges: true
2828
})
29-
]
29+
],
30+
node: {
31+
global: false
32+
}
3033
});
3134

3235
export default config;

0 commit comments

Comments
 (0)