{"size": 992, "ext": "js", "max_stars_repo_path": "chrome-extension/js/replacements.js", "max_stars_repo_name": "lucaswadedavis/counterspell", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "chrome-extension/js/replacements.js", "max_issues_repo_name": "lucaswadedavis/counterspell", "max_issues_repo_issues_event_min_datetime": "2015-06-10T23:35:15.000Z", "max_issues_repo_issues_event_max_datetime": "2015-06-11T03:36:28.000Z", "max_forks_repo_path": "chrome-extension/js/replacements.js", "max_forks_repo_name": "lucaswadedavis/cssymbiont", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 10, "max_forks_count": null, "avg_line_length": 20.6666666667, "max_line_length": 73, "alphanum_fraction": 0.6481854839}
chrome.storage.sync.get(null,function(obj){
  if (!obj.replacements){
    obj.replacements = [];
    chrome.storage.sync.set(obj,function(){});
  }
  console.log(obj.replacements);
  walk(document.body,obj.replacements);
});


function walk(node,replacements){
	// I stole the recursive dom walker function from here:
	// http://is.gd/mwZp7E

	var child, next;

	switch ( node.nodeType )  
	{
		case 1:  // Element
		case 9:  // Document
		case 11: // Document fragment
			child = node.firstChild;
			while ( child ) 
			{
				next = child.nextSibling;
				walk(child,replacements);
				child = next;
			}
			break;

		case 3: // Text node
			//handleText(node);
      counterspell(node,replacements);
			break;
	}
};

function counterspell(textNode, replacements){
  var d = textNode.nodeValue;
  for (var i in replacements){
    var pattern = new RegExp(("\\b"+replacements[i].original+"\\b"),"g");
    d = d.replace(pattern,replacements[i].replacement);
  }

  textNode.nodeValue = d;
};

