diff --new-file --recursive --suppress-common-lines --exclude changes.txt --exclude diff.txt releases/unplug-2.030/source/chrome/content/common.js releases/unplug-2.031/source/chrome/content/common.js 135,136c135,136 < version : 2.030, < codename : "clinic", --- > version : 2.031, > codename : "sprawl", 139c139 < revision : 201008150338, --- > revision : 201008160118, diff --new-file --recursive --suppress-common-lines --exclude changes.txt --exclude diff.txt releases/unplug-2.030/source/chrome/content/display/pop/pop.js releases/unplug-2.031/source/chrome/content/display/pop/pop.js 47a48,65 > // preferered downloaders from config > switch (UnPlug2.get_pref("downloader")) { > case "saveas": > this.preferred_downloaders = ["saveas"]; > break; > case "openover": > this.preferred_downloaders = ["openover"]; > break; > default: > this.preferred_downloaders = ["dta", "flashgot", "saveas"]; > break; > } > // fallbacks (if the default fails) > this.preferred_downloaders.push("special"); > this.preferred_downloaders.push("saveas"); > // this.preferred_downloaders.push("openover"); > this.preferred_downloaders.push("fallback"); > 52c70,73 < this.results = []; --- > this.download_to_uid = {}; // { result.download.toSource() : 1 } > this.results = []; // { 1 : result } ... or rather [ ..., result, ... ] > this.media_id_lookup = {}; // { "youtube-324121" : [1, ...] } > this.playlist_id_lookup = {}; // { "youtube-uploader-1213" : [1, ...] } 83c104 < var all_results = document.getElementsByTagName("unplug_result"); --- > var num_results = UnPlug2SearchPage.results.length; 85c106 < if (all_results.length == 0) { --- > if (num_results == 0) { 88c109 < } else if (all_results.length == 1) { --- > } else if (num_results == 1) { 91c112 < document.getElementById("dynamic_results").value = UnPlug2.str("search_n_results").replace("#", all_results.length); --- > document.getElementById("dynamic_results").value = UnPlug2.str("search_n_results").replace("#", num_results); 103a125,126 > var e = document.getElementById("dynamic_results"); > e.value = "Have errors"; 107,117d129 < // drag+drop observer < drag_and_drop_observer : function (url) { < return { < onDragStart: function (e, transferData, action) { < transferData.data = new TransferData(); < transferData.data.addDataForFlavour("text/unicode", url); < /* transferData.data.addDataForFlavour("text/html", url); */ < } < }; < }, < 123d134 < UnPlug2.log("FOUND: " + result.toSource()); 129,135c140,156 < for (var i = 0; i < UnPlug2SearchPage.results.length; i++) { < // JavaScript being retarded here: < // {"X" : "Y"} == {"X" : "Y"} -> false < // So convert to source strings and compare to give the correct damned answer! < if (UnPlug2SearchPage.results[i].download.toSource() === result.download.toSource()) { < var old_result_widget = document.getElementById("result_" + i); < old_result_widget.addDuplicate(result); --- > /* > * detect if it's an exact duplicate > * In JavaScript, asking if {"X" : "Y"} == {"X" : "Y"} -> false > * So convert to source strings and compare to give the correct answer! > */ > var download_tosource = result.download.toSource(); > var uid = UnPlug2SearchPage.download_to_uid[download_tosource]; // TODO -- also need to check this key is not a "native object" like "length", "toString", etc! > > UnPlug2.log("FOUND: " + result.toSource() + " as " + (uid || "new result")); > > if (uid === undefined) { > try { > // we need to add a new object > var uid = UnPlug2SearchPage.results.length; > UnPlug2SearchPage.download_to_uid[download_tosource] = uid; > UnPlug2SearchPage.results[uid] = result; > result.uid = uid; 137,140c158,189 < if (!UnPlug2SearchPage.results[i].details.file_ext) { < UnPlug2SearchPage.results[i].details.file_ext = result.details.file_ext; < } < return; --- > var reselem = UnPlug2SearchPage.result_e_create(); > reselem.setAttribute("id", "result_" + uid); > reselem.setAttribute("tooltiptext", "uid=" + uid + "\n\ndownload=" + result.download.toSource() + "\n\noriginal = " + result.details.toSource()); > > // sets download callbacks, etc > UnPlug2SearchPage.result_e_set_download(reselem, result); > > // this sets labels, icons, descripions, css, etc > // but wont ever move the element > UnPlug2SearchPage.result_e_set_description(reselem, result); > > // container for the group, eg the mediaid and/or playlistid > UnPlug2SearchPage.set_container(uid, reselem, result.details); > > } catch(e) { > UnPlug2.log("ERROR displaying result " + e); > } > } else { > var reselem = document.getElementById("result_" + uid); > var old_result = UnPlug2SearchPage.results[uid]; > if (old_result.certainty > result.certainty) { > // Update > UnPlug2SearchPage.results[uid].details = result.description; > > // we need to update this.results and the widget displayed on the page with our better data > reselem.setAttribute("tooltiptext", reselem.getAttribute("tooltiptext") + "\n\nupdated = " + result.details.toSource()); > UnPlug2SearchPage.result_e_set_description(reselem, result); > > // it can attach/detach from the parent element as needed > UnPlug2SearchPage.update_container(uid, reselem, old_result.details, result.description); > } else { > reselem.setAttribute("tooltiptext", reselem.getAttribute("tooltiptext") + "\n\nignored = " + result.details.toSource()); 142a192,205 > }, > > result_e_create : function () { > var orig = document.getElementById("unplug_result_template"); > var dupe = orig.cloneNode(true); > dupe.collapsed = false; > return dupe; > }, > > result_e_set_download : function (reselem, result) { > // variables for use in the callbaks (closures) > var uid = result.uid; > var download = result.download; > var that = UnPlug2SearchPage; 144,146c207,221 < // add this result < var new_result_index = UnPlug2SearchPage.results.length; < UnPlug2SearchPage.results[new_result_index] = result; --- > var getwidget = (function (wname) { > var l = reselem.getElementsByTagName("menuitem") > for (var i = 0; i < l.length; ++i) { > if (l[i].className && l[i].className.split(" ").indexOf(wname) >= 0) { > return l[i]; > } > } > var l = reselem.getElementsByTagName("toolbarbutton") > for (var i = 0; i < l.length; ++i) { > if (l[i].className && l[i].className.split(" ").indexOf(wname) >= 0) { > return l[i]; > } > } > return null; > }); 148,182c223,303 < try { < var reselem = document.createElement("unplug_result"); < < // add an id so we can edit this item later < reselem.setAttribute("id", "result_" + new_result_index); < reselem.setAttribute("reference", new_result_index); < < // change css classes in some circumstances < // TODO -- improve css styling code < if (result.details.swf) { < reselem.className = "swf"; < } < < // make draggable if simple url only < if (result.download.url) { < reselem.addEventListener("draggesture", function (e) { < nsDragAndDrop.startDrag(e, UnPlug2SearchPage.drag_and_drop_observer(result.download.url)); < }, false); < } < < var preferred_downloaders; < switch (UnPlug2.get_pref("downloader")) { < case "saveas": < preferred_downloaders = ["saveas"]; < break; < case "openover": < preferred_downloaders = ["openover"]; < break; < default: < preferred_downloaders = ["downthemall", "flashgot", "saveas"]; < break; < } < < // hide before and show after calling init < reselem.collapsed = true; --- > var buttons = ["copyurl", "saveas", "dta", "flashgot", "special", "opentab", "opennew", "openover", "config", "fallback"] > // what's available > var available_buttons = []; > for (var i = 0; i < buttons.length; ++i) { > var wname = buttons[i]; > if (that.widgets[wname].avail(result)) { > available_buttons.push(wname); > } > } > // what's best of those available (for main button action) > var best_downloader = null; > for (var i = 0; i < that.preferred_downloaders.length; ++i) { > var wname = that.preferred_downloaders[i]; > if (available_buttons.indexOf(wname) >= 0) { > best_downloader = wname; > break; > } > } > // hook up events and enable > for (var i = 0; i < available_buttons.length; ++i) { > var wname = available_buttons[i]; > var w = getwidget(wname); > // use closure to get correct scoping > var function_function = (function (that, uid, wname) { > return (function (evt) { > that.widgetresponse(uid, wname, wname == "config" ? "downloader" : null); > evt.stopPropagation(); > }); > }); > if (w) { > w.addEventListener("command", function_function(that, uid, wname), false); > w.setAttribute("disabled", false); > } > if (best_downloader == wname) { > // also hook up main button > var main = getwidget("big-download-button"); > main.addEventListener("command", function_function(that, uid, wname), false); > main.className = "big-download-button menuitem-iconic " + wname; > } > } > > // setup drag and drop > if (result.download.url) { // make draggable if simple url only > var image = reselem.getElementsByTagName("image")[0]; // ur-thumbnail > reselem.setAttribute("draggable", true); > reselem.addEventListener("dragstart", (function (url, image) { > return (function (event) { > event.dataTransfer.setData('text/uri-list', url); > event.dataTransfer.setData('text/plain', url); > event.dataTransfer.effectAllowed = "link"; > event.dataTransfer.setDragImage(image, 25, 25); > }); > })(result.download.url, image), true); > } > }, > > result_e_set_description : function (reselem, result) { > // variables for use in the callbaks (closures) > var uid = result.uid; > var details = result.details; > var that = UnPlug2SearchPage; > > var name_label = reselem.getElementsByTagName("label")[0]; > name_label.setAttribute("value", details.name); > var desc_label = reselem.getElementsByTagName("label")[1]; > desc_label.setAttribute("value", details.description); > var protocol_label = reselem.getElementsByTagName("label")[2]; > protocol_label.setAttribute("value", details.protocol); > var host_label = reselem.getElementsByTagName("label")[3]; > host_label.setAttribute("value", details.host); > var thumbnail = reselem.getElementsByTagName("image")[0]; > thumbnail.setAttribute("src", details.thumbnail); > > reselem.className = [ > "file-ext-" + (details.file_ext || "unknown"), > "certainty-" + (details.certainty < 0 ? "low" : "high"), > reselem.className].join(" ") > }, > > set_container : function (uid, reselem, details) { > if (!details.mediaid) { 184,187c305,349 < reselem.initResult(result, preferred_downloaders); < reselem.collapsed = false; < } catch(e) { < UnPlug2.log("ERROR displaying result " + e); --- > return; > } > > var minfo = this.media_id_lookup[details.mediaid]; > // escape used here because could have all sorts of special characters in mediaid > var eid = "mediaid_" + escape(details.mediaid || "none"); > var container = document.getElementById(eid); > if (! container) { > container = document.createElement("vbox"); > container.className = "container"; > container.id = eid; > document.getElementById("results").appendChild(container); > } > if (minfo === undefined) { > this.media_id_lookup[details.mediaid] = { > certainty : details.certainty, > quality : details.quality, > best : uid }; > reselem.className += " mediaid-best"; > container.appendChild(reselem); > } else { > if (minfo.certainty < details.certainty || (minfo.certainty == details.certainty && minfo.quality < details.quality)) { > var old_best = document.getElementById("result_" + minfo["best"]); > old_best.className = old_best.className.replace("mediaid-best", "mediaid-collapse"); > // this media info is the main one > this.media_id_lookup[details.mediaid] = { > certainty : details.certainty, > quality : details.quality, > best : uid }; > reselem.className += " mediaid-best"; > container.insertBefore(reselem, container.firstChild); > } else { > reselem.className += " mediaid-collapse"; > container.appendChild(reselem); > } > } > container.appendChild(reselem); > }, > > update_container : function (uid, reselem, old_details, new_details) { > if ((old_details.mediaid || "none") != (new_descripton.mediaid || "none")) { > // remove from current container > reselem.parentNode.removeChild(reselem); > // and add to the new one > UnPlug2SearchPage.set_container(uid, reselem, new_details); 377a540,548 > "special" : { > avail : function (res) { return res.download.url && ( > res.download.url.indexOf("rtmp://") == 0 > || res.download.url.indexOf("rtmpe://") == 0); > }, > exec : function (res, data) { > alert("Sorry, this feature is not available yet"); > } > }, 385c556,559 < avail : function (res) { return (res.download.url ? true : false); }, --- > avail : function (res) { return res.download.url && ( > res.download.url.indexOf("http://") == 0 > || res.download.url.indexOf("https://") == 0); > }, 416c590 < "downthemall" : { --- > "dta" : { 421,422c595,599 < if (res.download.url) { < return true; --- > if (!res.download.url) { > return false; > } > if (res.download.url.indexOf("http://") != 0 && res.download.url.indexOf("https://") != 0) { > return false; 424c601 < return false; --- > return true; 448c625,627 < return (res.download.url ? true : false); --- > return (res.download.url && ( > res.download.url.indexOf("http://") == 0 > || res.download.url.indexOf("https://") == 0)) 462c641 < alert("No default downloader is available"); --- > alert(UnPlug2.str("cannot_download_this_kind")); diff --new-file --recursive --suppress-common-lines --exclude changes.txt --exclude diff.txt releases/unplug-2.030/source/chrome/content/display/pop/pop.xul releases/unplug-2.031/source/chrome/content/display/pop/pop.xul 4d3 < 9a9,10 > > %dtdresult; 62,64d62 <