I'm trying to make an extension that activates when I visit facebook. Up to this part all is good, however then it starts running my code indefinitely.
What I want is to run the content.js script only the first time I visit Facebook and then never run it again.
My current approach is this, but it doesn't work:
background.js
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.storage) {
if (typeof request.value != 'undefined') {
localStorage[request.storage] = request.value;
}
sendResponse({storage: localStorage[request.storage]});
} else {
sendResponse({});
}
});
content.js
var status;
chrome.extension.sendRequest({storage: 'status'}, function(response) {
status = response.storage;
});
if(status != '1')
{
chrome.extension.sendRequest({storage: 'status', value: '1'});
// do my stuff here but only 1 time
}
manifest.json
"content_scripts": [ {
"js": [ "js/jquery.js", "content.js" ],
"matches": [ "https://facebook.com/" ]
} ],
Basically my idea is to run content.js when I visit Facebook, then after the script is done, I add a status variable and then next time I check if the status is 1 which means that the code had already run before.
How can I accomplish this?
Thank you.