<commit_before>/**
 * Prepare hypothes.is URL to request API.
 */
function hypothesis_api_url(url, type) {
  if (!/^https?:\/\//i.test(url)) {
    url = 'http://' + url;
  }
  if (type === 'domain') {
    const url_obj = new URL(url);
    const query = 'uri.parts=' + url_obj.host.split('.').join('&uri.parts=')
    return 'https://hypothes.is/api/search?' + query;
  } else if (type === 'url') {
    return 'https://hypothes.is/api/search?uri=' + url;
  }
}

/**
 * Get hypothes.is data and render results.
 */
function get_annotations(type='url') {
  const url = getUrlByParameter('url');
  const new_url = hypothesis_api_url(url, type);
  $.getJSON(new_url, function(data) {
    const length = data.rows.length;
    if (length > 0) {
      for(let i=0; i<length; i++) {
        const rowData = data.rows[i];
        const date = rowData.created.substring(0,10);
        const source = rowData.target[0].source;
        const exactData = rowData.text;
        const user = rowData.user.substring(5, rowData.user.indexOf('@'));
        let title = '';
        if(rowData.document.title) {
          title = rowData.document.title[0];
        }
        let row = $('#row_contain-' + type);
        let item = row.clone();
        item.attr('id', 'row-' + i);
        item.find('.date').html('Dated on ' + date);
        item.find('.userinfo').html(user);
        item.find('#source-contain').html('(' + source + ')');
        item.find('#text-contain').html(exactData);
        item.find('.title').html(title);
        item.find('.links').append(
          $('<a>').attr({'href': rowData.links.incontext, 'id': 'link-incontext'})
                  .html('Click to see in context'),
          $('<a>').attr({'href': rowData.links.html, 'id': 'link-html'})
                  .html('Click to see the HTML')
        )
        if(rowData.target[0].hasOwnProperty('selector')){
          var selector_length = rowData.target[0].selector.length;
          var exact = rowData.target[0].selector[selector_length-1].exact;
          item.find('.target-selector-exact').html(exact);
        } else {
          item.find('.target-selector-exact').hide();
        }
        $('#container-whole-' + type).append(item);
      }
    } else {
      let error_msg;
      if (type === 'domain') {
        error_msg = 'There are no annotations for the current domain.';<commit_msg>open annotations URLs in a new tab<commit_after>/**
 * Prepare hypothes.is URL to request API.
 */
function hypothesis_api_url(url, type) {
  if (!/^https?:\/\//i.test(url)) {
    url = 'http://' + url;
  }
  if (type === 'domain') {
    const url_obj = new URL(url);
    const query = 'uri.parts=' + url_obj.host.split('.').join('&uri.parts=')
    return 'https://hypothes.is/api/search?' + query;
  } else if (type === 'url') {
    return 'https://hypothes.is/api/search?uri=' + url;
  }
}

/**
 * Get hypothes.is data and render results.
 */
function get_annotations(type='url') {
  const url = getUrlByParameter('url');
  const new_url = hypothesis_api_url(url, type);
  $.getJSON(new_url, function(data) {
    const length = data.rows.length;
    if (length > 0) {
      for(let i=0; i<length; i++) {
        const rowData = data.rows[i];
        const date = rowData.created.substring(0,10);
        const source = rowData.target[0].source;
        const exactData = rowData.text;
        const user = rowData.user.substring(5, rowData.user.indexOf('@'));
        let title = '';
        if(rowData.document.title) {
          title = rowData.document.title[0];
        }
        let row = $('#row_contain-' + type);
        let item = row.clone();
        item.attr('id', 'row-' + i);
        item.find('.date').html('Dated on ' + date);
        item.find('.userinfo').html(user);
        item.find('#source-contain').html('(' + source + ')');
        item.find('#text-contain').html(exactData);
        item.find('.title').html(title);
        item.find('.links').append(
          $('<a>').attr({'href': rowData.links.incontext, 'id': 'link-incontext','target':'_blank'})
                  .html('Click to see in context'),
          $('<a>').attr({'href': rowData.links.html, 'id': 'link-html','target':'_blank'})
                  .html('Click to see the HTML')
        )
        if(rowData.target[0].hasOwnProperty('selector')){
          var selector_length = rowData.target[0].selector.length;
          var exact = rowData.target[0].selector[selector_length-1].exact;
          item.find('.target-selector-exact').html(exact);
        } else {
          item.find('.target-selector-exact').hide();
        }
        $('#container-whole-' + type).append(item);
      }
    } else {
      let error_msg;
      if (type === 'domain') {
        error_msg = 'There are no annotations for the current domain.';
{'fraction_non_alphanumeric': 0.1903367496339678, 'fraction_numerical': 0.005019870320016733, 'mean_word_length': 2.4930606281957632, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, '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': '5964567', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1517, 'n_words': 301}