I'm trying to write an extension for FF. Expansion should change some element on the site.
chrome.manifest
content vkstats chrome/content/ content vkstats chrome/content/ contentaccessible=yes overlay chrome://browser/content/browser.xul chrome://vkstats/content/browser.xul
content / browser.xul
<?xml version="1.0"?> <overlay id="vkstats" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script type="application/x-javascript" src="chrome://vkstats/content/main.js" /> </overlay>
content / main.js
var VKStats = { init: function () { ///////////////////////// var l_ap = document.getElementById('l_ap'); var l_stats = document.createElement('li'); l_stats.innerHTML = 'Тест'; insertAfter(l_stats, l_ap); }, getUserId: function () { var http = new XMLHttpRequest(); http.open("GET", "http://vk.com/", false); http.send(); var user_id = /"user_id":(\d+)/m; return user_id.exec(http.responseText)[1]; } }; function insertAfter(elem, refElem) { return refElem.parentNode.insertBefore(elem, refElem.nextSibling); }
It seems like the extension is enabled only when the browser is started, but the element is not added. If you add a code to JS, for example alert (111) ;, will work, only once at the start of the browser, regardless of which site the tab is on. Even if you refresh the page, alert will not work anyway.
Help me figure out what the problem is?
var VKStats = { init: function(){ if(gBrowser) gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad, false); }, onPageLoad: function(aEvent){ var doc = aEvent.originalTarget; // doc that triggered the event var win = doc.defaultView; // win is the window for the doc ///////////////////////// var l_ap = doc.getElementById('l_ap'); var l_stats = doc.createElement('li'); l_stats.innerHTML = 'тут текст'; //l_ap.appendChild(l_stats); insertAfter(l_stats, l_ap); }, getUserId: function(){ var http = new XMLHttpRequest(); http.open("GET","http://vk.com/",false); http.send(); var user_id = /"user_id":(\d+)/m; return user_id.exec(http.responseText)[1]; } }; function insertAfter(elem, refElem) { return refElem.parentNode.insertBefore(elem, refElem.nextSibling); } window.addEventListener("load", function load(event){ window.removeEventListener("load", load, false); VKstats.init(); },false);
(..)?
looks suspicious. Insert a temporaryalert(doc.location.href)
before theif
'om. - VladD