Skip to content

Instantly share code, notes, and snippets.

@linyows
Last active December 16, 2015 07:59
Show Gist options
  • Save linyows/5402953 to your computer and use it in GitHub Desktop.
Save linyows/5402953 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name github-build-badge
// @author linyows
// @namespace http://linyows.com/
// @description "Expand build status badge"
// @include https://github.com/*
// ==/UserScript==
(function() {
var match_witch_badge = /<a href="(http:\/\/ci[0-9]{0,3}\..*\.[a-z]{2,5}\/job\/.*)"><img src=".*" alt="Build Status" data-canonical-src=".*" style=".*"><\/a>/g;
var replace_format = '<a href="%source" target="_blank" class="jenkins-build-status"><img src="%source/badge/icon" /></a>';
var timer_id = null;
var emit_button_classes = [];
emit_button_classes.push('preview-tab'); // github preview
function expandBadge() {
if (timer_id !== null) {
return;
}
timer_id = setTimeout(function(){
var classes = [];
classes.push('markdown-body');
for (var i in classes) {
var element = document.getElementsByClassName(classes[i]);
Array.prototype.slice.call(element, 0).forEach(function(div){
div.innerHTML = div.innerHTML.replace(match_witch_badge, function(a, image_url){
return replace_format.replace(/%source/g, image_url);
});
});
}
timer_id = null;
}, 1500);
}
// 画像展開を実行するイベントを登録
for (var i = 0; i < emit_button_classes.length; ++i) {
var buttons = document.getElementsByClassName(emit_button_classes[i]);
Array.prototype.slice.call(buttons, 0).forEach(function(button) {
button.addEventListener('click', expandBadge);
});
}
expandBadge();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment