I am new to Chrome extensions so I am having trouble knowing why I am not getting my expect results.
I have a script that allows you to add keywords. I want my program to keep track of the keywords and hide the parent div of the keywords. Essentially it would filter out stuff you do not want to see. Like, Justin Bieber or Kim Kardashian.
I can add the keywords with no problem but I cannot get the content to be hidden.
I think the problem is I may not be targeting the dom correctly of the page I am viewing.
Maybe missing a permission?
Could someone please tell me how to do this with an extension?
keywords.js
$(document).ready(function () {
$('#add').click( function() {
var Description = $('#description').val();
if($("#description").val() === '') {
$('#alert').html("<strong>Warning!</strong> You left the to-do empty");
$('#alert').fadeIn().delay(1000).fadeOut();
return false;
}
$('#keyWords').prepend("<li><input id='check' name='check' type='checkbox'/>" + Description + "</li>");
$('#form')[0].reset();
var keyWords = $('#keyWords').html();
localStorage.setItem('keyWords', keyWords);
return false;
});
if(localStorage.getItem('keyWords')) {
$('#keyWords').html(localStorage.getItem('keyWords'));
}
$('#clear').click( function() {
window.localStorage.clear();
location.reload();
return false;
});
}); // End of document ready function
$(document).ready(function() {
$("div p:contains(localStorage.getItem('keyWords')).parent('div').hide()");
}); //end of document ready function
This is my Manifest.json
{
"name": "Wuno Zensoring",
"version" : "1.0",
"permissions": [
"activeTab",
"storage"
],
"description": "This extension will search the document file for keywords and hide their parent div.",
"icons": {
"19": "icon19.png",
"38": "icon38.png",
"48": "icon48.png",
"128": "icon128.png"
},
"browser_action": {
"default_icon": "icon.png128",
"default_popup": "keyform.html",
"background_page": "keyform.html",
"default_icon": {
"19": "icon19.png",
"38": "icon38.png",
"48": "icon48.png",
"128": "icon128.png"
}
},
"manifest_version": 2
}
My html file keyform.html
<!doctype html>
<html>
<head>
<title>Wuno Webpage Analyzer</title>
<script src="jquery-1.11.3.min.js"></script>
<script src="keywords.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<img src="icon48.png">
<section>
<form id="form" action="#" method="POST">
<input id="description" name="description" type="text" />
<input id="add" type="submit" value="Add" />
<button id="clear">Clear All</button>
</form>
<div id="alert"></div>
<ul id="keyWords"></ul>
</body>
</html>