From 84e58f97862fd685e43cf0cc99c69a2fdb384119 Mon Sep 17 00:00:00 2001 From: Francois Lebel Date: Wed, 14 Oct 2015 23:07:23 -0700 Subject: [PATCH 1/5] Added support for UserVoice tickets. --- README.md | 1 + trello_bookmarklet.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index efbbf4e..3feefe2 100755 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ This is a bookmarklet you - FogBugz cases - JIRA issues - GitHub issues and commits + - UserVoice tickets - The selected text from an arbitrary URL - ... more? I'm happy to take pull requests that add support for other websites! diff --git a/trello_bookmarklet.js b/trello_bookmarklet.js index ed06162..2c79f37 100755 --- a/trello_bookmarklet.js +++ b/trello_bookmarklet.js @@ -58,6 +58,15 @@ // we're looking at an email in Gmail name = $('h1 .hP').text().trim(); + } else if ($('body[uv-sheet-container]').length) { + + // We're looking at UserVoice tickets + var ticket_number_regex = /.*\/admin\/tickets\/(\d+)\/.*/; + var ticket_number = ticket_number_regex.exec(location.href); + name = "[DoC #" + ticket_number[1] + "] " + $('h1.ticket-subject-header').text().trim(); + desc = "Link to Ticket: " + location.href; + desc += "\nReported by: " + window.currentSupportAgent.displayName; + } else { From 82d02e345b60038426f5691d7065e7627271c1be Mon Sep 17 00:00:00 2001 From: Francois Lebel Date: Thu, 15 Oct 2015 11:03:19 -0700 Subject: [PATCH 2/5] Removed optional slash after the ticket number. --- trello_bookmarklet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trello_bookmarklet.js b/trello_bookmarklet.js index 2c79f37..920d4ce 100755 --- a/trello_bookmarklet.js +++ b/trello_bookmarklet.js @@ -61,7 +61,7 @@ } else if ($('body[uv-sheet-container]').length) { // We're looking at UserVoice tickets - var ticket_number_regex = /.*\/admin\/tickets\/(\d+)\/.*/; + var ticket_number_regex = /.*\/admin\/tickets\/(\d+).*/; var ticket_number = ticket_number_regex.exec(location.href); name = "[DoC #" + ticket_number[1] + "] " + $('h1.ticket-subject-header').text().trim(); desc = "Link to Ticket: " + location.href; From 4be80551a4fbcd054afbfeb69868d0a60a58789a Mon Sep 17 00:00:00 2001 From: Francois Lebel Date: Thu, 15 Oct 2015 15:14:53 -0700 Subject: [PATCH 3/5] Use latest jQuery 2.x on pages using <= 1.x. --- trello_bookmarklet.js | 73 +++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/trello_bookmarklet.js b/trello_bookmarklet.js index 920d4ce..ad97530 100755 --- a/trello_bookmarklet.js +++ b/trello_bookmarklet.js @@ -1,5 +1,10 @@ (function(window){ var $; + var jQuery_page + var jQuery_trello_bookmarklet; + + // Keep track of the jQuery included in the page + $ = window.$ = jQuery_page = window.jQuery; var get_est_jira_time = function() { var jira_time = $('#tt_single_values_orig').text().trim(); @@ -110,33 +115,37 @@ // Create the card if(name) { - Trello.post("lists/" + idList + "/cards", { - name: name, - desc: desc - }, function(card){ - // Display a little notification in the upper-left corner with a link to the card - // that was just created - var $cardLink = $("") - .attr({ - href: card.url, - target: "card" - }) - .text("Created a Trello Card") - .css({ - position: "absolute", - left: 0, - top: 0, - padding: "4px", - border: "1px solid #000", - background: "#fff", - "z-index": 1e3 - }) - .appendTo("body") + // Use newer (2.x) jQuery version to avoid CORS errors + (function(jQuery) { + Trello.post("lists/" + idList + "/cards", { + name: name, + desc: desc + }, function(card){ + // Display a little notification in the upper-left corner with a link to the card + // that was just created + var $cardLink = $("") + .attr({ + href: card.url, + target: "card" + }) + .text("Created a Trello Card") + .css({ + position: "absolute", + left: 0, + top: 0, + padding: "4px", + border: "1px solid #000", + background: "#fff", + "z-index": 1e3 + }) + .appendTo("body") - setTimeout(function(){ - $cardLink.fadeOut(3000); - }, 5000) - }) + setTimeout(function(){ + $cardLink.fadeOut(3000); + }, 5000) + }) + $ = window.$ = window.jQuery = jQuery_page; + }(jQuery_trello_bookmarklet)) } } @@ -241,19 +250,21 @@ waterfall([ // Load jQuery function(next) { - if(window.jQuery) { + if (parseInt(window.jQuery.fn.jquery.split(".")[0]) >= 2) { + jQuery_trello_bookmarklet = $; next(null); } else { var script = document.createElement("script"); - script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"; script.onload = next; + script.onreadystatechange = next; + script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"; document.getElementsByTagName("head")[0].appendChild(script); + + jQuery_trello_bookmarklet = jQuery.noConflict(true); } }, // Get the user's App Key, either from local storage, or by prompting them to retrieve it function(ev, next) { - $ = window.jQuery; - var appKey = store(appKeyName) || window[appKeyName]; if(appKey && appKey.length == 32) { next(appKey); @@ -323,4 +334,6 @@ // Run the user portion run ]); + // Reset jQuery to the version included in the page + $ = window.$ = window.jQuery = jQuery_page; })(window); From 43fd24cf546d89bbf0d6dc0361bdd6f94be6c44d Mon Sep 17 00:00:00 2001 From: Francois Lebel Date: Wed, 28 Oct 2015 08:12:30 -0700 Subject: [PATCH 4/5] Nitpick. --- trello_bookmarklet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trello_bookmarklet.js b/trello_bookmarklet.js index ad97530..dfe0196 100755 --- a/trello_bookmarklet.js +++ b/trello_bookmarklet.js @@ -1,6 +1,6 @@ (function(window){ var $; - var jQuery_page + var jQuery_page; var jQuery_trello_bookmarklet; // Keep track of the jQuery included in the page From 3978cd5d94dd50e88c9fbee7c3a3da8be31d9be1 Mon Sep 17 00:00:00 2001 From: Francois Lebel Date: Wed, 28 Oct 2015 09:25:10 -0700 Subject: [PATCH 5/5] Removed customized card name. --- trello_bookmarklet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trello_bookmarklet.js b/trello_bookmarklet.js index dfe0196..641443f 100755 --- a/trello_bookmarklet.js +++ b/trello_bookmarklet.js @@ -68,7 +68,7 @@ // We're looking at UserVoice tickets var ticket_number_regex = /.*\/admin\/tickets\/(\d+).*/; var ticket_number = ticket_number_regex.exec(location.href); - name = "[DoC #" + ticket_number[1] + "] " + $('h1.ticket-subject-header').text().trim(); + name = "#" + ticket_number[1] + " " + $('h1.ticket-subject-header').text().trim(); desc = "Link to Ticket: " + location.href; desc += "\nReported by: " + window.currentSupportAgent.displayName;