JS Source Code of the MAC-Addesss Notation Changer
function fnClipboard(macAdrCpy) {
document.getElementById('macinput').value = macAdrCpy;
var copyText = document.getElementById('macinput');
copyText.select();
document.execCommand('copy');
};
function pasteFromClipboard() {
document.getElementById('macinput').value = '';
var pasteText = document.getElementById('macinput');
pasteText.focus();
document.execCommand('paste');
};
function macConvert(macNotationType) {
var lmtr = ['x', '-', ':', '.', '-'];
var block = [12, 2, 2, 4, 6];
var macAdrAll = [];
var len = lmtr.length;
var i;
var cntr;
var macAdrOut = '';
var macAdr = document.getElementById('macinput').value;
var macAdrStrp = macAdr.toLowerCase();
macAdrStrp = macAdrStrp.replace(/[^A-Fa-f0-9]/g, '');
if (macAdrStrp.length !== 12) {
document.getElementById("macinput").style.backgroundColor = "#f0a0a0";
} else {
document.getElementById("macinput").style.backgroundColor = "#f5f5f5";
for (cntr=0; cntr<len; ++cntr) {
for (i=0; i < 12; i = i + block[cntr]) {
macAdrOut = macAdrOut + macAdrStrp.substr(i, block[cntr]) + lmtr[cntr];
}
macAdrOut = macAdrOut.substr(0, macAdrOut.length-1);
macAdrAll[cntr] = macAdrOut;
macAdrOut = '';
}
macAdrCpy = macAdrAll[macNotationType];
fnClipboard(macAdrCpy);
window.close();
}
};
document.addEventListener('DOMContentLoaded', function() {
var jsEventgoButton = document.getElementById('gobutton');
jsEventgoButton.addEventListener('click', function() {
pasteFromClipboard();
macConvert(0);
});
var jsEventgoButton = document.getElementById('gobutton1');
jsEventgoButton.addEventListener('click', function() {
pasteFromClipboard();
macConvert(1);
});
var jsEventgoButton = document.getElementById('gobutton2');
jsEventgoButton.addEventListener('click', function() {
pasteFromClipboard();
macConvert(2);
});
var jsEventgoButton = document.getElementById('gobutton3');
jsEventgoButton.addEventListener('click', function() {
pasteFromClipboard();
macConvert(3);
});
var jsEventgoButton = document.getElementById('gobutton4');
jsEventgoButton.addEventListener('click', function() {
pasteFromClipboard();
macConvert(4);
});
});
Comments
Post a Comment