0

I am working on a Spoiler Blocker Chrome extension where user inputs a string in popup.html, presses submit and then js searches for this string (supposedly) in the current tab and if it finds matches then it redacts them.

The issue I am having is that my popup.js which takes care of recording user input in an array only works in the popup.html and does not redact content from the activeTab.

here is my popup.js code

function checkForSpoilers() {
    $('*:contains("and")').each(function(){
        $element = $(this);
        if($element.children().length < 1) {
            $element.addClass('spoiled');
            if($element.is("strong,span,b,i,em")) {
                $element.parent().addClass('spoiled');
            }
        }
    });
}

I am checking for "and" because I also cannot figure out how to use $('*:contains(...) on an array that holds the input value

Here is the code for saving an input into an array

var spoilersArray = [];

function saveInputToArray() {
    spoilersArray.push($('input').val());
}

I am very new to JS and I would appreciate any help or direction.

Rob W
  • 315,396
  • 71
  • 752
  • 644
kmushegi
  • 1
  • 2
  • See http://stackoverflow.com/questions/4532236/how-can-i-access-the-pages-dom-rather-than-the-popups-dom-using-jquery-if-pos – Rob W Jun 29 '14 at 13:16
  • Thank you! but where would `chrome.extensions.tabs.executeScripts` go? I do have a Content-Script which is popup.js. It has a listener for `DOMContentLoaded` it looks like this `document.addEventListener('DOMContentLoaded',function() { document.querySelector('button').addEventListener('click',doTheMagic); });` so where would `chrome.extensions.tabs.executeScripts` go or do I have to add another listener? I am just beginning to learn JS, sorry for stupid questions. – kmushegi Jun 29 '14 at 13:23
  • `chrome.tabs.executeScript` would be used in your popup script to insert a content script in the page (`popup.js` is *not* a content script if it is embedded in the `popup.html`). Read the [content script](https://developer.chrome.com/extensions/content_scripts) documentation and the answer in the question I linked in my previous comment. – Rob W Jun 29 '14 at 13:29

0 Answers0