Skip to content

Commit

Permalink
update compatibility table. AG-21379
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit f28eac5
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Fri Apr 14 00:19:18 2023 +0300

    update compatibility table

commit abad886
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Fri Apr 14 00:13:49 2023 +0300

    fix getCurrentUBOScriptlets()

commit c6c2c8b
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Fri Apr 14 00:10:55 2023 +0300

    disable no-continue rule for linter
  • Loading branch information
slavaleleka committed Apr 14, 2023
1 parent c593a6c commit 8c76204
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 51 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
'import/prefer-default-export': 0,
'arrow-body-style': 0,
'import/no-extraneous-dependencies': 0,
'no-continue': 'off',
'no-await-in-loop': 0,
'no-restricted-syntax': 0,
// jsdoc rules
Expand Down
82 changes: 53 additions & 29 deletions scripts/check-sources-updates.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable no-console, camelcase */
const fs = require('fs');
const axios = require('axios');
const { EOL } = require('os');

const {
REMOVED_MARKER,
COMPATIBILITY_TABLE_DATA_PATH,
Expand Down Expand Up @@ -136,7 +138,13 @@ function markTableWithDiff(diff, ruleType, platform) {
* UBO Scriptlets github raw resources
*/
const UBO_SCRIPTLETS_FILE = 'https://raw.githubusercontent.com/gorhill/uBlock/master/assets/resources/scriptlets.js';
const ALIAS_MARKER = 'alias';
const SCRIPTLETS_START_MARKER = 'Injectable scriptlets';
const DIVIDER_MARKER = 'builtinScriptlets.push';
const COMMENT_MARKER = '//';
const FUNCTION_MARKER = 'function ';
const NAME_MARKER_START = "name: '";
const NAME_MARKER_END = "',";
const ALIASES_MARKER = 'aliases: ';

/**
* Make request to UBO repo(master), parses and returns the list of UBO scriptlets
Expand All @@ -146,41 +154,57 @@ async function getCurrentUBOScriptlets() {
const { data } = await axios.get(UBO_SCRIPTLETS_FILE);
console.log('UBO done');

const regexp = /\/\/\/\s(\S*\.js|alias\s\S*\.js)/g;
const parsedNames = [];

let result;
// eslint-disable-next-line no-cond-assign
while (result = regexp.exec(data)) {
// array of parsed UBO scriptlets and their aliases
parsedNames.push(result[1]);
const startIndex = data.indexOf(SCRIPTLETS_START_MARKER);
if (startIndex === -1) {
throw new Error('UBO file format has been changed');
}

let nameRecord;
const names = [];
let aliasName;
let aliases = [];
let i = 0;
while (i < parsedNames.length) {
let k = 1;
// check if scriptlet has aliases (which might be next after it)
while ((i + k < parsedNames.length) && (parsedNames[i + k].includes(ALIAS_MARKER))) {
aliasName = parsedNames[i + k].replace(/alias\s/, '');
aliases.push(aliasName);
k += 1;

const chunks = data.slice(startIndex).split(DIVIDER_MARKER);

chunks.forEach((chunk) => {
let name;
let aliases;

const functionDefinitionIndex = chunk.indexOf(FUNCTION_MARKER) || chunk.length;
const scriptletObjectText = chunk.slice(0, functionDefinitionIndex).trim();

const textLines = scriptletObjectText.split(EOL);
for (let i = 0; i < textLines.length; i += 1) {
const line = textLines[i].trim();
if (line.startsWith(COMMENT_MARKER)) {
continue;
}
// parse the name
if (line.startsWith(NAME_MARKER_START)) {
name = line.slice(NAME_MARKER_START.length, line.indexOf(NAME_MARKER_END));
continue;
}
// parse the aliases
if (line.startsWith(ALIASES_MARKER)) {
const aliasesStr = line
.slice(ALIASES_MARKER.length)
// prepare the string for JSON.parse
.replace(/'/g, '"')
.replace(/,?$/, '');
aliases = JSON.parse(aliasesStr);
// 'name' string goes first and 'aliases' string goes after it
// so if aliases are parsed, no need to continue lines iterating
break;
}
}

if (aliases.length > 0) {
nameRecord = `${parsedNames[i]} (${aliases.join(', ')})`;
aliases = [];
i += k;
} else {
nameRecord = parsedNames[i];
i += 1;
if (!name) {
return;
}

names.push(nameRecord);
}
let namesStr = name;
if (aliases) {
namesStr += ` (${aliases.join(', ')})`;
}
names.push(namesStr);
});

return names;
}
Expand Down
30 changes: 17 additions & 13 deletions scripts/compatibility-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@
},
{
"adg": "log-addEventListener",
"ubo": "addEventListener-logger.js (aell.js)"
"ubo": "addEventListener-logger.js (aell.js) (removed)"
},
{
"adg": "log-eval"
},
{
"adg": "log-on-stack-trace"
},
{
"adg": "m3u-prune",
"ubo": "m3u-prune.js"
},
{
"adg": "noeval"
},
Expand Down Expand Up @@ -162,22 +166,28 @@
"ubo": "alert-buster.js"
},
{
"ubo": "gpt-defuser.js"
"ubo": "gpt-defuser.js (removed)"
},
{
"ubo": "golem.de.js"
},
{
"ubo": "upmanager-defuser.js"
"ubo": "upmanager-defuser.js (removed)"
},
{
"ubo": "smartadserver.com.js (removed)"
},
{
"ubo": "damoh-defuser.js (removed)"
},
{
"ubo": "smartadserver.com.js"
"ubo": "twitch-videoad.js (removed)"
},
{
"ubo": "damoh-defuser.js"
"ubo": "href-sanitizer.js"
},
{
"ubo": "twitch-videoad.js"
"ubo": "call-nothrow.js"
},
{
"abp": "trace"
Expand Down Expand Up @@ -237,16 +247,10 @@
"abp": "abort-on-iframe-property-write"
},
{
"ubo": "abort-current-script.js (acs.js, abort-current-inline-script.js, acis.js)"
},
{
"ubo": "no-floc.js"
"ubo": "no-floc.js (removed)"
},
{
"ubo": "window.name-defuser.js"
},
{
"ubo": "m3u-prune.js"
}
],
"redirects": [
Expand Down
19 changes: 10 additions & 9 deletions wiki/compatibility-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
| [disable-newtab-links](../wiki/about-scriptlets.md#disable-newtab-links) | disable-newtab-links.js | |
| [json-prune](../wiki/about-scriptlets.md#json-prune) | json-prune.js | json-prune |
| [log](../wiki/about-scriptlets.md#log) | | log |
| [log-addEventListener](../wiki/about-scriptlets.md#log-addEventListener) | addEventListener-logger.js (aell.js) | |
| [log-addEventListener](../wiki/about-scriptlets.md#log-addEventListener) | addEventListener-logger.js (aell.js) (removed) | |
| [log-eval](../wiki/about-scriptlets.md#log-eval) | | |
| [log-on-stack-trace](../wiki/about-scriptlets.md#log-on-stack-trace) | | |
| [m3u-prune](../wiki/about-scriptlets.md#m3u-prune) | m3u-prune.js | |
| [noeval](../wiki/about-scriptlets.md#noeval) | | |
| [nowebrtc](../wiki/about-scriptlets.md#nowebrtc) | nowebrtc.js | |
| [no-topics](../wiki/about-scriptlets.md#no-topics) | | |
Expand All @@ -45,12 +46,14 @@
| | webrtc-if.js | |
| | overlay-buster.js | |
| | alert-buster.js | |
| | gpt-defuser.js | |
| | gpt-defuser.js (removed) | |
| | golem.de.js | |
| | upmanager-defuser.js | |
| | smartadserver.com.js | |
| | damoh-defuser.js | |
| | twitch-videoad.js | |
| | upmanager-defuser.js (removed) | |
| | smartadserver.com.js (removed) | |
| | damoh-defuser.js (removed) | |
| | twitch-videoad.js (removed) | |
| | href-sanitizer.js | |
| | call-nothrow.js | |
| | | trace |
| | | hide-if-shadow-contains |
| | | hide-if-contains |
Expand All @@ -70,10 +73,8 @@
| | | commitInjection |
| | | abort-on-iframe-property-read |
| | | abort-on-iframe-property-write |
| | abort-current-script.js (acs.js, abort-current-inline-script.js, acis.js) | |
| | no-floc.js | |
| | no-floc.js (removed) | |
| | window.name-defuser.js | |
| | m3u-prune.js | |


# <a id="redirects"></a> Redirects compatibility table
Expand Down

0 comments on commit 8c76204

Please sign in to comment.