/
index.html
179 lines (145 loc) · 5.28 KB
/
index.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Web Page</title>
<!-- Include the Filestack library -->
<script src="https://static.filestackapi.com/filestack-js/3.x.x/filestack.min.js"></script>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f1f1f1;
font-family: 'Times New Roman', Times, serif;
background-image: url('https://img.freepik.com/free-photo/abstract-blue-geometric-shapes-background_24972-1841.jpg');
background-size: cover;
}
button {
padding: 50px;
font-size: 50px;
font-family: 'Times New Roman', Times, serif;
cursor: pointer;
margin: 10px;
border: none;
border-radius: 5px;
background-color: #EF4A25;
color: white;
}
#filestackEnhanceButtonContainer {
display: flex;
flex-direction: column;
align-items: center;
}
.closeButton {
padding: 5px 10px;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
border: none;
border-radius: 3px;
background-color: #ccc;
color: #333;
}
#copyButton {
display: none;
padding: 10px 20px;
font-size: 18px;
cursor: pointer;
margin: 10px;
border: none;
border-radius: 5px;
background-color: #EF4A25;
color: white;
}
#returnToOCRButton {
display: none;
padding: 10px 20px;
font-size: 18px;
cursor: pointer;
margin: 10px;
border: none;
border-radius: 5px;
background-color: #fbbc05;
color: white;
}
#copiedMessage {
display: none;
margin-top: 10px;
color: #333;
}
#ocrText {
border: 2px solid #EF4A25;
padding: 10px;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="filestackContainer" style="display: none;"></div>
<div id="filestackEnhanceButtonContainer">
<button id="filestackEnhanceButton" onclick="openFilestackEnhancePicker()">Filestack OCR</button>
</div>
<div id="ocrResult" style="display: none;">
<p id="ocrText"></p>
<button id="copyButton" onclick="copyText()">Copy Text</button>
<button id="returnToOCRButton" onclick="returnToOCR()">Return to OCR</button>
<span id="copiedMessage">Text copied!</span>
</div>
<script>
const apikey = 'A18L3T2eWRemxYIGwGlZsz';
const client = filestack.init(apikey);
let uploadedFileHandle;
function openFilestackEnhancePicker() {
const options = {
onUploadDone: (res) => {
uploadedFileHandle = res.filesUploaded[0].handle;
performOCR(uploadedFileHandle);
},
};
const picker = client.picker(options);
picker.open();
}
function performOCR(fileHandle) {
const policy = 'eyJjYWxsIjpbInBpY2siLCJyZWFkIiwic3RhdCIsIndyaXRlIiwid3JpdGVVcmwiLCJzdG9yZSIsImNvbnZlcnQiLCJyZW1vdmUiLCJleGlmIiwicnVuV29ya2Zsb3ciXSwiZXhwaXJ5IjoxNzA5MDYyMjAwfQ==';
const signature = '3d39be23b3298d8662f5089b601421562e42791c0d02249ff3166bd470c023fc';
const ocrUrl = `https://cdn.filestackcontent.com/${apikey}/security=p:${policy},s:${signature}/ocr/${fileHandle}`;
fetch(ocrUrl)
.then(response => response.json())
.then(data => {
const ocrResult = document.getElementById('ocrResult');
const ocrText = document.getElementById('ocrText');
ocrText.innerText = 'OCR Result: ' + data.text;
ocrResult.style.display = 'block';
document.getElementById('copyButton').style.display = 'block';
document.getElementById('returnToOCRButton').style.display = 'block';
document.getElementById('filestackEnhanceButtonContainer').style.display = 'none';
})
.catch(error => console.error('Error:', error));
}
function copyText() {
const textElement = document.getElementById('ocrText');
const text = textElement.innerText;
navigator.clipboard.writeText(text)
.then(() => {
document.getElementById('copiedMessage').style.display = 'block';
setTimeout(() => {
document.getElementById('copiedMessage').style.display = 'none';
}, 2000);
})
.catch(err => {
console.error('Failed to copy: ', err);
});
}
function returnToOCR() {
document.getElementById('ocrResult').style.display = 'none';
document.getElementById('copyButton').style.display = 'none';
document.getElementById('returnToOCRButton').style.display = 'none';
document.getElementById('filestackEnhanceButtonContainer').style.display = 'block';
}
</script>
</body>
</html>