Skip to content

Commit c951b12

Browse files
committed
chore: refacto code
1 parent bc7c987 commit c951b12

15 files changed

+799
-130
lines changed

.eslintrc.js

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
11
module.exports = {
2-
env: {
3-
browser: true,
4-
commonjs: true,
5-
es6: true,
6-
},
7-
extends: [
8-
'plugin:vue/essential',
9-
'airbnb-base',
10-
],
11-
globals: {
12-
Atomics: 'readonly',
13-
SharedArrayBuffer: 'readonly',
14-
},
15-
parserOptions: {
16-
ecmaVersion: 2018,
17-
},
18-
plugins: [
19-
'vue',
20-
],
21-
rules: {
22-
"at-rule-no-unknown": [true, {
23-
ignoreAtRules: [
24-
/apply/,
25-
/tailwind/,
26-
/screen/,
27-
/if/,
28-
/else/,
29-
/return/,
30-
/function/,
31-
/debug/
32-
]
33-
}],
34-
"declaration-block-trailing-semicolon": null,
35-
"no-descending-specificity": null
36-
},
37-
};
2+
"env": {
3+
"browser": true,
4+
"es6": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:vue/essential"
9+
],
10+
"globals": {
11+
"Atomics": "readonly",
12+
"SharedArrayBuffer": "readonly"
13+
},
14+
"parserOptions": {
15+
"ecmaVersion": 2018,
16+
"sourceType": "module"
17+
},
18+
"plugins": [
19+
"vue"
20+
],
21+
"rules": {
22+
}
23+
};

.history/.eslintrc_20200428103401.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
commonjs: true,
5+
es6: true,
6+
},
7+
extends: [
8+
'plugin:vue/essential',
9+
'airbnb-base',
10+
],
11+
globals: {
12+
Atomics: 'readonly',
13+
SharedArrayBuffer: 'readonly',
14+
},
15+
parserOptions: {
16+
ecmaVersion: 2018,
17+
},
18+
plugins: [
19+
'vue',
20+
],
21+
rules: {
22+
"at-rule-no-unknown": [true, {
23+
ignoreAtRules: [
24+
/apply/,
25+
/tailwind/,
26+
/screen/,
27+
/if/,
28+
/else/,
29+
/return/,
30+
/function/,
31+
/debug/
32+
]
33+
}],
34+
"declaration-block-trailing-semicolon": null,
35+
"no-descending-specificity": null
36+
},
37+
};

.history/.eslintrc_20200507105239.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
commonjs: true,
5+
es6: true,
6+
},
7+
extends: [
8+
'plugin:vue/essential',
9+
'airbnb-base',
10+
],
11+
globals: {
12+
Atomics: 'readonly',
13+
SharedArrayBuffer: 'readonly',
14+
},
15+
parserOptions: {
16+
ecmaVersion: 2018,
17+
},
18+
plugins: [
19+
'vue',
20+
],
21+
rules: {
22+
"at-rule-no-unknown": [null, {
23+
ignoreAtRules: [
24+
/apply/,
25+
/tailwind/,
26+
/screen/,
27+
/if/,
28+
/else/,
29+
/return/,
30+
/function/,
31+
/debug/
32+
]
33+
}],
34+
"declaration-block-trailing-semicolon": null,
35+
"no-descending-specificity": null
36+
},
37+
};

.history/.eslintrc_20200507105304.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
commonjs: true,
5+
es6: true,
6+
},
7+
extends: [
8+
'plugin:vue/essential',
9+
'airbnb-base',
10+
],
11+
globals: {
12+
Atomics: 'readonly',
13+
SharedArrayBuffer: 'readonly',
14+
},
15+
parserOptions: {
16+
ecmaVersion: 2018,
17+
},
18+
plugins: [
19+
'vue',
20+
],
21+
rules: {
22+
"scss/at-rule-no-unknown": [true, {
23+
ignoreAtRules: [
24+
/apply/,
25+
/tailwind/,
26+
/screen/,
27+
/if/,
28+
/else/,
29+
/return/,
30+
/function/,
31+
/debug/
32+
]
33+
}],
34+
"declaration-block-trailing-semicolon": null,
35+
"no-descending-specificity": null
36+
},
37+
};

.history/.eslintrc_20200507105454.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
node: true
6+
},
7+
parserOptions: {
8+
parser: 'babel-eslint'
9+
},
10+
extends: [
11+
'@nuxtjs',
12+
'prettier',
13+
'prettier/vue',
14+
'plugin:prettier/recommended',
15+
'plugin:nuxt/recommended'
16+
],
17+
plugins: [
18+
'prettier'
19+
],
20+
// add your custom rules here
21+
rules: {
22+
}
23+
}

