Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 911893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:17:17+00:00 2026-05-15T17:17:17+00:00

I want to write an extension for Google chrome that detects snippets of source

  • 0

I want to write an extension for Google chrome that detects snippets of source code on web pages and automatically copies them to the clipboard.

I’m new to javascript and jquery, so for the first step, I wanted to try a very simple case.

Using this site as an example:
http://www.swharden.com/blog/2010-03-05-realtime-fft-graph-of-audio-wav-file-or-microphone-input-with-python-scipy-and-wckgraph/

I want to find the element that contains the string “import ” and add the text “Here is some code” after the element. Could someone give me a clue?

My first attempt was $('*:contains("import ")').after("Here's some code");, but that inserted after every element, including the parents, when I only want to insert after the lowest level child.

Edit: I want the code to work on any site. So I want to find any element that contains the “import “. Solutions specific to the example site aren’t what I’m looking for.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:17:18+00:00Added an answer on May 15, 2026 at 5:17 pm

    Go through each text node on the page and search for the query – "import". If it matches, then append the string "Here's some code" after it’s parent().

    $("body *").contents().filter(function() {
        if(this.nodeType != Node.TEXT_NODE) {
            return;
        }
        if(this.nodeValue.indexOf('import') == -1) {
            return;
        }
        $(this).parent().after("Here's some code");
    });
    

    Using your given example, this will add "Here's some code" after each line of code. To find out where exactly the code begins, you will have to apply some heuristics.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a Google Chrome Extension that can take information from a
I am trying to write an extension to google chrome and I want to
Considering that I want to write python code that would run on Google App
I try to write a dictionary extension for Google Chrome. Now, I want to
I want to write a Chrome extension that looks at the HTML of the
I wrote a Google Chrome extension and the site that I want to use
I'm actually trying to write a Google Chrome extension (with little-to-no experience). What I'm
So I wrote a Google Chrome extension. All I want to do is provide
I want to write an extension method for the List class that takes an
I am trying to write a Google Chrome extension to basically favorite pictures. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.