-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontent.ts
More file actions
78 lines (63 loc) · 2.68 KB
/
content.ts
File metadata and controls
78 lines (63 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import type { PlasmoCSConfig } from "plasmo"
import {getDecodedMessage} from "~decoder";
console.log(document.querySelector('input[type="password"]'))
const passwordFields = document.querySelectorAll('input[type="password"]')
// insert a style tag at the end of the head
const style = document.createElement('style');
style.innerText = '.plain-sight-active{background: #3b82f6;} .plain-sight-active::placeholder{color: white; font-weight: bold;}'
document.head.appendChild(style);
passwordFields.forEach(dropTarget => {
dropTarget.addEventListener("drop", onDropEnd);
dropTarget.addEventListener("dragenter", onDrop);
dropTarget.addEventListener("dragover", onDrop);
dropTarget.addEventListener("dragleave", onDropEnd);
});
function onDropEnd(e){
e.target.placeholder = '';
e.target.classList.remove('plain-sight-active')
}
function onDrop(e) {
e.target.placeholder = 'Drop your password image here';
e.target.classList.add('plain-sight-active')
}
function getBase64(file): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
}
passwordFields.forEach(passwordField => {
passwordField.addEventListener('drop', async (ev) => {
ev.preventDefault();
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s)
[...ev.dataTransfer.items].forEach(async (item, i) => {
// If dropped items aren't files, reject them
if (item.kind === "file") {
const file : File = item.getAsFile();
let password = prompt("What is your password?", "password12");
const encoded = await getDecodedMessage(await getBase64(file), password)
passwordField.value = encoded;
setTimeout(() => {
const keyboardEvent = new KeyboardEvent('keydown', {
code: 'Enter',
key: 'Enter',
charCode: 13,
keyCode: 13,
view: window,
bubbles: true
});
passwordField.dispatchEvent(keyboardEvent);
}, 500);
}
});
} else {
// Use DataTransfer interface to access the file(s)
[...ev.dataTransfer.files].forEach((file, i) => {
console.log(`… file[${i}].name = ${file.name}`);
});
}
});
})