Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@davestewart
Created January 16, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davestewart/74c26f7d86d1e11c68ea to your computer and use it in GitHub Desktop.
Save davestewart/74c26f7d86d1e11c68ea to your computer and use it in GitHub Desktop.
Sets Bitbucket, Github, Gist or (whatever you add) source code view indentation to something sensible
// ==UserScript==
// @name Source View Indentation Fix
// @namespace http://davestewart.io
// @version 1.0
// @description Sets Bitbucket, Github, Gist or (whatever you add) source code view indentation to something sensible
// @author Dave Stewart
// @grant none
// @match https://bitbucket.org/*
// @match https://gist.github.com
// @match https://gist.github.com/*
// @match https://github.com/*
// ==/UserScript==
// -----------------------------------------------------------------------------------------------------------
// user preferences
// tab sizes
var sizes =
{
// add / modify language extensions here...
default :4,
html :4,
js :4,
rb :2
};
// selectors
var selectors =
{
// add / modifiy selector templates here...
general:
[
'pre, pre *', // preformatted tags & content
'.code pre', // bitbucket
'.line' // gist
],
diffs:
[
'div[class*="{lang}-"] td', // github
'section[data-filename$=".{lang}"] pre.source' // bitbucket
],
files:
[
'div.{lang}-blob-data div.line', // gist
'td.{lang}-file-line', // github
'#editor-container[data-source-url$="{lang}"] pre' // bitbucket
]
};
// -----------------------------------------------------------------------------------------------------------
// code
// setup
function addStyle(selector, lang, size)
{
selector = selector.replace('{lang}', lang);
styles += selector + '{ tab-size: ' +size+ '; }\n';
}
var styles = '';
// build styles
// loop over types
for(var type in selectors)
{
// add heading
styles += '\n/* ' +type+ ' */\n\n';
// loop over rules
for(var i = 0; i < selectors[type].length; i++)
{
var selector = selectors[type][i];
// if no {lang} variable is found in the selector, just add the style once
if(selector.indexOf('{lang}') == -1)
{
addStyle(selector, null, sizes.default);
}
// otherwise, create a new rule for each language
else
{
for(var lang in sizes)
{
if(lang !== 'default')
{
addStyle(selector, lang, sizes[lang]);
}
}
}
}
}
// add styles to page
console.log('Code view indentation modified by Tampermonkey script "Source View Indentation Fix"');
$('head').append('<style>' +styles+ '</style>');
@vitaly-zdanevich
Copy link

Hm, not working for me :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment