Skip to content

Commit

Permalink
feat: add new ruleset grammar (#490)
Browse files Browse the repository at this point in the history
* implement new grammar

* trivial change of grammar

* rewrite match pattern

* update grammar

* minor refactoring of match pattern

* rename MatchPatternBatch to MatchPatternSet

* rename MatchPatternBatch to MatchPatternSet

* implement ruleset

* minor refactoring

* allow dollar sign in identifier

* add props

* update third party notices

* set scheme/host/path in InteractiveRuleset

* $ can be used only at beginning of identifier

* fix precedence of !

* refactor grammar

* remove octal escape sequences

* rename $engine to $site

* read names from metadata of subscriptions

* add kagi support

* change regexp match operator: "=~" -> "~="

* change grammar of identifier

* fix: add URL parts when creating patch

* update grammar

- change regexp operator from "~=" to "=~"
- add case insensitive operator "i"

* add documents for expressions

* add documents for YAML frontmatter

* <all_urls> is supported

* <all_urls> is supported

* expression including undefine properties return false

* minor refactoring

* remove description about name in subscription URL

* move link to subscriptions page

* fix typo

* minor refactoring

* remove compiledRules from subscriptions

* ddg: add props to news card in web search
  • Loading branch information
iorate authored Jun 15, 2024
1 parent cc3dab3 commit 0ca80c9
Show file tree
Hide file tree
Showing 61 changed files with 3,200 additions and 1,582 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,23 @@ This extension is available in the below search engines.
To publish a ruleset as a subscription, place a ruleset file encoded in UTF-8 on a suitable HTTP(S) server, and publish the URL. Here is an example hosted on GitHub:<br>
https://raw.githubusercontent.com/iorate/ublacklist-example-subscription/master/uBlacklist.txt

In uBlacklist >=6.6.0 for _Chrome_, subscription links are available. To add a subscription with `name` and `url`, the following URL can be used as a shortcut to the options page:
You can prepend YAML frontmatter to your ruleset. It is recommended that you set the `name` variable.

```
https://iorate.github.io/ublacklist/subscribe?name={urlEncode(name)}&url={urlEncode(url)}
---
name: Your ruleset name
---
*://*.example.com/*
```

In uBlacklist >=6.6.0 for _Chrome_, subscription links are available. To add a subscription with `url`, the following URL can be used as a shortcut to the options page:

```
https://iorate.github.io/ublacklist/subscribe?url={urlEncode(url)}
```

For the above example:<br>
https://iorate.github.io/ublacklist/subscribe?name=Example&url=https%3A%2F%2Fraw.githubusercontent.com%2Fiorate%2Fublacklist-example-subscription%2Fmaster%2FuBlacklist.txt
https://iorate.github.io/ublacklist/subscribe?url=https%3A%2F%2Fraw.githubusercontent.com%2Fiorate%2Fublacklist-example-subscription%2Fmaster%2FuBlacklist.txt

## For developers

Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"files": {
"ignore": ["**/package.json"]
"ignore": ["**/package.json", "**/parser.js"]
},
"vcs": {
"enabled": true,
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
"version": "0.0.0",
"dependencies": {
"@codemirror/commands": "^6.5.0",
"@codemirror/lang-yaml": "^6.1.1",
"@codemirror/language": "^6.10.1",
"@codemirror/lint": "^6.7.0",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.26.3",
"@lezer/common": "^1.2.1",
"@lezer/highlight": "^1.2.0",
"@lezer/lr": "^1.4.0",
"@mdi/svg": "^7.4.47",
"colord": "^2.9.3",
"dayjs": "^1.11.11",
"goober": "2.1.10",
"is-mobile": "^4.0.0",
"js-yaml": "^4.1.0",
"punycode": "^2.3.1",
"react": "^18.3.1",
"react-colorful": "^5.6.1",
Expand All @@ -21,7 +26,9 @@
},
"devDependencies": {
"@biomejs/biome": "^1.7.3",
"@lezer/generator": "^1.7.0",
"@types/fs-extra": "^11.0.4",
"@types/js-yaml": "^4.0.9",
"@types/license-checker": "^25.0.6",
"@types/node": "^20.12.8",
"@types/punycode": "^2.1.4",
Expand Down Expand Up @@ -56,8 +63,8 @@
"fix": "pnpm run /^fix:/",
"fix:biome": "biome check --apply .",
"fix:prettier": "prettier --write .",
"generate-ruleset-parser": "lezer-generator src/scripts/ruleset/ruleset.grammar -o src/scripts/ruleset/parser.js --noTerms",
"generate-third-party-notices": "tsx scripts/generate-third-party-notices.ts",
"postinstall": "pnpm generate-third-party-notices",
"test": "tsx scripts/test.ts"
},
"type": "module",
Expand Down
87 changes: 87 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async function createBuildScripts(
bundle: true,
define: defineProcessEnv(context),
entryPoints: sources.map((file) => path.join(srcDir, file)),
format: "esm",
format: "iife",
jsx: "automatic",
jsxDev: debug,
// https://github.com/evanw/esbuild/issues/3418
Expand Down
8 changes: 8 additions & 0 deletions src/_locales/en/messages.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,20 @@ export default exportAsMessages({
// The title of the add-subscription dialog.
options_addSubscriptionDialog_title: "Add a subscription",

// UNUSED
// The label for the name input on the add-subscription dialog.
options_addSubscriptionDialog_nameLabel: "Name",

// The label for the URL input on the add-subscription dialog.
options_addSubscriptionDialog_urlLabel: "URL",

// The label for the alternative name input on the add-subscription dialog.
options_addSubscriptionDialog_altNameLabel: "Alternative name (optional)",

// The helper text for the alternative name input on the add-subscription dialog.
options_addSubscriptionDialog_altNameDescription:
"The alternative name used when a downloaded ruleset does not contain a name.",

// The text of the add button on the add-subscription dialog.
options_addSubscriptionDialog_addButton: "Add",

Expand Down
3 changes: 3 additions & 0 deletions src/_locales/ja/messages.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export default exportAsMessages({
options_addSubscriptionDialog_title: "購読を追加する",
options_addSubscriptionDialog_nameLabel: "名前",
options_addSubscriptionDialog_urlLabel: "URL",
options_addSubscriptionDialog_altNameLabel: "代替の名前 (オプション)",
options_addSubscriptionDialog_altNameDescription:
"ダウンロードしたルールセットに名前が含まれないときに、代わりに使用される名前です。",
options_addSubscriptionDialog_addButton: "追加",
options_showSubscriptionDialog_blacklistLabel: "ルールのリスト",
options_updateInterval: "更新の間隔",
Expand Down
2 changes: 2 additions & 0 deletions src/common/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export type MessageName =
| "options_addSubscriptionDialog_title"
| "options_addSubscriptionDialog_nameLabel"
| "options_addSubscriptionDialog_urlLabel"
| "options_addSubscriptionDialog_altNameLabel"
| "options_addSubscriptionDialog_altNameDescription"
| "options_addSubscriptionDialog_addButton"
| "options_showSubscriptionDialog_blacklistLabel"
| "options_updateInterval"
Expand Down
Loading

0 comments on commit 0ca80c9

Please sign in to comment.