RRF checksum generator
HTML
<h2>
Generates RRF compatible checksums (and line number if needed)
</h2><div><code id="output">N1 M575 P1 S0*39</code><span class="icon-clipboard C2cb"></span></div>
<div><input id="input" type="text" value="M575 P1 S0"></div>
CSS
.icon-clipboard:after{
padding-left: 0.5em;
content:'\1f4cb';
}
JavaScript
line=1// IE 9+
$(function() {
var $input = $('#input');
var $output = $('#output');
$input.on('input', function(event) {
var value = $input.val();
cs = 0;
if (value.charAt(0) != "N") {
value = "N" + line + " " + value;
}
for (var i = 0; i < value.length; i++) {
cs = cs ^ value.charCodeAt(i);
}
cs = cs & 0xFF;
$output.text($input.val().length > 0 ? value + "*" + cs : "");
});
$input.on('focus', function(event) {
// var value = $input.val();
// if (value.charAt(0) != "N")
line++;
});
});
//https://jsfiddle.net/hszeto/yhngez3n/
;(function() {
$(function(){
'use strict';
$('body').click(function(event){
event.preventDefault();
// if element with "C2cb" was clicked
if ( $(event.target).hasClass('C2cb') ){
// Read value in data-copy2clipboard
var value = $('body').find('#output').text(); //event.target.dataset.copy2clipboard;
var range = document.createRange();
var success = true;
var selection;
// Create a temporary element off screen.
var tmpElem = $('<div>');
tmpElem.css({
position: "absolute",
left: "-10000px",
top: "-10000px"
});
// Add the input value to the temp element.
tmpElem.text( value );
$("body").append(tmpElem);
// Select temp element.
range.selectNodeContents( tmpElem.get(0) );
selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
// Copy begin
try {
success = document.execCommand('copy', false, null);
}
catch (e) {
alert("Copy failed");
}
if (success) {
// Build temp message
var tmp_msg = $('<button></button>');
tmp_msg.text('Copied');
tmp_msg.attr('id','temp_copied_msg');
...