Raw Source
Runy69 / Bitbucket Single File Download

// ==UserScript==
// @name			Bitbucket Single File Download
// @version			1.2
// @author			Runy69
// @description		Download button for all files in Bitbucket Sourcebrwoser
// @match			*bitbucket.org/*/src*
// @require			https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @updateURL		https://googledrive.com/host/0B8c6DgXq6gcGMVBBUTdqbVlrWGc/BBDownload.meta.js
// @downloadURL		https://googledrive.com/host/0B8c6DgXq6gcGMVBBUTdqbVlrWGc/BBDownload.user.js
// ==/UserScript==

function addDownloadLinks() {
    var repo = $('a.entity-name').attr('href');
    var url;
    for(var i = 0; i < $('td.filename').length; i++){
        url = $('td.filename div a').eq(i).attr('href').replace(repo+"/src/", repo+"/raw/");
        $('td.filename div').css({"display":"inline-block"});
        $('td.filename').eq(i).append('<a href="'+url+'" target="_blank"><div style="float: right;"><span class="aui-icon aui-icon-small icon-downloads" style="margin-right: 5px;"></span>Download</div></a>');
    }
}

function mutationHandler(mutationRecords) {
    addDownloadLinks();
}

$(document).ready(function() {
    var obsConfig = { childList: true, characterData: true};
    var observer = new MutationObserver(mutationHandler);
    observer.observe(document.getElementById('source-container'), obsConfig);
    addDownloadLinks();
});