AdguardTeam / AdguardTeam/Scriptlets

Improve 'set-constant' — support generating a constructor

Offen
#365 2 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @maximtop Auf GitHub ansehen
enhancement Priority: P4
Vorherrschende Sprache
JavaScript
Sterne
195
Forks
33
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Generating a constructor in `set-constant` scriptlet means that a filters list maintainer can make a fake class with custom methods and properties.

For example, a filters list maintainer can use it as the following filters:
```adblock
example.com#%#//scriptlet('set-constant', 'human', 'constructor')
example.com#%#//scriptlet('set-constant', 'human.prototype.sleep', 'noopFunc')
example.com#%#//scriptlet('set-constant', 'human.prototype.IsSleeping', 'false')
example.com#%#//scriptlet('set-constant', 'human.prototype.IsSleepingFunc', 'falseFunc')
```
The above filters can be converted to the following Typescript:
```typescript
class human {
constructor() {
this.IsSleeping = false
}

sleep() {
// noopFunc
}

IsSleepingFunc() {
return false
}
}
```

The generating a constructor in set-constant scriptlet can help to resolve a advertisement/tracking-related class in a normal `` element or javascript file without allowing the advertisement/tracking-related another javascript file. (E.g., https://github.com/AdguardTeam/AdguardFilters/issues/161389)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.