Skip to content

Instantly share code, notes, and snippets.

@bwinton
Forked from rtanglao/flagDuplicate.js
Created February 3, 2010 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwinton/293329 to your computer and use it in GitHub Desktop.
Save bwinton/293329 to your computer and use it in GitHub Desktop.
// Code written by Bryan Clark - merely pasted into a gist by Roland Tanglao
// Licenced under the Mozilla Public License, http://www.mozilla.org/MPL/MPL-1.1.html
// This code which is a JetPack for Mozilla Firefox doesn't work! It's prototype and proof of concept only
// See spec at https://wiki.mozilla.org/Thunderbird/Support/GetSatisfaction/Accelerator
var TOPICS = [];
var url = "http://www.getsatisfaction.com/mozilla_messaging/topics.rss"
$.get( url, function(xml){
var items = $(xml).find("item");
items.each(function() {
var label = $(this).find("title")[0].textContent;
var value = $(this).find("link")[0].textContent;
if (label && value) {
TOPICS.push({ "value" : value, "label" : label });
}
});
});
function injectJQUI(doc) {
if ($("#jquery_script", doc).length <= 0) {
var s = doc.createElement("script");
s.type = "text/javascript";
s.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js";
s.id = "jquery_script";
doc.body.appendChild(s);
}
if ($("#jquery_ui_script", doc).length <= 0) {
var s = doc.createElement("script");
s.type = "text/javascript";
s.src = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js";
s.id = "jquery_ui_script";
doc.body.appendChild(s);
}
if ($("#jquery_auto_script", doc).length <= 0) {
var s = doc.createElement("script");
s.type = "text/javascript";
s.src = "http://jquery-ui.googlecode.com/svn/trunk/ui/jquery.ui.autocomplete.js";
s.id = "jquery_auto_script";
doc.body.appendChild(s);
}
if ($("#jquery_nc_script", doc).length <= 0) {
var s = doc.createElement("script");
s.type = "text/javascript";
s.textContent = "$.noConflict();";
s.id = "jquery_nc_script";
doc.body.appendChild(s);
}
}
jetpack.tabs.onFocus(function() {
if (isMoMoGSFN(this.url)) {
injectJQUI(this.contentDocument);
appendDuplicateAction(this.contentDocument);
}
});
jetpack.tabs.onReady(function() {
if (isMoMoGSFN(this.url)) {
injectJQUI(this.contentDocument);
appendDuplicateAction(this.contentDocument);
}
});
function isMoMoGSFN(url) {
return url.match(/http[s]?:\/\/[www\.]*getsatisfaction\.com\/mozilla_messaging\//);
}
function appendDuplicateAction(doc) {
if ($("#make_duplicate_action", doc).length <= 0) {
var dupe_input = $("<input id='duplicate_input'/>", doc);
var dupe = $("<li id='make_duplicate_action'><strong>Search Duplicates</strong></li>", doc).append(dupe_input);
/*
$(dupe).click(function() {
$("#reply_content", doc).text("This is a duplicate of blah blah");
//GSFN tries to do something tricky that doesn't like this .focus() method
// so we have to trap the error
try { $("#reply_content", doc).focus(); } catch(ignore) {}
return false;
});
*/
$("#employee_tools_sidebar .topic_moderator_actions", doc).append(dupe);
// $("#duplicate_input").autocomplete( { data : TOPICS });
if ($("#jquery_topics_script", doc).length <= 0) {
var s = doc.createElement("script");
s.type = "text/javascript";
s.textContent = 'jQuery("#duplicate_input").autocomplete( { minLength: 0, source : '+TOPICS.toSource()+' } );';
s.id = "jquery_topics_script";
doc.body.appendChild(s);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment