Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert javascript code to bookmarklet for easy access

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:

  1. Drag & Drop the bookmarklet: https://codepen.io/shantanuo/pen/LYWRabE

  2. Visit a tech page for e.g. https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html

  3. 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.

like image 329
shantanuo Avatar asked Apr 10 '26 11:04

shantanuo


1 Answers

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.

like image 169
lxhom Avatar answered Apr 13 '26 00:04

lxhom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!