TeaWeb/shared/js/utils/helpers.ts

31 lines
1.0 KiB
TypeScript
Raw Normal View History

import * as sha1 from "../crypto/sha";
import { tr } from "tc-shared/i18n/localize";
2020-03-30 11:44:18 +00:00
export function hashPassword(password: string) : Promise<string> {
return new Promise<string>((resolve, reject) => {
sha1.sha1(password).then(result => {
2020-03-30 11:44:18 +00:00
resolve(btoa(String.fromCharCode.apply(null, new Uint8Array(result))));
2018-04-16 18:38:35 +00:00
});
2020-03-30 11:44:18 +00:00
});
2018-09-30 19:50:59 +00:00
}
2020-03-30 11:44:18 +00:00
export const copy_to_clipboard = str => {
2019-05-25 15:54:26 +00:00
console.log(tr("Copy text to clipboard: %s"), str);
2018-09-30 19:50:59 +00:00
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected =
document.getSelection().rangeCount > 0
? document.getSelection().getRangeAt(0)
: false;
el.select();
document.execCommand('copy');
document.body.removeChild(el);
if (selected) {
document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
};