<commit_before>/* eslint-disable no-undef, jsx-a11y/no-static-element-interactions */
import { isCordova } from 'worona-deps';
import React from 'react';
import { connect } from 'react-redux';
import urllite from 'urllite';
import * as deps from '../../deps';

class CaptureLinks extends React.Component {
  constructor() {
    super();
    this.onClick = this.onClick.bind(this);
  }

  onClick(e) {
    // Get the <a> element.
    let el = e.target;
    while (el && el.nodeName !== 'A') {
      el = el.parentNode;
    }

    // Ignore clicks from non-a elements.
    if (!el) {
      return;
    }

    // Use a regular expression to parse URLs instead of relying on the browser
    // to do it for us (because IE).
    const linkUrl = urllite(el.href);
    const siteUrl = urllite(this.props.siteUrl);

    // Remove blur.
    el.blur();

    if (!isCordova) {
      // If we are not inside Cordova, do nothing in these cases:

      // Ignore canceled events, modified clicks, and right clicks.
      if (e.defaultPrevented) {
        return;
      }

      if (e.metaKey || e.ctrlKey || e.shiftKey) {
        return;
      }

      if (e.button !== 0) {
        return;
      }

      // Ignore the click if the element has a target.<commit_msg>Avoid CaptureLinks with file protocols.<commit_after>/* eslint-disable no-undef, jsx-a11y/no-static-element-interactions */
import { isCordova } from 'worona-deps';
import React from 'react';
import { connect } from 'react-redux';
import urllite from 'urllite';
import * as deps from '../../deps';

class CaptureLinks extends React.Component {
  constructor() {
    super();
    this.onClick = this.onClick.bind(this);
  }

  onClick(e) {
    // Get the <a> element.
    let el = e.target;
    while (el && el.nodeName !== 'A') {
      el = el.parentNode;
    }

    // Ignore clicks from non-a elements.
    if (!el) {
      return;
    }

    // Use a regular expression to parse URLs instead of relying on the browser
    // to do it for us (because IE).
    const linkUrl = urllite(el.href);
    const siteUrl = urllite(this.props.siteUrl);

    if (linkUrl.protocol === 'file:') {
      return;
    }

    // Remove blur.
    el.blur();

    if (!isCordova) {
      // If we are not inside Cordova, do nothing in these cases:

      // Ignore canceled events, modified clicks, and right clicks.
      if (e.defaultPrevented) {
        return;
      }

      if (e.metaKey || e.ctrlKey || e.shiftKey) {
        return;
      }

      if (e.button !== 0) {
        return;
      }

      // Ignore the click if the element has a target.
{'fraction_non_alphanumeric': 0.13083751447317638, 'fraction_numerical': 0.0023157082207641835, 'mean_word_length': 2.203955500618047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '3002731', 'n_tokens_mistral': 862, 'n_tokens_neox': 829, 'n_words': 259}