0

i am making a chrome extension. i need a text from an open website in the active tab of browser to use in javascript of the extension. how to fetch it in there?

like in this website link in this site i want the time fetched in the javascript. i am 2 hours ago started new. Please help with an example code if anyone can.

just show an example of how to store that text in a variable. thank you

Weee
  • 15
  • 5
  • 2
    Welcome to Stack Overflow! Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=chrome+extension+scrape+website+site:stackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Jun 02 '22 at 06:02

1 Answers1

0

for the manifest it should probably be fairly basic, you might want to restrict it to a single site and link some js to run so

manifest.json

{
    "manifest_version": 3,
    "name": "some name",
    "version": "0.0.0",
    "description": "description",

    "content_scripts": [ {
        "matches": ["https://www.utctime.net/ist-indian-time-now"],
        "js": ["main.js"]
    } ]

   
}

and the JS is pretty much getting the specific element, here it has an id named time so that can be used.

main.js

getTime = () =>{
    time = document.getElementById("time").innerHTML
    console.log(time)
}
setInterval(getTime, 100);
35308
  • 575
  • 5
  • 17
  • Hey one quick follow up. How to store this time in a variable string? so to use it somewhere else in script? – Weee Jun 02 '22 at 08:34
  • and how to call one script into another? -_- – Weee Jun 02 '22 at 13:11
  • As your litterly extracting the text containing the time your getting a string (there are ":" within to). Also extentions work by having a manifest json file manage details and can link js, here you get the time as a variable, from here you can link new files in the manifest and just call functions or set variables. – 35308 Jun 02 '22 at 20:02