Skip to content

Commit de99ca0

Browse files
committed
feat: remove typescript
1 parent 5de3ca2 commit de99ca0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1093
-1618
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_size = 2
6+
indent_style = space
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.eslintrc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ module.exports = {
1313
},
1414
parserOptions: {
1515
ecmaVersion: 2018,
16-
parser: '@typescript-eslint/parser',
1716
sourceType: 'module'
1817
},
1918
plugins: [
20-
'vue',
21-
'@typescript-eslint'
19+
'vue'
2220
],
2321
rules: {
2422
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
/*.log
33
/dist
44
/dist-zip
5+
coverage
56
.env
7+
.DS_Store
8+
.nuxt
9+
.vscode

package.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99
},
1010
"scripts": {
1111
"lint": "eslint --ext .js,.vue src",
12-
"prettier": "prettier \"src/**/*.{js,vue}\"",
13-
"prettier:write": "npm run prettier -- --write",
1412
"build:dev": "cross-env NODE_ENV=development webpack --hide-modules",
1513
"build-zip": "node scripts/build-zip.js",
1614
"watch:tailwind": "NODE_ENV=development postcss src/tailwind.css -o dist/tailwind.css -w",
1715
"dev:tailwind": "NODE_ENV=development postcss src/tailwind.css -o dist/tailwind.css",
1816
"build:tailwind": "NODE_ENV=production postcss src/tailwind.css -o dist/tailwind.css",
1917
"watch": "npm run build -- --watch",
2018
"watch:dev": "cross-env HMR=true npm run build:dev -- --watch",
21-
"dev": "concurrently \"npm run watch:tailwind\" \"NODE_ENV=development webpack --config webpack.config.js --mode=development --watch\"",
19+
"dev": "concurrently \"npm run watch:tailwind\" \"npm run watch:dev\"",
2220
"build": "npm run build:tailwind && webpack --mode production"
2321
},
2422
"dependencies": {
2523
"@babel/polyfill": "^7.8.7",
26-
"@types/node": "^14.0.1",
2724
"axios": "^0.19.0",
2825
"concurrently": "^5.2.0",
2926
"dotenv": "^8.2.0",
@@ -33,7 +30,6 @@
3330
"tailwindcss": "^1.3.5",
3431
"vue": "^2.6.10",
3532
"vue-telemetry-analyzer": "^0.1.6",
36-
"vuejs-logger": "1.5.4",
3733
"vuex": "^3.1.3",
3834
"vuex-webextensions": "^1.3.0",
3935
"webextension-polyfill": "^0.3.1"
@@ -43,8 +39,6 @@
4339
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
4440
"@babel/preset-env": "^7.1.0",
4541
"@babel/runtime-corejs3": "^7.4.0",
46-
"@typescript-eslint/eslint-plugin": "^2.31.0",
47-
"@typescript-eslint/parser": "^2.31.0",
4842
"archiver": "^3.0.0",
4943
"babel-eslint": "^10.0.3",
5044
"babel-loader": "^8.0.2",
@@ -70,8 +64,6 @@
7064
"node-sass": "^4.13.1",
7165
"puppeteer": "^2.1.1",
7266
"sass-loader": "^7.1.0",
73-
"ts-loader": "^7.0.3",
74-
"typescript": "^3.8.3",
7567
"vue-loader": "^15.4.2",
7668
"vue-svg-loader": "^0.16.0",
7769
"vue-template-compiler": "^2.6.10",

postcss.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const tailwindcss = require('tailwindcss');
1+
const tailwindcss = require('tailwindcss')
2+
23
module.exports = {
34
plugins: [
45
tailwindcss('./tailwind.config.js'),
5-
require('autoprefixer'),
6-
],
7-
};
6+
require('autoprefixer')
7+
]
8+
}

scripts/build-zip.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs');
4-
const path = require('path');
5-
const archiver = require('archiver');
3+
const fs = require('fs')
4+
const path = require('path')
5+
const archiver = require('archiver')
66

7-
const DEST_DIR = path.join(__dirname, '../dist');
8-
const DEST_ZIP_DIR = path.join(__dirname, '../dist-zip');
7+
const DEST_DIR = path.join(__dirname, '../dist')
8+
const DEST_ZIP_DIR = path.join(__dirname, '../dist-zip')
99

1010
const extractExtensionData = () => {
11-
const extPackageJson = require('../package.json');
11+
const extPackageJson = require('../package.json')
1212

1313
return {
1414
name: extPackageJson.name,
1515
version: extPackageJson.version
1616
}
17-
};
17+
}
1818

