Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 29, 2024. It is now read-only.

Advanced Settings 高级设置

WJ-Yuan edited this page Sep 28, 2024 · 2 revisions

EN / 简体中文

Advanced Settings

When using Summarizer, you may find that the full text of the web page obtained from certain URLs does not meet your expectations. You can choose to use a custom function to override the default web content acquisition method. Inside Summarizer, we use Sval to execute your custom function.

Please:

  1. Make sure there is only one function in the outermost layer
  2. The function needs to have a return value at the end

For example, for the Hacker News website, you can customize the function like this:

function getMarkdown() {
 const list = []
 const nodes = document.querySelectorAll(".athing")
 nodes.forEach((node) => {
 let title = node.querySelector(".titleline"),
 link = node.querySelector("a")
 title &&
 link &&
 list.push({
 title: title.textContent || "",
 link: link.href
 })
 })
 const result = list
 .map((item) => `- [${item.title}](${item.link})`)
 .join("\n")
 return `# Hacker News\n` + result
}

In addition, starting from version 1.1.0, we have exposed a TurndownService on the window object so that you can easily convert HTML to markdown. You can get it through window.__summarizer_turndown in the function. For the specific configuration of TurndownService, please see turndown.

function getMarkdown() {
const TurndownService = window.__summarizer_turndown
const service = new TurndownService()
return service.turndown("<h1>Hello world!</h1>")
}

You can also share your custom rules here. Of course, you can also refer to other people's rules.

高级设置

使用 Summarizer 时,您可能觉得某些网址下获取的网页全文内容不符合您的预期,您可以选择自定义函数的方式来覆盖默认的获取方式。在 Summarizer 内部,我们使用 Sval 来执行您的自定义函数。

请:

  1. 务必保证最外层只有一个函数
  2. 函数最后需要有一个返回值

比如,对于 Hacker News 网站,您可以这样自定义函数:

function getMarkdown() {
 const list = []
 const nodes = document.querySelectorAll(".athing")
 nodes.forEach((node) => {
 let title = node.querySelector(".titleline"),
 link = node.querySelector("a")
 title &&
 link &&
 list.push({
 title: title.textContent || "",
 link: link.href
 })
 })
 const result = list
 .map((item) => `- [${item.title}](${item.link})`)
 .join("\n")
 return `# Hacker News\n` + result
}

另外,1.1.0 版本开始,我们在 window 对象上暴露了一个 TurndownService 以便您轻松将 html 转为 markdown,您可以在函数中通过 window.__summarizer_turndown 获取它,关于 TurndownService 的具体配置请见 turndown

function getMarkdown() {
 const TurndownService = window.__summarizer_turndown
 const service = new TurndownService()
 return service.turndown("<h1>Hello world!</h1>")
}

您还可以在这里分享您的自定义规则。当然,也可以参考别人的规则。

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /