dimanche 4 janvier 2015

comparing the url from the tabs to those in an array, and adding more to the array


Hello so I am relatively new to using the chrome and javascript together,and I would like to request some help on how to proceed with the project I want to do. I want to create an extension and one of the main thing is to have a list (possibly an array) of urls. If the url of any of the tabs match the urls on the list then it closes. I was thinking of creating a for loop to cycle through the array of urls that were imputed like this



*://facebook.com/*


so that it matches all the possible urls. Based on this: http://ift.tt/1t6rIqt


I started with this to show more or less the idea.



chrome.tabs.onCreated.addListener(function(tab.url){
if (tab.url===*://facebook.com/*){
chrome.tabs.remove(tab)
}
};


Another user helped me and corrected it to this if I only want to have 1 url, however due to the nature of what I want I am afraid that, that will not work. Perhaps if it was modified to include a for loop to see if they match the list of urls and if they do then close the tab or tabs.



chrome.tabs.onCreated.addListener(function (tab) {
if (tab.url.indexOf('facebook.com') != -1) {
chrome.tabs.remove(tab.id);
}
});


My second doubt is how to add and remove Urls to the array in case the user wants to do so. Since this is an extension I was thinking of making an HTML file appear on the click of a button (perhaps the option page) so that the user imputs the urls that should be on the url list there. However I am not sure on how to get the urls from there to the array or to whatever thing is going to be used.


Thanks in advance and I apologize for mistakes as English is not my first language.





Aucun commentaire:

Enregistrer un commentaire