Skip to content

Instantly share code, notes, and snippets.

@jimmystridh
Created March 19, 2014 14:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmystridh/9642320 to your computer and use it in GitHub Desktop.
Save jimmystridh/9642320 to your computer and use it in GitHub Desktop.
UserScript to fetch the embed link from a Dropbox share link, and embed in youtrack
// ==UserScript==
// @name YouTrack Dropbox Embed
// @namespace http://visit.com/
// @version 0.1
// @description inserts an image from a dropbox url
// @match https://youtrack.internal.visit.com/*
// @copyright 2012+, Jimmy
// ==/UserScript==
(function(){
document.addEventListener('keydown', function(e) {
// pressed alt+g
if (e.keyCode == 71 && e.shiftKey && !e.ctrlKey && e.altKey && !e.metaKey) {
var url = prompt("Dropbox url?","");
if (url != null)
{
GM_xmlhttpRequest({ // that would be "func1"
"method" : "GET",
"url" : url, // first url in the list
"onload" : function(xhr)
{
var oPage = xhr.responseText; // page contents
console.log(oPage);
var link = /<a href="(https:\/\/dl.dropboxusercontent.*?)" id="download_button_link"/.exec(oPage)[1];
var textarea = document.querySelector("textarea[name*=description]");
textarea.innerHTML += "\n{html}<img src=\"" + link + "\" width=\"100%\" />{html}";
}
});
}
}
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment