Code:
var cpc_lurker = {
onLoad: function() {
this.console = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
this.cpc_prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.cpc_lurker.");
this.ostype = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS;
if (this.ostype == 'Darwin') this.setPref('forcelargepref',false,'b');
this.prefObserver.register();
if (!this.getById('cpc_lurker-toolbar-button')) {
if (this.getPref('firstrunpref','b') || this.getPref('activepref','b')) {
this.setPref('firstrunpref',false,'b');
this.addBtn('nav-bar','cpc_lurker-toolbar-button');
this.applyBaseStyle();
this.init();
}
} else {
this.setPref('firstrunpref',false,'b');
this.applyBaseStyle();
if (this.getPref('activepref','b')) {
this.init();
}
}
},
prefObserver: {
register: function() {
cpc_lurker.cpc_prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
cpc_lurker.cpc_prefs.addObserver("", this, false);
},
unregister: function() {
if (!cpc_lurker.cpc_prefs) return;
cpc_lurker.cpc_prefs.removeObserver("", this);
},
observe: function(aSubject, aTopic, aData) {
if(aTopic != "nsPref:changed") return;
switch (aData) {
case "forcelargepref": if (cpc_lurker.styleapplied) cpc_lurker.applyForceLarge();
case "badgepref": if (cpc_lurker.initialized) { cpc_lurker.updateButton(cpc_lurker.verif); } break;
case "themepref": if (cpc_lurker.initialized) cpc_lurker.constructPopup(cpc_lurker.verif); break;
case "widthpoppref": if (cpc_lurker.initialized) cpc_lurker.applyPopupWidth(); break;
case "heightpoppref": if (cpc_lurker.initialized) cpc_lurker.applyPopupHeight(); break;
}
}
},
applyBaseStyle:function() {
this.btn_cpc = this.getById("cpc_lurker-toolbar-button");
if (this.btn_cpc) {
this.stack_cpc = this.getById("cpc_lurker-stack");
this.badge_cpc = this.getById("cpc_lurker-badge");
this.num_cpc = this.getById("cpc_lurker-num");
this.btn_cpc.setAttribute('ostype',this.ostype);
this.stack_cpc.setAttribute('ostype',this.ostype);
this.badge_cpc.setAttribute('ostype',this.ostype);
this.num_cpc.setAttribute('ostype',this.ostype);
this.styleapplied = true;
this.applyForceLarge();
}
},
applyForceLarge: function() {
var forcelargepref = this.getPref('forcelargepref','b',false);
this.btn_cpc.setAttribute('forcelarge',forcelargepref);
this.stack_cpc.setAttribute('forcelarge',forcelargepref);
this.badge_cpc.setAttribute('forcelarge',forcelargepref);
this.num_cpc.setAttribute('forcelarge',forcelargepref);
},
init: function() {
if (!this.styleapplied) this.applyBaseStyle();
this.strings = this.getById("cpc_lurker-strings");
this.menupopup_cpc = this.getById("cpc_lurker-menupopup");
this.menuactive_cpc = this.getById("cpc_lurker-menuactive");
this.menulogout_cpc = this.getById('cpc_lurker-menulogout');
this.menurefresh_cpc = this.getById("cpc_lurker-menurefresh");
this.popup_cpc = this.getById("cpc_lurker-popup");
this.popup_cpc_inner = this.getById("cpc_lurker-inner");
this.popup_ctnt_node_cpc = this.getById("cpc_lurker-popupctnt").cloneNode(true);
this.title_cpc = this.getById("cpc_lurker-title_cpc");
this.refresh_cpc = this.getById("cpc_lurker-btn_refresh");
this.footer_cpc = this.getById('cpc_lurker-footer');
this.readall_cpc = this.getById('cpc_lurker-readall');
this.logout_cpc = this.getById('cpc_lurker-logout');
this.popup_cpc.addEventListener('popupshowing', function(e) { cpc_lurker.onPopupShowing(); }, false);
this.popup_cpc.addEventListener('popuphiding', function(e) { cpc_lurker.onPopupHiding(); }, false);
this.title_cpc.addEventListener('click', function(e) { cpc_lurker.onTitleClick(e); }, false);
this.refresh_cpc.addEventListener('click', function(e) { cpc_lurker.onRefresh(e); }, false);
this.readall_cpc.addEventListener('click', function(e) { cpc_lurker.confReadAll(e); }, false);
this.logout_cpc.addEventListener('click', function(e) { cpc_lurker.confLogout(e); }, false);
this.htmlcache; this.popupcache; this.tooltiptext_mt; this.lnt_old; this.hash;
this.nM; this.nT; this.nM_old; this.nT_old;
this.badge_m; this.badge_t; this.theme; this.icns_old; this.fl_old;
this.timeout_upd; this.timeout_bdg; this.txt_px_old; this.prev_badge;
this.verif = -3;
this.initialized = true;
this.applyFFVersion();
this.applyPopupWidth();
this.activeCPC(this.getPref('activepref','b'));
},
onTitleClick:function(e) {
switch (e.button) {
case 0:
if(this.getPref('currenttabpref','b')) {
this.openCPC(false,false,false,true);
break;
}
case 1: this.openCPC(false,false,e.button); break;
default: break;
}
if (e.button == 0) this.switchPopup(this.popup_cpc,false);
},
onPopupShowing: function() {
this.switchBtn();
if (this.verif == 1) this.stopTimeout(cpc_lurker.timeout_upd);
},
onPopupHiding: function() {
this.switchBtn();
switch (this.verif) {
case 1: this.startUpdate((this.getPref('freshpoppref','s',true)*1000)); break;
case -3: break;
default: this.startUpdate(); break;
}
},
onToolbarButtonMousedown: function(e) {
if (e.target.id == "cpc_lurker-toolbar-button") {
switch (e.button) {
case 0:
if (this.getPref("clickpref","s") == "1" && this.initialized) { this.switchPopup(this.popup_cpc,true,true); }
break;
case 2:
if (this.initialized) {
if (this.menupopup_cpc.state == "closed") { this.switchPopup(this.menupopup_cpc,true); }
} else if (this.getById('cpc_lurker-menupopup').state == "closed") {
this.getById('cpc_lurker-menupopup').openPopup(this.getById('cpc_lurker-toolbar-button'), this.getPref("positionpref","s"), 0, 0, false, false);
}
break;
default: break;
}
}
},
onToolbarButtonMouseup: function(e) {
if (e.target.id == "cpc_lurker-toolbar-button") {
switch (e.button) {
case 0:
if (this.getPref('clickpref','s') == '2') { this.openCPC(); }
else if (this.getPref('clickpref','s') == '3' && this.verif == 1)
{
this.onOpenSelAllClick(e,true);
this.startUpdate((this.getPref('freshpoppref','s',true)*1000));
}
break;
case 1: this.openCPC(); break;
default: break;
}
}
},
onMenuActiveCommand: function() {
var switchactive = !this.getPref('activepref','b');
this.setPref('activepref',switchactive,'b');
if (!this.initialized && switchactive) {
this.init();
} else {
this.activeCPC(switchactive);
}
},
onMenuLogoutCommand: function() {
this.openCPC('login.php?do=logout&logouthash='+this.hash,true);
this.menulogout_cpc.setAttribute('disabled','true');
this.verif = -1;
this.updateButton(this.verif);
this.constructPopup(this.verif);
},
onRefresh: function(e) {
if (e.button == 0) this.update();
},
onLnksClick: function(e) {
switch (e.button) {
case 0: this.switchPopup(this.popup_cpc,false); this.openCPC(e.target.getAttribute('lien'),true,false,this.getPref('currenttabpref','b')); break;
case 1: this.openCPC(e.target.getAttribute('lien')); break;
default: break;
}
if (e.button != 2) e.target.setAttribute('opnd','true');
},
onOpenSelAllClick: function(e,all) {
if (e.button == 0) {
var chkd = false;
var chkbxs = document.getElementsByClassName('chkbx');
var chkbxs_l = chkbxs.length;
for (var i=0;i<chkbxs_l;i++) {
if (all || chkbxs[i].checked) {
this.openCPC(chkbxs[i].nextSibling.getAttribute('lien'));
chkbxs[i].nextSibling.setAttribute('opnd','true');
chkbxs[i].checked = false;
chkd = true;
}
}
if (all || chkd) { this.switchPopup(this.popup_cpc,false); }
}
},
activeCPC: function(activepref) {
if (activepref) {
this.menurefresh_cpc.setAttribute('disabled','false');
this.menuactive_cpc.setAttribute('label',this.strings.getString('menudisable'));
this.startUpdate(3000);
} else {
this.nM = 0;
this.nT = 0;
this.verif = -3;
this.stopTimeout(this.timeout_bdg);
this.stopTimeout(this.timeout_upd);
this.updateButton(this.verif);
this.menurefresh_cpc.setAttribute('disabled','true');
this.menuactive_cpc.setAttribute('label',this.strings.getString('menuenable'));
this.menulogout_cpc.setAttribute('disabled','true');
this.constructPopup(this.verif);
}
},
update: function(boucle) {
this.xhrCPC();
if (boucle) { this.startUpdate(); }
},
constructAddon: function(response) {
this.verif = this.verifXHR(response);
this.updateButton(this.verif);
this.constructPopup(this.verif);
},
constructPopup: function(verif) {
var ntheme = this.applyTheme();
var new_popup_ctnt = this.popup_ctnt_node_cpc.cloneNode(true);
if (verif != -3) { this.refresh_cpc.setAttribute('hidden','false'); } else { this.refresh_cpc.setAttribute('hidden','true'); }
if (verif >= 0) { this.footer_cpc.setAttribute('hidden','false'); } else { this.footer_cpc.setAttribute('hidden','true'); }
if (verif == 1) {
var cache = true;
var lnt = this.getLnT();
var lnt_l = lnt.length;
if ((this.nM+this.nT) != (this.nM_old+this.nT_old) || ntheme) {
cache = false;
} else {
var k = 0;
while (cache && k<lnt_l) {
if (lnt[k].titre != this.lnt_old[k].titre) { cache = false; }
k++;
}
}
if (cache) {
new_popup_ctnt = this.popup_cache.cloneNode(true);
} else {
this.lnt_old = lnt;
this.createElement('label',['value',this.btn_cpc.getAttribute('tooltiptext')],new_popup_ctnt);
this.createElement('separator',['class','groove','style','margin-bottom:10px;'],new_popup_ctnt);
var vbm;
if (this.nM) {
vbm = this.createElement('vbox',false,new_popup_ctnt);
var hbmpall = this.createElement('hbox',false,vbm);
this.createElement('label',[
'class','cpc_lurker-gras cpc_lurker-lnkall',
'value',this.strings.getString('mplabel')+' ('+this.nM+')',
'lien','private.php?rien=0',
'tooltiptext',this.strings.getString('mptooltip'),
'onclick','cpc_lurker.onLnksClick(event);'
],hbmpall);
}
var vbt;
if (this.nT) {
vbt = this.createElement('vbox',false,new_popup_ctnt);
if (vbm) { this.createElement('separator',['class','thin'],vbt); }
var hbtall = this.createElement('hbox',false,vbt);
this.createElement('label',[
'class','cpc_lurker-gras cpc_lurker-lnkall',
'value',this.strings.getString('tlabel')+' ('+this.nT+')',
'lien','subscription.php?do=viewsubscription&folderid=all',
'tooltiptext',this.strings.getString('ttooltip'),
'onclick','cpc_lurker.onLnksClick(event);'
],hbtall);
}
for (var i=0;i<lnt_l;i++) {
var hbl;
switch (lnt[i].type) {
case 'm': hbl = this.createElement('hbox',false,vbm); break;
default : hbl = this.createElement('hbox',false,vbt); break;
}
this.createElement('checkbox',['label',lnt[i].num+1+'.','class','chkbx'],hbl);
this.createElement('label',[
'flex','1',
'crop','end',
'class',this.theme+' cpc_lurker-lnk',
'value',lnt[i].titre,
'lien',lnt[i].lien,
'tooltiptext',lnt[i].titre,
'onclick','cpc_lurker.onLnksClick(event);'
],hbl);
this.createElement('spacer',['flex','100'],hbl);
}
var hbbtn = this.createElement('hbox',['id','cpc_lurker-hbbtn'],new_popup_ctnt);
this.createElement('label',[
'class','cpc_lurker-btn',
'value',this.strings.getString('opensellabel'),
'onclick','cpc_lurker.onOpenSelAllClick(event,false);'
],hbbtn);
this.createElement('label',[
'class','cpc_lurker-btn',
'value',this.strings.getString('openalllabel'),
'onclick','cpc_lurker.onOpenSelAllClick(event,true);'
],hbbtn);
this.popup_cache = new_popup_ctnt.cloneNode(true);
}
} else {
this.createElement('label',['value',this.strings.getString('popupctnt'+(verif+4))],new_popup_ctnt);
}
this.popup_cpc_inner.replaceChild(new_popup_ctnt,this.getById('cpc_lurker-popupctnt'));
this.applyPopupHeight();
},
applyFFVersion: function() {
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo);
var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"].getService(Components.interfaces.nsIVersionComparator);
if (versionChecker.compare(appInfo.version, "16") >= 0) {
this.popup_cpc.setAttribute('ff','v16');
} else {
this.popup_cpc.setAttribute('ff','pre16');
}
},
applyPopupWidth: function() {
this.popup_cpc.setAttribute('style','max-width:'+this.getPref('widthpoppref','s',false)+'px;');
},
applyPopupHeight: function() {
var h = Number(this.popup_cpc_inner.clientHeight);
var maxH = this.getPref('heightpoppref','s',true);
if (h > maxH) {
this.popup_cpc_inner.setAttribute('height',String(maxH));
} else if(this.popup_cpc_inner.getAttribute('height')) {
this.popup_cpc_inner.removeAttribute('height');
}
},
applyTheme: function() {
var ntheme = false;
var themepref = this.getPref('themepref','s');
var theme_os;
switch (this.ostype) {
case "WINNT": theme_os = 'win'+themepref; break;
case "Linux": theme_os = 'nux'+themepref; break;
case "Darwin": theme_os = 'osx'+themepref; break;
default: break;
}
if (this.theme != theme_os) {
this.popup_cpc.setAttribute('class',theme_os);
this.refresh_cpc.setAttribute('class',theme_os);
this.readall_cpc.setAttribute('class',theme_os);
this.logout_cpc.setAttribute('class',theme_os);
this.theme = theme_os;
ntheme = true;
}
return ntheme;
},
createElement: function(element,attrs,papa) {
var el = document.createElement(element);
if (attrs) {
var a_l = attrs.length;
for (var i=0;i<a_l;i+=2) {
el.setAttribute(attrs[i],attrs[i+1]);
}
}
if (papa) { papa.appendChild(el); }
return el;
},
getLnT: function() {
var mTab;
var tTab;
var fTab;
if (this.nM) { mTab = this.extractLnT(/pmid=\d+" class="title">.+</gi,"private.php?do=showpm&","m"); }
if (this.nT) { tTab = this.extractLnT(/threads\/.+" id="thread_title_\d+">.+</gi,"?goto=newpost","t"); }
if (mTab && tTab) {
fTab = mTab.concat(tTab);
} else if (tTab) {
fTab = tTab;
} else {
fTab = mTab;
}
return fTab;
},
extractLnT: function(pattern,add,type) {
var titrePattern = />.+<$/;
var trimPattern = /".+<$/;
var raw = this.htmlcache.match(pattern);
var raw_l = raw.length;
var retour = new Array(raw_l-1);
for (var i=0;i<raw_l;i++) {
var t = raw[i].match(titrePattern)[0];
t = t.substring(1,t.length-1);
t = t.replace(/"/g,'"').replace(/&/g,'&');
var l = raw[i].replace(trimPattern,"");
if (type == "m") { l = add+l; }
else { l = l+add; }
retour[i] = {
'num':i,
'type':type,
'titre':t,
'lien':l
}
}
return retour;
},
xhrCPC: function(alt) {
var date = new Date();
var url = this.getPref("accesspref","s");
var xhr = new XMLHttpRequest();
if (!alt) {
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200 && this.responseText) {
cpc_lurker.constructAddon(this.responseText);
} else {
cpc_lurker.constructAddon(null);
}
}
};
xhr.open('GET', url+"/usercp.php?nocache="+date.getTime(), true);
} else {
xhr.open('GET', url+alt, true);
}
this.addCookies(xhr,url);
xhr.send();
},
addCookies: function(xhr,url) {
var hostpref = url.replace(/^http:\/\/forum[2]?/,"");
var cookieManager = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager);
var iter = cookieManager.enumerator;
while (iter.hasMoreElements()) {
var cookie = iter.getNext();
if (cookie instanceof Components.interfaces.nsICookie) {
if (cookie.host == hostpref) { xhr.setRequestHeader("Cookie",cookie.name+"="+cookie.value); }
}
}
},
verifXHR: function(html) {
if (html == undefined || html == null) { html = -2; }
else if (html.indexOf('<div class="cp_content">') == -1) { html = -1; }
else {
this.nM_old = this.nM;
this.nT_old = this.nT;
this.hash = this.getByPatt(html,/markreadhash=([^"]+)/,1,false);
this.htmlcache = this.getSubThread(html);
this.nM = this.getByPatt(html,/<a href="private\.php" class="understate">.+<\/a> \(([0-9]+)\)/,1,true);
this.nT = this.getByPatt(html,/<h2 class="blockhead">.+ \(([0-9]+)\)<\/h2>/,1,true);
if (!(this.nM+this.nT)) { html = 0; }
else { html = 1; }
}
return html
},
updateButton: function(verif) {
var tooltiptext = "";
this.stack_cpc.setAttribute('class','p'+(verif+4));
if (verif >= 0) this.menulogout_cpc.setAttribute('disabled','false');
if (verif == 1) {
var nMchanged, nTchanged, pxchanged, icnschanged, flchanged;
var txt_px = this.getPref('badgepref','s',true);
var icns = this.getNavIconsize();
var fl = this.getPref('forcelargepref','b',false);
if (this.icns_old != icns) { icnschanged = true; this.icns_old = icns; }
if (this.fl_old != fl) { flchanged = true; this.fl_old = fl; }
if (this.txt_px_old != txt_px) { pxchanged = true; this.txt_px_old = txt_px; }
if (this.nT != this.nT_old) { nTchanged = true; }
if (this.nM != this.nM_old) { nMchanged = true; }
if (nTchanged || pxchanged || icnschanged || flchanged) {
var bT = {};
bT.height = Number(txt_px);
bT.type = 't';
bT.num = Number(this.nT);
bT.icns = icns;
bT.fl = fl;
this.badge_t = this.constructBadge(bT);
} else {
this.badge_t = this.constructBadge({num:0});
}
if (nMchanged || pxchanged || icnschanged || flchanged) {
var bM = {};
bM.height = Number(txt_px);
bM.type = 'm';
bM.num = Number(this.nM);
bM.icns = icns;
bM.fl = fl;
this.badge_m = this.constructBadge(bM);
} else {
this.badge_m = this.constructBadge({num:0});
}
if (nTchanged || nMchanged) {
if(this.nM) {
tooltiptext = this.nM + " ";
if (this.nM > 1) { tooltiptext += this.strings.getString("messplus");}
else { tooltiptext += this.strings.getString("mess"); }
}
if(tooltiptext && this.nT) { tooltiptext += ", "; }
if(this.nT) {
tooltiptext += this.nT + " ";
if (this.nT > 1) { tooltiptext += this.strings.getString("discuplus"); }
else { tooltiptext += this.strings.getString("discu"); }
}
this.tooltiptext_mt = tooltiptext;
} else {
tooltiptext = this.tooltiptext_mt
}
if (this.badge_t && this.badge_m) {
this.diapoBadges(true);
} else if (this.badge_t) {
this.stopTimeout(this.timeout_bdg);
this.applyBadge(this.badge_t);
} else if (this.badge_m){
this.stopTimeout(this.timeout_bdg);
this.applyBadge(this.badge_m);
}
} else {
this.stopTimeout(this.timeout_bdg);
this.hideBadge();
tooltiptext = this.strings.getString("m"+(verif+4));
}
this.btn_cpc.setAttribute('tooltiptext',tooltiptext);
},
getSubThread: function(html) {
var debut = html.indexOf('<div class="cp_content">');
var fin = html.indexOf('<!-- ############## END SUBSCRIBED THREADS ############## -->');
return html.substring(debut, fin);
},
getByPatt: function(str,patt,idx,pint) {
var retour = str.match(patt);
if (retour) {
if (pint) return parseInt(retour[idx]);
return retour[idx];
}
return 0;
},
constructBadge: function(badge) {
var retour = null;
if (badge.num > 0) {
retour = {};
var icns = 16;
if ((badge.icns == 'large' && this.ostype == 'Linux') || badge.fl) icns = 24;
var typ_idx_x = 0;
var typ_idx_y = 0;
var siz_idx_x = 0;
var siz_idx_y = 0;
var num_idx_x = 0;
var num_idx_y = 0;
var coef_num_idx_x = 0;
var coef_num_idx_y = 0;
if (badge.height < 8) badge.height = 8;
if (badge.height > 11) badge.height = 11;
if (badge.num > 99) badge.num = 99;
if (badge.num > 9) { typ_idx_x += icns; }
if (badge.type == 'm') { typ_idx_x += (icns*2); }
switch(badge.height) {
case 8:
break;
case 9:
typ_idx_y += icns;
siz_idx_x += icns*10;
break;
case 10:
typ_idx_y += (icns*2);
siz_idx_y += icns*10;
break;
case 11:
typ_idx_y += (icns*3);
siz_idx_x += icns*10;
siz_idx_y += icns*10;
break;
}
if (badge.num < 10) {
coef_num_idx_x = badge.num;
} else {
coef_num_idx_x = Number(String(badge.num).charAt(1));
coef_num_idx_y = Number(String(badge.num).charAt(0))
}
typ_idx_x = String(-(typ_idx_x));
typ_idx_y = String(-(typ_idx_y));
num_idx_x = String(-(siz_idx_x+(icns*coef_num_idx_x)));
num_idx_y = String(-(siz_idx_y+(icns*coef_num_idx_y)));
retour.badge = 'background-position: '+typ_idx_x+'px '+typ_idx_y+'px';
retour.num = 'background-position: '+num_idx_x+'px '+num_idx_y+'px';
}
return retour;
},
applyBadge: function(styles) {
this.badge_cpc.setAttribute('style',styles.badge);
this.num_cpc.setAttribute('style',styles.num);
this.badge_cpc.setAttribute('hidden','false');
this.num_cpc.setAttribute('hidden','false');
},
hideBadge: function() {
this.prev_badge = null;
this.badge_cpc.setAttribute('hidden','true');
this.num_cpc.setAttribute('hidden','true');
},
diapoBadges: function(boucle) {
if (this.prev_badge == "t") {
this.applyBadge(this.badge_m);
this.prev_badge = "m";
} else {
this.applyBadge(this.badge_t);
this.prev_badge = "t";
}
if (boucle) { this.startDiapoBadges(); }
},
getById: function(id) {
return document.getElementById(id);
},
getNavIconsize: function() {
return document.getElementById("nav-bar").getAttribute("iconsize");
},
switchBtn: function() {
this.btn_cpc.open = !this.btn_cpc.open;
},
switchPopup: function(popup,open,arrow) {
if (open) {
var positionpref = this.getPref('positionpref','s');
popup.openPopup(this.btn_cpc, positionpref, this.getXPopup(positionpref,arrow), 0, false, false);
} else {
popup.hidePopup();
}
},
getXPopup: function(positionpref,arrow) {
var x = 0;
if (arrow) {
var rectBtn = this.btn_cpc.getBoundingClientRect();
x = -((rectBtn.right-rectBtn.left)/2);
if (positionpref == 'after_start') { x = -x; }
}
return x;
},
getPref: function(cpcpref,type,n) {
switch (type) {
case "s": cpcpref = this.cpc_prefs.getCharPref(cpcpref); break;
case "i": cpcpref = this.cpc_prefs.getIntPref(cpcpref); break;
case "b": cpcpref = this.cpc_prefs.getBoolPref(cpcpref); break;
default: break;
}
if (n) { cpcpref = Number(cpcpref); }
return cpcpref;
},
setPref: function(cpcpref,val,type) {
switch (type) {
case "s": this.cpc_prefs.setCharPref(cpcpref,val); break;
case "i": this.cpc_prefs.setIntPref(cpcpref,val); break;
case "b": this.cpc_prefs.setBoolPref(cpcpref,val); break;
default: break;
}
},
openCPC: function(alt,active,mbutton,currentTab) {
var access = this.getPref("accesspref","s");
var related = this.getPref('tabrelatedpref','b');
var date = new Date();
var url;
var where;
if ((alt && !active) || mbutton == 1) { where = 'tab'; } else { where = 'tabshifted'; }
if (alt) { url = access+"/"+alt+"&nocache="+date.getTime(); }
else { url = access+"/usercp.php?nocache="+date.getTime(); }
if ('privateTab' in window && this.getPref('noprivtabpref','b')) { privateTab.readyToOpenTab(false); }
if(currentTab) {
gBrowser.loadURI(url);
} else {
openLinkIn(url,where,{relatedToCurrent:related});
}
},
startUpdate: function(time) {
this.stopTimeout(this.timeout_upd);
if (time) {
this.timeout_upd = setTimeout(function() { cpc_lurker.update(true); },time);
} else {
this.timeout_upd = setTimeout(function() { cpc_lurker.update(true); },this.getPref("refreshpref","s",true)*60000);
}
},
startDiapoBadges: function() {
this.stopTimeout(this.timeout_bdg);
this.timeout_bdg = setTimeout(function() { cpc_lurker.diapoBadges(true); },5000);
},
stopTimeout: function(to) {
if (to) { clearTimeout(to); to = null; }
},
confReadAll: function(e) {
if (e.button == 0) {
this.switchPopup(this.popup_cpc,false);
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
var ok = promptService.confirm(
window,
this.strings.getString("confirmTitle"),
this.strings.getString("confirmMessageReadAll"));
if (ok) {
this.xhrCPC('/forumdisplay.php?do=markread&markreadhash='+this.hash);
setTimeout(function() { cpc_lurker.update(); },3000);
} else {
this.switchPopup(this.popup_cpc,true,true);
}
}
},
confLogout: function(e) {
if (e.button == 0) {
this.switchPopup(this.popup_cpc,false);
var check = { value: false };
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
var ok = promptService.confirmCheck(
window,
this.strings.getString("confirmTitle"),
this.strings.getString("confirmMessageLogout"),
this.strings.getString("confirmMessageDisable"),
check);
if (ok) {
this.openCPC('login.php?do=logout&logouthash='+this.hash,true);
if (check.value) { this.onMenuActiveCommand(); }
} else {
this.switchPopup(this.popup_cpc,true,true);
}
}
},
addBtn: function(toolbarId, id) {
var tb = this.getById(toolbarId);
var before = null;
tb.insertItem(id, before);
tb.setAttribute("currentset", tb.currentSet);
document.persist(tb.id, "currentset");
if (toolbarId == "addon-bar") tb.collapsed = false;
}
};
window.addEventListener("load", function () { cpc_lurker.onLoad(); }, false);
Il y a d'ailleurs eu une MAJ de l'extension récemment. Quelqu'un sait ce qui a changé ?