我有这个代码试图用作书签。
fetch('https://hf.space/embed/Alifarsi/news_summarizer/+/api/predict/', { method: "POST", body: JSON.stringify({"data":[ "https://www.cp24.com/news/ontario-reports-481-new-covid-19-cases-1-death-1.5667950"]}), headers: { "Content-Type": "application/json" } }).then(function(response) { return response.json(); }).then(function(json_response){ console.log(json_response) })
我从:
/a>
通常书签以“ JavaScript:”关键字开头。我试图在字符串的开头添加,但没有获取预期的页面。
更新:
可能我没有解释我要实现的目标:
-
drag&放下书签:
https://codepen.io/shantanuo/penanuo/pen/pen/pen/pen/lywrabe
- 例如
https://pandas.pydata.orgg/docs/reference/reference/reference/reference/reference/reference/reference/reference/reference/reference/reference/reference/reference/reference/ pandas.read_csv.html
-
当您“活动”选项卡显示上述页面内容时,请单击“书签”。
您将看到此页面的列表。如果有效,我认为我可以使用API获取当前页面的摘要,以节省我阅读整篇文章的时间。但这似乎并不像上述过程那样容易。
I have this code that I am trying to use as a bookmarklet.
fetch('https://hf.space/embed/Alifarsi/news_summarizer/+/api/predict/', { method: "POST", body: JSON.stringify({"data":[ "https://www.cp24.com/news/ontario-reports-481-new-covid-19-cases-1-death-1.5667950"]}), headers: { "Content-Type": "application/json" } }).then(function(response) { return response.json(); }).then(function(json_response){ console.log(json_response) })
I got the code from:
https://hf.space/embed/Alifarsi/news_summarizer/api
Usually the bookmarklets start with "javascript:" keyword. I tried to added that at the start of the string, but it did not fetch the expected page.
Update:
May be I have not explained what I am trying to achieve:
-
Drag & Drop the bookmarklet:
https://codepen.io/shantanuo/pen/LYWRabE
-
Visit a tech page for e.g.
https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html
-
Click on the bookmarklet when you the active tab is showing the contents of the page mentioned above.
You will see the stack-overflow questions where this page is referred. If this works, I thought I can get the summary of current page using the API that will save my time reading the entire article. But this does not seem to be as easy as the process mentioned above.
发布评论
评论(4)
Chrome在新选项卡上使用
fetch()
封锁书签。尝试在另一个网站上作为书签运行,例如 https://w3c.github.io 应该工作。Chrome blocks bookmarklets using
fetch()
on a new Tab. Try running it as a bookmarklet on another site like for example https://w3c.github.io, and it should work.JavaScript:指示符
领先的
JavaScript:
对于浏览器识别书签是必不可少的。此 uri 的一部分被称为方案并确定接下来会发生什么。“没有获取预期的页面”
JavaScript:
通过URL执行,一般会在 chrome:// 页面上被阻止。 COM/CHOMIUM/CHOMIUM/BLOB/6895919A91D3E5418359582D82375CDD9A4C1BA/content/content/renderer/renderer/render_thread_impl.cc#l992“新的选项卡页面是
chrome:// newtab/
,因此书签不起作用。完整列表可以通过输入大约:关于
。如果要使用书签,则必须将位置更改为JavaScript:
允许执行。rentrentrentr
通过使用数据uri方案
data:
以脚本标记生成一个以书签代码为脚本的html文件。它将用此HTML存根替换您的当前页面,这可能很烦人。只需切换到
http(s):
url可能会更容易。或将新的选项卡页面设置为via 。javascript: indicator
The leading
javascript:
is essential for the browser to recognize a bookmarklet. This part of a URI is called scheme and decides what happens next."did not fetch the expected page"
javascript:
execution via URL is blocked in general on allchrome://
pages in render_thread_impl.cc:992:The new tab page is
chrome://newtab/
, so bookmarklets do not work there. The complete list can be seen by enteringabout:about
. If you want to work the bookmarklet, you must change location to wherejavascript:
execution is allowed.A trick bookmarklet to switch location and run JS at the same time
By using the data URI scheme
data:
generate an in place html file with the bookmarklet code as script tag.It will replace your current page with this html stub, which can be annoying. Might be easier to just switch to an
http(s):
URL. Or set the new tab page to such on via extension.从您的编辑中了解,您希望从
hf.space/embed/alifarsi/news_summarizer
获得当前页面的摘要。因此,代替cp24.com
您必须将当前页面的URL传递给location.href
:不过,它对复杂的API文档并没有太大帮助。通常,这些以主要想法在细节之前的方式写。为您的示例 pandas.pandas.read_cs.csv
要学习基础知识,请更好地 search> search 比AI摘要文档。
As I understand from your edit, you want to get a summary of the current page from
hf.space/embed/Alifarsi/news_summarizer
. Therefore in place ofcp24.com
you must pass the current page's URL to it, stored inlocation.href
:It won't help you much with complex API documentation though. Normally these are written in a way that the main idea comes before the details. For your example pandas.read_csv it would be
To learn the basics, better search for a tutorial than an AI summary of the docs.
您需要将代码放在IIFE中 -
因此您的代码应该是 -
我已经在浏览器中对其进行了测试。它可以很好地记录控制台中的响应数据。您只需将代码像下面的图像一样。它应该很好。
You need to put you code inside an IIFE like this -
So your code should be -
I have tested it in my browser. It logs the response data in the console just fine. You can just take the code do it like the image below. It should work just fine.