<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap" rel="stylesheet">
<style>
body {
  background-color: #EFEFEF;
    font-family: 'Source Code Pro', monospace;
    font-weight: 400;
    color:#333;
}
#top {

display: block;
 position: fixed;
 margin-top: 0px;
 margin-right: 0px;
  margin-left: 0px;
 padding: 5px;
 top: 0px;
 left: 0px;
 width: 100%;
 height: 90px;
    color: #fff;
    background-color: #6F6F6F;
    border:2px solid #6F6F6F;
    }
#context {
margin-top:120px;
line-height:1.2em;
    background-color: #f9f9f9;
    padding: 0px;
    padding-top: 10px;
    padding-left: 10px;
    border:1px solid #6F6F6F;
    color:#000;
    border-radius: 20px;
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;
}
a {
    color: #F2F2F2;
    word-wrap: break-word;
    text-decoration: none;

    -webkit-transition: color 0.1s ease-in, background 0.1s ease-in;
    -moz-transition: color 0.1s ease-in, background 0.1s ease-in;
    -ms-transition: color 0.1s ease-in, background 0.1s ease-in;
    -o-transition: color 0.1s ease-in, background 0.1s ease-in;
    transition: color 0.1s ease-in, background 0.1s ease-in;
}

a:hover,
a:focus {
    color: #C2C2C2;
    text-decoration: none;
    outline: 0;
}

a:before,
a:after {
    -webkit-transition: color 0.1s ease-in, background 0.1s ease-in;
    -moz-transition: color 0.1s ease-in, background 0.1s ease-in;
    -ms-transition: color 0.1s ease-in, background 0.1s ease-in;
    -o-transition: color 0.1s ease-in, background 0.1s ease-in;
    transition: color 0.1s ease-in, background 0.1s ease-in;
}
</style>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>

<script type="text/javascript" src="https://rawgit.com/julmot/mark.js/master/dist/jquery.mark.js"></script>

<style id="compiled-css" type="text/css">
mark { text-decoration: underline dotted 3px  rgb(244, 208, 63); background: rgba(244, 208, 63 ,0.1);; cursor: pointer; text-underline-offset:3px;}
mark.show-title:after {
    content:'title';
    padding:5px;
    border:1px solid #ccc;
    top:5px;
    right:10%;
    background: #bada55;
}
mark.typographical { text-decoration: underline dotted 3px rgb( 120, 66, 18 ); background: rgba( 120, 66, 18 ,0.1);}
mark.misspelling { text-decoration: underline dotted 3px  rgb(231, 76, 60) ;background:  rgba(231, 76, 60,0.1) ;}
mark.duplication { text-decoration: underline dotted 3px rgb(243, 156, 18);background: rgba(243, 156, 18,0.1);}
mark.grammar { text-decoration: underline dotted 3px rgb(34, 153, 84);background: rgba(34, 153, 84,0.1);}
mark.style { text-decoration: underline dotted 3px rgb(52, 152, 219);background: rgba(52, 152, 219,0.1);}
mark.inconsistency { text-decoration: underline dotted 3px rgb(155, 89, 182); background: rgba(155, 89, 182,0.1);}
</style>

</head>
<body>

<div id="top">
<div>Check by <a href="https://languagetool.org">languagetool.org</a> (#LANG#) : <span id="msg">in progress</span></div>
<hr>
<div id="log" >&nbsp;</div>
</div>

<div id="context" >
#CONTENT#
</div>
<script type="text/javascript">


var $context = $('#context'),
	results = [],
  ranges = [];

$.ajax({
  url: "https://languagetool.org/api/v2/check",
  type: "POST",
  data: {
    language: "#LANG#",
    disableRules: "WHITESPACE_RULE",
    allowIncompleteResults: true,
    text: $context.text()
  },
  success: function(data) {
  $( "#msg" ).html('done');
    $.each(data.matches, function(key, value) {
      results.push(value);
      ranges.push({ start: value.offset, length: value.length });
    });
    $context.markRanges(ranges, {
      debug: true,
      each: function(node, range) {
        var start = range.start,
          found = results.find(function(el) {
            return el.offset === start;
          }) || null;
        if (found) {
          node.classList.add(found.rule.issueType);
          node.setAttribute('title', found.rule.issueType + ': ' + found.rule.description);
          node.onclick =function(){ $( "#log" ).html('"'+ node.textContent+'" -> '+node.getAttribute('title'))};
        }
      }
    });
  }
});



</script>
</body>
</html>