1919
const makeDestZipDirIfNotExists = () => {
20-
if(!fs.existsSync(DEST_ZIP_DIR)) {
21-
fs.mkdirSync(DEST_ZIP_DIR);
20+
if (!fs.existsSync(DEST_ZIP_DIR)) {
21+
fs.mkdirSync(DEST_ZIP_DIR)
2222
}
2323
}
2424

2525
const buildZip = (src, dist, zipFilename) => {
26-
console.info(`Building ${zipFilename}...`);
26+
console.info(`Building ${zipFilename}...`)
27+
28+
const archive = archiver('zip', { zlib: { level: 9 } })
29+
const stream = fs.createWriteStream(path.join(dist, zipFilename))
2730

28-
const archive = archiver('zip', { zlib: { level: 9 }});
29-
const stream = fs.createWriteStream(path.join(dist, zipFilename));
30-
3131
return new Promise((resolve, reject) => {
3232
archive
3333
.directory(src, false)
3434
.on('error', err => reject(err))
35-
.pipe(stream);
35+
.pipe(stream)
3636

37-
stream.on('close', () => resolve());
38-
archive.finalize();
39-
});
40-
};
37+
stream.on('close', () => resolve())
38+
archive.finalize()
39+
})
40+
}
4141

4242
const main = () => {
43-
const {name, version} = extractExtensionData();
44-
const zipFilename = `${name}-v${version}.zip`;
45-
46-
makeDestZipDirIfNotExists();
43+
const { name, version } = extractExtensionData()
44+
const zipFilename = `${name}-v${version}.zip`
45+
46+
makeDestZipDirIfNotExists()
4747

4848
buildZip(DEST_DIR, DEST_ZIP_DIR, zipFilename)
4949
.then(() => console.info('OK'))
50-
.catch(console.err);
51-
};
50+
.catch(console.err)
51+
}
5252

53-
main();
53+
main()

src/background.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/background.html

Whitespace-only changes.

src/background.ts renamed to src/background.js

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,71 @@ import axios from 'axios'
22
import store from './store'
33

44
// array to save domain for checking if allready post
5-
const domainsVisited: Array<String> = []
5+
const domainsVisited = []
66
const browser = require('webextension-polyfill')
77

