<commit_before>'use strict';

// Search for things that look like Bitcoin addresses
// Replace them with clickable links.
//var replaced = $("body").html().replace(/text/g,'replace');
//$("body").html(replaced);

/*
var btn = document.createElement("BUTTON")
var t = document.createTextNode("CLICK ME");
btn.appendChild(t);
//Appending to DOM 
document.body.appendChild(btn);
*/

/*
 * We don't use registerProtocolHandler() because we have to declare web accessible
 * resources, and that exposes to the web that the user is using that extension.
 * 
 * The following commit is just for documentation, it is not in our source.
 * https://github.com/sembrestels/darkwallet/commit/b99acd91#diff-4b1eb3dc4
 * 
 * Instead, we listen the click event on links that have bitcoin uris.
 */
document.body.addEventListener('click', function(e) {
  var elem = e.target;
  if (elem.tagName == 'A' && typeof elem.href == 'string' && elem.href.indexOf('bitcoin:') == 0) {
    window.open('chrome-extension://' + chrome.runtime.id + "/html/index.html#/send?uri=" + encodeURIComponent(elem.href));
    e.preventDefault();
  }
}, false);
<commit_msg>Managing better anchor clicks in content script.<commit_after>'use strict';

// Search for things that look like Bitcoin addresses
// Replace them with clickable links.
//var replaced = $("body").html().replace(/text/g,'replace');
//$("body").html(replaced);

/*
var btn = document.createElement("BUTTON")
var t = document.createTextNode("CLICK ME");
btn.appendChild(t);
//Appending to DOM 
document.body.appendChild(btn);
*/

/*
 * We don't use registerProtocolHandler() because we have to declare web accessible
 * resources, and that exposes to the web that the user is using that extension.
 * 
 * The following commit is just for documentation, it is not in our source.
 * https://github.com/sembrestels/darkwallet/commit/b99acd91#diff-4b1eb3dc4
 * 
 * Instead, we listen the click event on links that have bitcoin uris.
 */
var uri = 'chrome-extension://' + chrome.runtime.id + "/html/index.html#/send?uri=";
document.body.addEventListener('click', function(e) {
  var elem = e.target;
  while (elem && elem.tagName != 'A') {
    elem = elem.parentNode;
  }
  if (elem && elem.tagName == 'A' && typeof elem.href == 'string' && elem.href.indexOf('bitcoin:') == 0) {
    window.open(uri + encodeURIComponent(elem.href));
    e.preventDefault();
  }
}, false);

{'fraction_non_alphanumeric': 0.1530442035029191, 'fraction_numerical': 0.007506255212677231, 'mean_word_length': 4.2039045553145336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5082902', 'n_tokens_mistral': 736, 'n_tokens_neox': 723, 'n_words': 218}