Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ostapenko committed Sep 23, 2024
1 parent 4437a40 commit 60dcdba
Show file tree
Hide file tree
Showing 12 changed files with 441 additions and 514 deletions.
26 changes: 0 additions & 26 deletions bin/build.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
const fs = require('fs')
const Zip = require('adm-zip')

const currentVersion = JSON.parse(
fs.readFileSync('./src/manifest.json')
).version

const version = process.argv[2]

if (!version) {
// eslint-disable-next-line no-console
console.error(
`No version number specified. Current version is ${currentVersion}.`
)

process.exit(1)
}

;['./src/manifest.json'].forEach((file) => {
const json = JSON.parse(fs.readFileSync(file))

json.version = version

fs.writeFileSync(file, JSON.stringify(json, null, 2))
})

const zip = new Zip()

zip.addLocalFolder('./src', '')

zip.writeZip('./build/webextension.zip')
Empty file removed build/.gitkeep
Empty file.
4 changes: 1 addition & 3 deletions src/html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
</svg>
</div>

<div class="tabs">
<div class="tab tab--technologies tab--active" data-i18n="tabTechnologies">&nbsp;</div>
</div>


<div class="tab-items">
<div class="tab-item">
Expand Down
55 changes: 28 additions & 27 deletions src/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function getDom(technologies) {
technologies: _technologies.filter(({ dom }) =>
Object.values(dom)
.flat()
.some(({ properties }) => properties),
.some(({ properties }) => properties)
),
})),
..._technologies.reduce((technologies, { name, dom }) => {
Expand Down Expand Up @@ -84,7 +84,7 @@ async function getDom(technologies) {
exists &&
technologies.findIndex(
({ name: _name, selector: _selector, exists }) =>
name === _name && selector === _selector && exists === '',
name === _name && selector === _selector && exists === ''
) === -1
) {
technologies.push({
Expand All @@ -95,16 +95,15 @@ async function getDom(technologies) {
}

if (text) {
const value = (node.innerText ? node.innerText.trim() : '').slice(
0,
1000000,
)
const value = (
node.textContent ? node.textContent.trim() : ''
).slice(0, 1000000)

if (
value &&
technologies.findIndex(
({ name: _name, selector: _selector, text }) =>
name === _name && selector === _selector && text === value,
name === _name && selector === _selector && text === value
) === -1
) {
technologies.push({
Expand All @@ -129,7 +128,7 @@ async function getDom(technologies) {
name === _name &&
selector === _selector &&
property === _property &&
value === toScalar(value),
value === toScalar(value)
) === -1
) {
const value = node[property]
Expand Down Expand Up @@ -160,7 +159,7 @@ async function getDom(technologies) {
name === _name &&
selector === _selector &&
attribute === _atrribute &&
value === toScalar(value),
value === toScalar(value)
) === -1
) {
const value = node.getAttribute(attribute)
Expand Down Expand Up @@ -229,23 +228,25 @@ const Content = {
resolve(
languages
.filter(({ percentage }) => percentage >= 75)
.map(({ language: lang }) => lang)[0],
),
.map(({ language: lang }) => lang)[0]
)
)
: resolve(),
: resolve()
))

const cookies = document.cookie.split('; ').reduce(
(cookies, cookie) => ({
...cookies,
[cookie.split('=').shift()]: [cookie.split('=').pop()],
}),
{},
{}
)

// Text

const text = document.body.innerText.replace(/\s+/g, ' ').slice(0, 25000)
const text = document.body.textContent
.replace(/\s+/g, ' ')
.slice(0, 25000)

// CSS rules
let css = []
Expand Down Expand Up @@ -290,13 +291,13 @@ const Content = {

return metas
},
{},
{}
)

// Detect Google Ads
if (/^(www\.)?google(\.[a-z]{2,3}){1,2}$/.test(location.hostname)) {
const ads = document.querySelectorAll(
'#tads [data-text-ad] a[data-pcu]',
'#tads [data-text-ad] a[data-pcu]'
)

for (const ad of ads) {
Expand Down Expand Up @@ -326,17 +327,17 @@ const Content = {
const urls = [
...new Set([
`https://${decodeURIComponent(
ad.href.split(/^.+\?u=https%3A%2F%2F/).pop(),
ad.href.split(/^.+\?u=https%3A%2F%2F/).pop()
)
.split('/')
.shift()}`,

`https://${ad.innerText.split('\n').pop()}`,
`https://${ad.textContent.split('\n').pop()}`,
]),
]

urls.forEach((url) =>
Content.driver('detectTechnology', [url, 'Facebook Ads']),
Content.driver('detectTechnology', [url, 'Facebook Ads'])
)
}
}
Expand Down Expand Up @@ -400,10 +401,10 @@ const Content = {
args instanceof Error
? [args.toString()]
: args
? Array.isArray(args)
? args
: [args]
: [],
? Array.isArray(args)
? args
: [args]
: [],
},
(response) => {
chrome.runtime.lastError
Expand All @@ -414,11 +415,11 @@ const Content = {
new Error(
`${
chrome.runtime.lastError.message
}: Driver.${func}(${JSON.stringify(args)})`,
),
}: Driver.${func}(${JSON.stringify(args)})`
)
)
: resolve(response)
},
}
)
})
},
Expand All @@ -445,7 +446,7 @@ const Content = {
]),
])
}
}),
})
)
},

Expand Down
Loading

0 comments on commit 60dcdba

Please sign in to comment.