88
const map = store.getters.dataInfo
99
// send url to analyzer
10-
async function sendUrl(url: string, domain: string, tabId: number) {
10+
async function sendUrl (url, domain, tabId) {
1111
// loading
1212
store.commit('SET_ISLOADING', true)
1313

1414
await axios({
1515
method: 'GET',
16-
url: `https://vue-telemetry.nuxtjs.app/api/analyze?url=${url}&src=extension`,
16+
url: `https://vuetelemetry.com/api/analyze?url=${url}&src=extension`,
1717
auth: {
1818
username: 'nuxt-admin',
1919
password: 'vue-telemetry-protected-area'
2020
}
2121
}).then(({ data }) => {
22-
// delete useless jsonKey
23-
delete data.url
24-
delete data.hostname
25-
delete data.domain
26-
delete data.screenshot
27-
delete data.meta
28-
29-
setMapData(domain, data)
30-
}).catch(() => {
22+
setMapData(domain, data.body)
23+
}).catch((e) => {
3124
browser.browserAction.setIcon({
3225
tabId,
3326
path: {
3427
16: 'icons/icon-grey-128.png',
3528
32: 'icons/icon-grey-128.png'
3629
}
3730
})
38-
setMapData(domain, 'error')
31+
setMapData(domain, e.response.data.statusCode === 400 ? 'noVue' : 'error')
3932
})
4033

4134
store.commit('SET_ISLOADING', false)
4235
}
4336

44-
// when tab created
45-
function handleCreated(tab: { url: string }) {
46-
setMapData(tab.url, 'noVue')
47-
store.commit('SET_CURRENTDOMAIN', 'noVue')
48-
}
49-
5037
// when tab clicked
51-
async function handleActivated() {
38+
async function handleActivated () {
5239
// get active tab
53-
browser.tabs.query({ currentWindow: true, active: true }).then((tabsArray: { id: number, url: string; }[]) => {
54-
if (/^chrome/.test(tabsArray[0].url) || /^about/.test(tabsArray[0].url)) {
55-
store.commit('SET_CURRENTDOMAIN', 'noVue')
56-
setMapData(tabsArray[0].url, 'noVue')
57-
} else {
58-
detectVue(tabsArray[0].id, tabsArray[0].url)
40+
browser.tabs.query({ currentWindow: true, active: true }).then((tabsArray) => {
41+
const { id, url, status } = tabsArray[0]
42+
43+
if (status === 'complete') {
44+
detectVue(id, url)
5945
}
6046
})
6147
}
6248

6349
// when tab updated
64-
async function handleUpdated(tabId: number, changeInfo: { status: string }, tabInfo: { url: string }) {
50+
async function handleUpdated (tabId, changeInfo, tabInfo) {
6551
if (changeInfo.status === 'complete') {
6652
detectVue(tabId, tabInfo.url)
6753
}
6854
}
6955

70-
browser.tabs.onCreated.addListener(handleCreated)
7156
browser.tabs.onActivated.addListener(handleActivated)
7257
browser.tabs.onUpdated.addListener(handleUpdated)
7358

7459
// detect vue by calling detector and sendUrl
75-
async function detectVue(tabId: number, url: string) {
60+
async function detectVue (tabId, url) {
61+
store.commit('SET_CURRENTDOMAIN', url)
62+
63+
if (!url) {
64+
return
65+
}
66+
if (/^chrome/.test(url) || /^about/.test(url)) {
67+
return setMapData(url, 'noVue')
68+
}
69+
7670
await hasVue(tabId).then(({ response }) => {
7771
store.commit('SET_CURRENTDOMAIN', response.vueInfo.domain)
7872

@@ -93,25 +87,24 @@ async function detectVue(tabId: number, url: string) {
9387
sendUrl(url, response.vueInfo.domain, tabId)
9488
} else {
9589
setMapData(response.vueInfo.domain, 'noVue')
96-
store.commit('SET_CURRENTDOMAIN', 'noVue')
9790
}
9891
}
9992
})
10093
}
10194

102-
// check vue in detector.js and get response
103-
function hasVue(tabId: number) {
95+
// check vue in content.js and get response
96+
function hasVue (tabId) {
10497
return new Promise((resolve) => {
10598
browser.tabs.sendMessage(
10699
tabId,
107100
{ greeting: '' }
108-
).then((response: any) => {
101+
).then((response) => {
109102
resolve(response)
110103
})
111104
})
112105
}
113106

114-
function setMapData(domain: string, data: any) {
107+
function setMapData (domain, data) {
115108
map[domain] = data
116109
store.commit('SET_DATAINFO', map)
117110
}

src/detector.ts renamed to src/content.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const browser = require('webextension-polyfill')
2-
const isBrowser: boolean = typeof navigator !== 'undefined'
3-
const isFirefox: boolean = isBrowser && navigator.userAgent.indexOf('Firefox') > -1
2+
const isBrowser = typeof navigator !== 'undefined'
3+
const isFirefox = isBrowser && navigator.userAgent.indexOf('Firefox') > -1
44

55
let vueInfo = null
6-
let resolveDetecting: { (): void; (value?: unknown): void; }
6+
let resolveDetecting
77

88
const detecting = new Promise((resolve) => {
99
resolveDetecting = resolve
@@ -16,7 +16,7 @@ window.addEventListener('message', ({ data }) => {
1616
}
1717
})
1818

19-
function handleMessage() {
19+
function handleMessage () {
2020
return new Promise((resolve) => {
2121
detecting.then(function () {
2222
resolve({ response: { vueInfo } })
@@ -30,15 +30,15 @@ if (document instanceof HTMLDocument) {
3030

3131
browser.runtime.onMessage.addListener(handleMessage)
3232

33-
function detectVue(win: { postMessage: (arg0: { __vue_telemetry__: boolean; domain: string; hasVue: boolean; }) => void; }) {
33+
function detectVue (win) {
3434
setTimeout(() => {
35-
let hasVue: boolean = Boolean(window.Vue || (window as any).$nuxt) // || [...document.querySelectorAll('*')].map((el) => Boolean(el.__vue__)).filter(Boolean).length)
35+
let hasVue = Boolean(window.Vue || window.$nuxt)
3636

3737
if (hasVue === false) {
3838
const all = document.querySelectorAll('*')
39-
let el: Element
39+
let el
4040
for (let i = 0; i < all.length; i++) {
41-
if ((all[i] as any).__vue__) {
41+
if (all[i].__vue__) {
4242
el = all[i]
4343
break
4444
}
@@ -56,14 +56,14 @@ function detectVue(win: { postMessage: (arg0: { __vue_telemetry__: boolean; doma
5656
}, 100)
5757
}
5858

59-
function installScript(fn: { (win: { postMessage: (arg0: { __vue_telemetry__: boolean; domain: string; hasVue: boolean; }) => void; }): void; toString?: any; }) {
59+
function installScript (fn) {
6060
const source = `;(${fn.toString()})(window)`
6161

6262
if (isFirefox) {
6363
// eslint-disable-next-line no-eval
6464
window.eval(source) // in Firefox, this evaluates on the content window
6565
} else {
66-
const script: HTMLScriptElement = document.createElement('script')
66+
const script = document.createElement('script')
6767
script.setAttribute('defer', 'defer')
6868
script.textContent = source
6969
document.documentElement.appendChild(script)

0 commit comments

Comments
 (0)