Récupération url onglet

44 lượt xem
Chuyển tới thư đầu tiên chưa đọc

Jonathan Bihan

chưa đọc,
20:04:18 27 thg 6, 201527/6/15
đến chromium-...@chromium.org
Bonjour, je développe ma première extension visant à modifier le css et le js d'un site bien précis. 

Dans ce but, j'ai ajouté ceci à la fin de mon manifest : 

"permissions": 
[
"tabs"
]

puis ceci dans la fonction initialiser de mon background : 

chrome.tabs.getSelected(null,function(tab) { url = tab.url; });

url = url.substring( 0 ,url.lastIndexOf( "/" ) );

Bien entendu, la variable url est une variable globale. Je me demandais pourquoi ça ne me renvoyait rien. Est-ce parce que j'ai fait une erreur ? Parce que ma page d'accueil est un nouvel onglet ? 

J'aimerais en fait pouvoir récupérer l'url de l'onglet afin de pouvoir appliquer les modifications sur le site en question et pas sur tout site, et j'aimerais si possible vérifier assez souvent l'url pour vérifier qu'elle corresponde bien, mais j'avoue que j'ai encore du mal à saisir comment fonctionne l'extension et comment fonctionne la récupération de l'url. Je ne saisis toujours pas quand et tous les combien de temps l'extension vérifiera l'url pour la vérification. J'aimerais si possible qu'à chaque changement de page ou rafraichissement que l'extension vérifie l'url pour appliquer les modifications.

Toute aide est la bienvenue.

Merci

Erik Price

chưa đọc,
07:07:47 28 thg 6, 201528/6/15
đến Jonathan Bihan, chromium-...@chromium.org

I am not sure if the manifest is case-sensitive, but you probably don’t want to capitalize permissions and tabs:

"permissions": [
  "tabs"
]

and the chrome.tabs.getSelected function is deprecated in favor of chrome.tabs.query, which gives you a list of tabs that match the first argument predicate:

chrome.tabs.query({active: true}, function(tabs) {
  for (var i in tabs) {
    console.log(tabs[i].url);
  }
});

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/7de59948-e21f-4e0e-8292-3a4bfc2f9fa1%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Jonathan Bihan

chưa đọc,
15:16:32 28 thg 6, 201528/6/15
đến chromium-...@chromium.org, taim...@gmail.com
Thanks, with chrome.tabs.query it works ! And the manifest isn't case-sensitive. 

Now, I have a new problem : 

chrome.tabs.executeScript(null,
{
code:"var p = document.getElementById('leftmenu').lastChild; p.style.color = 'white'; p.style.textAlign = 'center';"
});

With chrome.tabs.executeScript and without, the p element is not white and center. But, if I write an alert in the code, I have the alert. And in my manifest : 

"permissions": 
[
]

I have the permissions, but the modifications don't work. Why ? Have you got an idea about this ? Thanks
Trả lời tất cả
Trả lời tác giả
Chuyển tiếp
0 tin nhắn mới