Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove Minus and Plus Signs when cherrypicking Github Commits

Open up the web console while viewing the file(s) of a commit on Github and paste in this snippet:

var added_nodes = document.querySelectorAll(".blob-code.blob-code-addition .blob-code-inner");
var deleted_nodes = document.querySelectorAll(".blob-code.blob-code-deletion .blob-code-inner");
// var neutral_nodes = document.querySelectorAll(".blob-code.blob-code-context .blob-code-inner"); //don't think one is necessary
var str, new_str, pieces;

function removeNodes(nodes) {
  for(var i=0;  i < nodes.length;  i++) {
    str = nodes[i].innerHTML;
    
    pieces= str.split('');
    pieces[0] = ' ';

    nodes[i].innerHTML = pieces.join('');
  }
}

removeNodes(added_nodes);
removeNodes(deleted_nodes);
// removeNodes(neutral_nodes);

based from: https://gist.github.com/crookedneighbor/a12148b54315ca92124b

@vinay30

This comment has been minimized.

Copy link

commented Mar 21, 2018

Could you just do:

var added_nodes = document.querySelectorAll(".blob-code.blob-code-addition .blob-code-inner");
var deleted_nodes = document.querySelectorAll(".blob-code.blob-code-deletion .blob-code-inner");

function removeNodes(nodes) {
  for(var i = 0; i < nodes.length; i++) {
    nodes[i].innerHTML = nodes[i].innerHTML.replace('+', ' ');
  }
}

removeNodes(added_nodes);
removeNodes(deleted_nodes);

Since without the /g flag, replace will just swap out the first instance of +.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.