[Help] Updating an old add on for Firefox
Hello this is really my first time doing this kind of thing.
I have already learned how to unpack and pack a .jar file.
So first.
Heres the project.
https://addons.mozilla.org/en-US/firefox/addon/3915
Its link is out of date.
So I am trying to redirect it now.
Here is the source I guess
Code:
var DanbooruTB = {
// vars
_explicit : false,
_scroll : 8,
_results : 100,
offset : 0,
backlog : null,
// init
onLoad: function () {
window.addEventListener("unload", this.onUnload, false);
this.backlog = new Array();
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
var pbi = prefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
if (prefs.getPrefType("extensions.danboorutb.explicit") == prefs.PREF_BOOL)
this._explicit = this.getBoolPref(prefs, "extensions.danboorutb.explicit");
if (prefs.getPrefType("extensions.danboorutb.scroll") == prefs.PREF_INT)
this._scroll = this.getIntPref(prefs, "extensions.danboorutb.scroll");
if (prefs.getPrefType("extensions.danboorutb.results") == prefs.PREF_INT)
this._results = this.getIntPref(prefs, "extensions.danboorutb.results");
document.getElementById("danbooru_explicit").checked = this._explicit;
pbi.addObserver("extensions.danboorutb.explicit", DanbooruTB, false);
pbi.addObserver("extensions.danboorutb.scroll", DanbooruTB, false);
pbi.addObserver("extensions.danboorutb.results", DanbooruTB, false);
},
// deinit
onUnload: function () {
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
var pbi = prefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
pbi.removeObserver("extensions.danboorutb.explicit", DanbooruTB, false);
pbi.removeObserver("extensions.danboorutb.scroll", DanbooruTB, false);
pbi.removeObserver("extensions.danboorutb.results", DanbooruTB, false);
},
// pref handlers
observe: function (subject, topic, data) {
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
if(data == "extensions.danboorutb.explicit")
this._explicit = this.getBoolPref(prefs, "extensions.danboorutb.explicit");
if(data == "extensions.danboorutb.scroll")
this._scroll = this.getIntPref(prefs, "extensions.danboorutb.scroll");
if(data == "extensions.danboorutb.results")
this._results = this.getIntPref(prefs, "extensions.danboorutb.results");
},
// pref getters/setters (debugging)
getBoolPref : function (pb, p) { try { return pb.getBoolPref(p); } catch(ex) { dump(ex + "\n"); } return false; },
getIntPref : function (pb, p) { try { return pb.getIntPref(p); } catch(ex) { dump(ex + "\n"); } return false; },
setBoolPref : function (pb, p, v) { try { return pb.setBoolPref(p, v); } catch(ex) { dump(ex + "\n"); } return false; },
setIntPref : function (pb, p, v) { try { return pb.setIntPref(p, v); } catch(ex) { dump(ex + "\n"); } return false; },
requestPosts: function () {
document.getElementById("danbooru_status").value = "querying service...";
var req = new XMLHttpRequest();
var enctags = encodeURI(document.getElementById('danbooru_input').value);
if(!this._explicit) enctags += "+rating:safe";
req.open('GET', 'http://www.sagubooru.com/api/find_posts?tags=' + enctags + '&limit=' + this._results + '&offset=' + this.offset, true);
req.onreadystatechange = function(aEvt) {
if(req.readyState == 4)
if(req.status == 200)
DanbooruTB.parsePosts(req.responseXML);
};
req.send(null);
},
parsePosts: function (resp) {
document.getElementById("danbooru_status").value = "parsing result...";
var posts = resp.getElementsByTagName("post")
var piclist = document.getElementById("danbooru-piclist");
for(var i = 0; i < posts.length; i++) {
var _box = document.createElement("box");
var filename = posts[i].getAttribute("md5") + ".jpg";
var fileid = posts[i].getAttribute("id");
var tags = posts[i].getAttribute("tags");
var path = "http://sagubooru.com/data/preview/" + filename.slice(0, 2) + "/" + filename.slice(2, 4) + "/" + filename;
var fullpath = "http://sagubooru.com/post/view/" + fileid;
_box.setAttribute("style", "background-image: url(" + path + ")", false);
_box.setAttribute("onclick","if(event.button == 1) gBrowser.selectedTab = gBrowser.addTab(\"" + fullpath + "\"); else gBrowser.loadURI(\"" + fullpath + "\", null, null);", false);
_box.setAttribute("tooltiptext","Tags: " + tags, false);
piclist.appendChild(_box);
}
this.offset += posts.length;
document.getElementById("danbooru_status").value = "last request returned " + posts.length + " results (" + this.offset + " total so far)";
},
inputHandler: function (event) {
if(event.keyCode == event.DOM_VK_RETURN) {
var piclist = document.getElementById("danbooru-piclist");
while(piclist.hasChildNodes()) piclist.removeChild(piclist.firstChild);
while(this.backlog.length > 0) this.backlog.pop();
this.offset = 0;
this.requestPosts();
document.getElementById("danbooru-piclist-output").style.display = "block";
}
},
clear: function () {
document.getElementById('danbooru_status').value = '';
document.getElementById('danbooru_input').value = 'Tags';
document.getElementById('danbooru-piclist-output').style.display = 'none';
var piclist = document.getElementById('danbooru-piclist');
while(piclist.hasChildNodes()) piclist.removeChild(piclist.firstChild);
while(this.backlog.length > 0) this.backlog.pop();
this.offset = 0;
},
explictHandler: function (event) {
var exp = document.getElementById("danbooru_explicit");
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
this.setBoolPref(prefs, "extensions.danboorutb.explicit", !exp.checked);
var tags = document.getElementById('danbooru_input').value;
if(tags && tags != "Tags") {
var piclist = document.getElementById("danbooru-piclist");
while(piclist.hasChildNodes()) piclist.removeChild(piclist.firstChild);
while(this.backlog.length > 0) this.backlog.pop();
this.offset = 0;
this.requestPosts();
}
},
scroll: function (direction) {
var piclist = document.getElementById("danbooru-piclist");
switch(direction) {
case 1:
for(var i = 0; i < this._scroll; i++)
if(piclist.firstChild) this.backlog.push(piclist.removeChild(piclist.firstChild));
if(this.backlog.length >= this.offset - 3 * this._scroll) this.requestPosts();
break;
case -1:
if(this.backlog.length > 0)
for(var i = 0; i < this._scroll; i++)
if(this.backlog.length > 0) piclist.insertBefore(this.backlog.pop(), piclist.firstChild);
break;
}
}
} // DanbooruTB
window.addEventListener("load", function(e) { DanbooruTB.onLoad(e); }, false);
And here is what I guess needs the editing
Code:
req.open('GET', 'http://www.sagubooru.com/api/find_posts?tags=' + enctags + '&limit=' + this._results + '&offset=' + this.offset, true);
While looking through this now I have also notice something else thats important o.O
But before I take anything further I need pro help.
Here is what I've done
Code:
req.open('GET', 'http://danbooru.donmai.us/post?tags=' + enctags + '&searchDefault=Search');
This probably needs editing too
But I don't know what to do so if someone could help me.
Code:
parsePosts: function (resp) {
document.getElementById("danbooru_status").value = "parsing result...";
var posts = resp.getElementsByTagName("post")
var piclist = document.getElementById("danbooru-piclist");
for(var i = 0; i < posts.length; i++) {
var _box = document.createElement("box");
var filename = posts[i].getAttribute("md5") + ".jpg";
var fileid = posts[i].getAttribute("id");
var tags = posts[i].getAttribute("tags");
var path = "http://sagubooru.com/data/preview/" + filename.slice(0, 2) + "/" + filename.slice(2, 4) + "/" + filename;
var fullpath = "http://sagubooru.com/post/view/" + fileid;
_box.setAttribute("style", "background-image: url(" + path + ")", false);
_box.setAttribute("onclick","if(event.button == 1) gBrowser.selectedTab = gBrowser.addTab(\"" + fullpath + "\"); else gBrowser.loadURI(\"" + fullpath + "\", null, null);", false);
_box.setAttribute("tooltiptext","Tags: " + tags, false);
piclist.appendChild(_box);
}
Re: [Help] Updating an old add on for Firefox
What do you need help with though the detecting the new update through FF?
Re: [Help] Updating an old add on for Firefox
Actually I use Lolifox and I'm just changing the site.
There are tons of sites with the name 'booru' in them.
I basically want to change the site to the official one.
The first stuff in the first code section is another site.
I just wanna change the site.
They use the same source for the site too I think.