.history/.eslintrc_20200507105514.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
node: true
6+
},
7+
parserOptions: {
8+
parser: 'babel-eslint'
9+
},
10+
extends: [
11+
'prettier',
12+
'prettier/vue',
13+
'plugin:prettier/recommended',
14+
],
15+
plugins: [
16+
'prettier'
17+
],
18+
// add your custom rules here
19+
rules: {
20+
}
21+
}

.history/.eslintrc_20200507105541.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
node: true
6+
},
7+
parserOptions: {
8+
parser: 'babel-eslint'
9+
},
10+
// add your custom rules here
11+
rules: {
12+
}
13+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import axios from 'axios';
2+
import store from './store';
3+
4+
// array to save domain for checking if allready post
5+
const domainsVisited = [];
6+
const browser = require('webextension-polyfill');
7+
8+
const map = store.getters.dataInfo;
9+
10+
11+
// send url to analyzer
12+
async function sendUrl(url, domain, tabId) {
13+
// loading
14+
store.commit('SET_ISLOADING', true);
15+
16+
await axios({
17+
method: 'GET',
18+
url: `https://vue-telemetry.netlify.com/api/analyze?url=${url}&src=extension`,
19+
auth: {
20+
username: 'nuxt-admin',
21+
password: 'vue-telemetry-protected-area',
22+
},
23+
}).then(({ data }) => {
24+
// delete useless jsonKey
25+
delete data.url;
26+
delete data.hostname;
27+
delete data.domain;
28+
delete data.screenshot;
29+
delete data.meta;
30+
31+
setMapData(domain, data);
32+
}).catch((err) => {
33+
browser.browserAction.setIcon({
34+
tabId,
35+
path: {
36+
16: 'icons/icon-vue-telemetry-404error-128.png',
37+
32: 'icons/icon-vue-telemetry-404error-128.png',
38+
},
39+
});
40+
setMapData(domain, 'error');
41+
});
42+
43+
store.commit('SET_ISLOADING', false);
44+
}
45+
46+
// when tab created
47+
function handleCreated(tab) {
48+
setMapData(tab.url, 'noVue');
49+
store.commit('SET_CURRENTDOMAIN', 'noVue');
50+
}
51+
52+
// when tab clicked
53+
async function handleActivated() {
54+
// get active tab
55+
browser.tabs.query({ currentWindow: true, active: true }).then((tabsArray) => {
56+
if (/^chrome/.test(tabsArray[0].url) || /^about/.test(tabsArray[0].url)) {
57+
store.commit('SET_CURRENTDOMAIN', 'noVue');
58+
setMapData(tabsArray[0].url, 'noVue');
59+
} else {
60+
detectVue(tabsArray[0].id, tabsArray[0].url);
61+
}
62+
});
63+
}
64+
65+
// when tab updated
66+
async function handleUpdated(tabId, changeInfo, tabInfo) {
67+
if (changeInfo.status == 'complete') {
68+
detectVue(tabId, tabInfo.url);
69+
}
70+
}
71+
72+
browser.tabs.onCreated.addListener(handleCreated);
73+
browser.tabs.onActivated.addListener(handleActivated);
74+
browser.tabs.onUpdated.addListener(handleUpdated);
75+
76+
77+
// detect vue by calling detector and sendUrl
78+
async function detectVue(tabId, url) {
79+
await hasVue(tabId).then(({ response }) => {
80+
store.commit('SET_CURRENTDOMAIN', response.vueInfo.domain);
81+
82+
if (response.vueInfo.hasVue) {
83+
browser.browserAction.setIcon({
84+
tabId,
85+
path: {
86+
16: 'icons/icon-robot-128.png',
87+
32: 'icons/icon-robot-128.png',
88+
},
89+
});
90+
}
91+
92+
if (!domainsVisited.includes(response.vueInfo.domain)) {
93+
domainsVisited.push(response.vueInfo.domain);
94+
95+
if (response.vueInfo.hasVue) {
96+
sendUrl(url, response.vueInfo.domain, tabId);
97+
} else {
98+
setMapData(response.vueInfo.domain, 'noVue');
99+
store.commit('SET_CURRENTDOMAIN', 'noVue');
100+
}
101+
}
102+
});
103+
}
104+
105+
// check vue in detector.js and get response
106+
function hasVue(tabId) {
107+
return new Promise((resolve) => {
108+
browser.tabs.sendMessage(
109+
tabId,
110+
{ greeting: '' },
111+
).then((response) => {
112+
resolve(response);
113+
});
114+
});
115+
}
116+
117+
function setMapData(domain, data) {
118+
map[domain] = data;
119+
store.commit('SET_DATAINFO', map);
120+
}

0 commit comments

Comments
 (0)