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

  • SEARCH
  • Home
  • 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 9090257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:19:58+00:00 2026-06-16T22:19:58+00:00

My goal is to create a button that when clicked deletes the parent divs

  • 0

My goal is to create a button that when clicked deletes the parent divs on reddit whose links have already been visited. Due to security issues, visited link status cannot be detected from unprivileged javascript, thus, I attempted a chrome extension. However, this doesn’t seem to work either, as even the javascript called from an extension with history permission returns “Uncaught TypeError: Cannot call method ‘search’ of undefined.” Thus, I am still looking for a way to do this.

Update 1/8/2013

I’m very close to getting this working, however, I can’t get n_results in the content script to accurately reflect its status in the background script. Any ideas? Latest code below.

Update 1/8/2013

It’s working! See below if you need to do something like described above.

manifest.json

{
  "name": "Never The Same (NTS) Reddit",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Previously visited links are deleted.",
  "browser_action": {"default_icon": "icon.png"},
  "permissions": ["history","tabs"],
  "content_scripts": [
      {
          "run_at": "document_end",
          "matches": ["http://www.reddit.com/*"],
          "js": ["jquery-1.8.3.min.js", "ntsreddit_content.js"]
      }
  ],
  "background": {"scripts": ["ntsreddit_background.js"]}
}

ntsreddit_background.js

chrome.extension.onMessage.addListener(
    function (request, sender) {
        chrome.history.getVisits({"url": request.url},
        function (visits) {
            if (visits.length > 0) {
                chrome.tabs.sendMessage(sender.tab.id, {
                    "url": request.url
                });
            };
        });
    });

ntsreddit_content.js

$("div.thing a.title").each(
    function(index, value) {
        chrome.extension.sendMessage({"url": value.href});
    });

chrome.extension.onMessage.addListener(function (message) {
    anchor=$('a[href^="' + message.url + '"][class~="title"]')
    if (anchor.length > 0) {
        anchor.closest(".thing").remove();
    };
});
  • 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-06-16T22:19:59+00:00Added an answer on June 16, 2026 at 10:19 pm

    Content scripts have some limitations. They cannot use chrome.* APIs (except for parts of chrome.extension), your code chrome.history in bookmarklet.js will always be undefined

    EDIT:

    After making some changes to your script i got it running.

    Changes

    • Chrome API(s) are asynchronous, you should only do further logical calculations after call back has returned
    • sendResponse() Method is deprecated

    ntsreddit_background.js

    Moved tabs.sendMessage() to handle asynchronous nature of chrome API(s) and eliminated deprecated API(s)

    chrome.extension.onMessage.addListener(
    
    function (request, sender) {
        console.log(sender.tab);
        n_results = -1;
    
        console.log(request.link);
    
        chrome.history.getVisits({
            url: request.link
        },
    
        function (visits) {
            console.log(visits.length);
            n_results = visits.length;
            chrome.tabs.sendMessage(sender.tab.id, {
                "result": n_results
            });
        });
    
    
    
    });
    

    ntsreddit_content.js

    Added a listener to handle response received from background Page

    var firstlink = "https://www.google.co.in/";
    
    chrome.extension.sendMessage({
        "link": firstlink
    });
    chrome.extension.onMessage.addListener(function (message, sender) {
        console.log(message.result);
    });
    

    I hope this solves your problem.

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

Sidebar

Related Questions

I'm trying to create an 'edit' button for a post that when clicked will
I have an activity that has a Button. When the Button is clicked it
My goal is to create an entry form (addnew.php) that will allow me to
My ultimate goal is to create a timer that produces a sound at an
My goal is to create an animation with the YUI Animation Utility that does
Hi here's the goal: to create an automatic bit of content that toggles open
My goal is to create non-white toolbar bar items. I have tried creating with
Is it possible to have a link/button that will execute an AJAX/Jquery function to
I've created an object Chartblock that implements QGraphicsItem. My goal is to create a
I have a form that has hidden elements in it to create a pseudo-array

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.