SERPINFO
SERPINFO is the mechanism that allows uBlacklist to work on search engines such as Google, Bing, and DuckDuckGo. Each SERPINFO is a YAML file that describes how to locate search results on a specific search engine's results page, so that uBlacklist can block, highlight, or attach buttons to them.
uBlacklist ships with built-in SERPINFO definitions for the supported search engines. You can also subscribe to SERPINFO published by others, or write your own to support a search engine that is not yet covered.
The SERPINFO options page is opened from Other search engines on the extension's options page. There you can enable or disable individual SERPINFO, subscribe to ones published by others, and write your own under My SERPINFO.
ファイル形式
SERPINFO ファイルは以下の構造を持つ YAML 形式を使用します:
name: SearchEngineName
version: 1.0.0
homepage: https://example.com/
lastModified: 2023-09-01T00:00:00Z
pages:
- name: PageType
matches:
- https://search.example.com/search?*
results:
- root: .result-selector
url: a.link
props:
title: .title
commonProps:
$site: example
$category: web
トップレベルプロパティ
| 必須 | プロパティ | 型 | 説明 |
|---|---|---|---|
| ✓ | name | string | SERPINFO の名前 |
| ✓ | pages | array | ページ定義の配列 |
version | string | SERPINFO のバージョン | |
description | string | SERPINFO の説明 | |
homepage | string | SERPINFO のホームページURL | |
lastModified | string | ISO 形式での最終更新日時 |
ページ定義
pages 配列内の各項目は、特定の種類の検索結果ページ (Web、画像、ニュースなど) を表します:
| 必須 | プロパティ | 型 | 説明 |
|---|---|---|---|
| ✓ | name | string | ページ定義の名前 |
| ✓ | matches | array | ページを含めるためのマッチパターンの配列 |
| ✓ | results | array | 検索結果定義の配列 |
excludeMatches | array | ページを除外するためのマッチパターンの配列 | |
includeRegex | string | ページを含めるための正規表現パターン | |
excludeRegex | string | ページを除外するための正規表現パターン | |
userAgent | string | "any"、"desktop"、または "mobile" を指定可能 | |
commonProps | object | このページのすべての結果に適用される共通プロパティ | |
delay | number or boolean | ページ読み込み後の遅延時間 (ミリ秒) または遅延の有効/無効を指定 |
検索結果定義
results 配列内の各項目は、単一の検索結果からデータを抽出する方法を定義します:
| 必須 | プロパティ | 型 | 説明 |
|---|---|---|---|
| ✓ | root | string or array | 検索結果要素を見つけるためのルートコマンド |
| ✓ | url | string or array | 検索結果から URL を抽出するためのプロパティコマンド |
name | string | 検索結果定義の名前 | |
props | object | 抽出するプロパティ名とプロパティコマンドのキーと値のペア | |
button | array | 検索結果にブロックボタンを追加するためのボタンコマンド | |
preserveSpace | boolean | ブロックされた検索結果のレイアウトスペースを保持し、レイアウトのシフトを防ぐ |
コマンド
SERPINFO は複雑なシナリオに対応するため、以下の 3 つのカテゴリに分類されたコマンドをサポートします:
ルートコマンド
<css-selector>または[selector, <css-selector>]: CSS セレクターに一致する要素を検索[upward, <level>, <root-command>]: ルートコマンドで見つかった各要素から DOM ツリーを<level>ステップ上に移動
要素コマンド
<css-selector>または[selector, <css-selector>, <element-command>?]: CSS セレクターで要素を取得[upward, <level>, <element-command>?]: DOM ツリーを<level>ステップ上に移動
注意: <element-command> が省略された場合、現在のルート要素が暗黙的に使用されます。
プロパティコマンド
<css-selector>: CSS セレクターに一致する要素のtextContentプロパティ (デフォルト) またはhref属性 (URL 抽出時) を取得[attribute, <name>, <element-command>?]: 属性値を取得[property, <name>, <element-command>?]: プロパティ値を取得[const, <value>]: 定数文字列を返す[domainToURL, <property-command>]: ドメインを URL に変換[regexInclude, <pattern>, <property-command>]: 正規表現に一致する場合のみ含める[regexExclude, <pattern>, <property-command>]: 正規表現に一致する場合は除外[regexSubstitute, <pattern>, <replacement>, <property-command>]: 正規表現で置換[or, [<property-command>*], <element-command>?]: 複数のコマンドを順番に試す
注意: <element-command> が省略された場合、現在のルート要素が暗黙的に使用されます。
ボタンコマンド
-
[icon, <options>?, <element-command>?]: スタイルを指定してアイコンボタンを追加します。オプションには以下が含まれます:style: インラインスタイル (例:"top: 16px; right: 32px; --ub-icon-size: 16px;")
-
[text, <options>?, <element-command>?]: 位置とスタイルを指定してテキストボタンを追加します。オプションには以下が含まれます:position:"beforebegin","afterbegin","beforeend","afterend"(デフォルト:beforeend")style: インラインスタイル (例:"color: var(--fg-color); font-size: 14px;")
-
[inset, <options>?, <element-command>?]: 要素内の特定の位置にボタンを追加。オプションには以下が含まれます:top: CSS の長さまたは割合right: CSS の長さまたは割合bottom: CSS の長さまたは割合left: CSS の長さまたは割合zIndex: z-index 値 (デフォルト: 1)
注意: <element-command> が省略された場合、現在のルート要素が使用されます。
例
以下は Bing 画像検索の例です:
name: Bing
version: 0.1.0
homepage: https://github.com/ublacklist/builtin#readme
license: MIT
lastModified: 2023-04-05T11:11:20Z
pages:
- name: Images (desktop)
matches:
- https://www.bing.com/images/search?*
userAgent: desktop
results:
- root: [upward, 1, ".iuscp"]
url:
- regexSubstitute
- '"purl":"([^"]+)'
- "\\1"
- [attribute, "m", ".iusc"]
props:
title: [attribute, "title", "li > a"]
button: [inset, { top: "32px", right: 0 }, ".iuscp"]
commonProps:
$site: bing
$category: images
購読
SERPINFO の公開
SERPINFO ファイルをホストし、購読リンクを提供することで、SERPINFO を他のユーザーと共有できます。
- 上記の形式に従って SERPINFO ファイルを作成
- ファイルを GitHub や自身のウェブサイトなどで公開
- 以下の形式で購読リンクを共有:
https://ublacklist.github.io/serpinfo/subscribe?url=<url-encoded-url>
<url-encoded-url> は、公開された SERPINFO ファイルの URL を URLエンコード したものです。
SERPINFO の購読
SERPINFO を購読するには:
- 提供された購読リンクをクリック
- 拡張機能がオプションページを開き、購読の追加を促します
- 確認して拡張機能にSERPINFOを追加
購読リンクを使用するには、手動で有効化する必要があります。拡張機能のオプションページに移動し、「SERPINFO 購読リンクを有効にする」をオンにしてください。