Skip to content

Instantly share code, notes, and snippets.

@MitMaro
Last active January 24, 2017 20:07
Show Gist options
  • Save MitMaro/3aa0899f2f95276fa38367006e231433 to your computer and use it in GitHub Desktop.
Save MitMaro/3aa0899f2f95276fa38367006e231433 to your computer and use it in GitHub Desktop.
Custom styles for BitBucket and Tampermonkey
// ==UserScript==
// @name BitBucket Style Updates
// @namespace http://mitmaro.ca
// @version 1.0.0
// @description Converts the diff tab size on BB
// @author Tim Oram
// @match https://bitbucket.org/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
var sheet = document.createElement('style');
sheet.innerHTML = `
pre.source {
tab-size: 4 !important;
}
#announcement {
display: none;
}
`;
document.body.appendChild(sheet);
const pr = document.querySelector(`#pr-tab-content`);
if (!pr) {
return;
}
const handler = debounce((mutations, obs) => {
console.log(new Date());
const items = document.querySelectorAll('pre.source');
const values = [].map.call(items, (el) => el.innerText);
let i = 0;
items.forEach((el) => el.innerHTML = values[++i]);
console.log(new Date());
}, 1000);
const observer = new MutationObserver(handler);
observer.observe(pr, {
attributes: false,
characterData: false,
childList: true,
subtree: true,
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment