forked from Kholid060/inspect-css
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-script.js
More file actions
62 lines (44 loc) · 1.6 KB
/
content-script.js
File metadata and controls
62 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* eslint-disable import/no-webpack-loader-syntax */
import app, { insertShadowRoot } from './main';
import appCss from '!to-string-loader!css-loader!postcss-loader!../assets/css/content-script/app.css';
import contentCss from '!to-string-loader!css-loader!postcss-loader!../assets/css/content-script/style.css';
function generateCSS() {
const style = document.createElement('style');
style.innerText = contentCss;
document.body.appendChild(style);
return function () {
document.body.removeChild(style);
};
}
function generateContent(container) {
const content = document.createElement('div');
const style = document.createElement('style');
style.innerText = appCss;
app.mount(content);
container.shadowRoot.appendChild(content);
container.shadowRoot.appendChild(style);
return function () {
app.unmount();
document.body.removeChild(container);
};
}
(() => {
const isAppExist = document.querySelector('.inspect-css');
if (isAppExist) return;
const container = document.createElement('div');
container.attachShadow({ mode: 'open' });
container.classList = 'inspect-css';
insertShadowRoot(container.shadowRoot);
const content = generateContent(container);
const css = generateCSS();
app.config.globalProperties.destoryExtension = () => {
content();
css();
const activeElement = document.querySelector('[active-element]');
if (activeElement) activeElement.removeAttribute('active-element');
['pause', 'display-grid'].forEach((classes) => {
document.body.classList.remove(classes);
});
};
document.body.appendChild(container);
})();