Bitbucket Whitespaces

Show hidden symbols (spaces, tabs)

  1. // ==UserScript==
  2. // @name Bitbucket Whitespaces
  3. // @namespace https://bitbucket.org/
  4. // @description Show hidden symbols (spaces, tabs)
  5. // @match https://bitbucket.org/*
  6. // @version 0.2
  7. // ==/UserScript==
  8.  
  9. // a function that loads jQuery and calls a callback function when jQuery has finished loading
  10. function addJQuery(callback) {
  11. var script = document.createElement('script');
  12. script.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
  13. script.addEventListener('load', function() {
  14. var script = document.createElement('script');
  15. script.textContent = 'window.jQ=jQuery.noConflict(true);(' + callback.toString() + ')();';
  16. document.body.appendChild(script);
  17. }, false);
  18. document.body.appendChild(script);
  19. }
  20.  
  21. // the guts of this userscript
  22. function main() {
  23. // jQ replaces $ to avoid conflicts.
  24. jQ('.udiff-line .source').each(function() {
  25. jQ(this).html(
  26. jQ(this).html()
  27. .replace(
  28. /^([ \+\-].*?)\s+$/,
  29. '$1<span style="color: red">[trailing whitespaces]</span>'
  30. )
  31. .replace(
  32. /\t/g,
  33. '<span style="color: red">» </span>'
  34. )
  35. );
  36. });
  37. }
  38.  
  39. // load jQuery and execute the main function
  40. addJQuery(main);