javascript - What's wrong with my extension? -
backg.html
<script type="text/javascript"> var domurl = "http://www.xxxxxx.xxxx/id"; var txt; var txt2; var id1; var id2; var imgarres = []; var imgarr = []; var imgels = []; var anchors = []; var anc = []; function getdata() { if (id1){cleartimeout(id1);} if (id2){cleartimeout(id2);} geturl(); var xurl = null; xurl = localstorage['url']; var xhr = new xmlhttprequest(); xhr.open('get',xurl, true); xhr.setrequestheader('cache-control', 'no-cache'); xhr.setrequestheader('pragma', 'no-cache'); xhr.onreadystatechange = function() { if (xhr.readystate == 4) { txt = xhr.responsetext; var r = txt.indexof('<b class="fl_r">online</b>'); var el = document.createelement("div"); el.innerhtml = txt; var n = imgprocess(el,xurl); var nam = el.getelementsbytagname("title")[0].innerhtml; if (r != -1) { var notification = webkitnotifications.createnotification(n, nam, 'online!!' ); notification.show(); id1 = settimeout(getdata, 60000*45); } else { id2 = settimeout(getdata, 60000*2); } }} xhr.send(); } function imgprocess(text,url){ imgarres = []; imgarr = []; imgels = text.getelementsbytagname("img"); (var i=0;i< imgels.length;i++){ if (imgels[i].src.indexof(parse(url)) != -1){ imgarr.push(imgels[i]); } } (var p=0; p< imgarr.length; p++){ if (imgarr[p].parentnode.nodename=="a"){ imgarres.push(imgarr[p]); } } var z = imgarres[0].src; return z; } function geturl(){ if (localstorage.id){ if (isnan(localstorage.id)){ nicktoid(localstorage.id, function(resul){ localstorage.removeitem("url"); localstorage["url"] = "http://xxxxxxxx.xxxx/id" + resul; }); } else { localstorage.removeitem("url"); localstorage["url"] = domurl + localstorage.id; } } else { var notif = webkitnotifications.createnotification(null, 'blah,blah,blah', 'specify id ' ); notif.show(); getdata(); } } function nicktoid(nick, callback){ var u = "http://xxxxxxx.xxxx/" + nick ; var xhr2 = new xmlhttprequest(); xhr2.open('get',u, true); xhr2.setrequestheader('cache-control', 'no-cache'); xhr2.setrequestheader('pragma', 'no-cache'); xhr2.onreadystatechange = function() { if (xhr2.readystate == 4) { txt2 = xhr2.responsetext; var el2 = document.createelement("div"); el2.innerhtml = txt2; anchors = el2.getelementsbytagname("a"); (var i=0;i< anchors.length;i++){ if (anchors[i].parentnode.id == "profile_avatar"){ anc.push(anchors[i]); } } var res = anc[0].href; var ir = res.replace(/^chrome-extension:\/\/.*?\//, "/"); var arstr = ir.split("_"); var resul = arstr[0].substr(6); callback(resul); } } xhr2.send(); } function init() { getdata(); } </script> </head> <body onload="init();"> </body> </html>
options.html
<script> onload = function() { if (localstorage.id){ document.getelementbyid("identifier").value = localstorage.id; } else { var el = document.createelement("div"); el.innerhtml = "enter id!!"; document.getelementsbytagname("body")[0].appendchild(el); } }; function onch(){ localstorage.id = document.getelementbyid("identifier").value; var bg = chrome.extension.getbackgroundpage(); if(bg.id1){ bg.getdata(); } } </script> <body> <h1> </h1> <form id="options"> <h2>settings</h2> <label><input type='text' id ='identifier' value='' onchange="onch();"> enter id </label> </form> </body> </html>
this post follow-up previous one. decided add specifying user nickname (in addition id). problem is: doesnt work expected. doesnt change user via options page immediately. (probably) saves nick localstorage, displays previous user!! begins display current user after twice reloading extension!!(specifying via ids works fine!). did miss?
Comments
Post a Comment