39 lines
837 B
JavaScript
39 lines
837 B
JavaScript
function arrayToHex(iv) {
|
|
let hexStr = '';
|
|
for (const i in iv) {
|
|
if (iv[i] < 16) {
|
|
hexStr += '0' + iv[i].toString(16);
|
|
} else {
|
|
hexStr += iv[i].toString(16);
|
|
}
|
|
}
|
|
window.hexStr = hexStr;
|
|
return hexStr;
|
|
}
|
|
|
|
function hexToArray(str) {
|
|
const iv = new Uint8Array(str.length / 2);
|
|
for (let i = 0; i < str.length; i += 2) {
|
|
iv[i / 2] = parseInt(str.charAt(i) + str.charAt(i + 1), 16);
|
|
}
|
|
|
|
return iv;
|
|
}
|
|
|
|
function notify(str) {
|
|
if (!('Notification' in window)) {
|
|
return;
|
|
} else if (Notification.permission === 'granted') {
|
|
new Notification(str);
|
|
} else if (Notification.permission !== 'denied') {
|
|
Notification.requestPermission(function(permission) {
|
|
if (permission === 'granted') new Notification(str);
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
arrayToHex,
|
|
hexToArray,
|
|
notify
|
|
};
|