-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
537 additions
and
3,268 deletions.
There are no files selected for viewing
Binary file not shown.
285 changes: 285 additions & 0 deletions
285
extension/firefox/content/deps/tesseract-core@4.0.2.wasm.js
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
export function deleteStep(index = -1) { | ||
const step = document.querySelector(`[wtc-step-index="${index}"]`); | ||
step.remove(); | ||
} | ||
} | ||
|
||
export function attachScrubs(screenshots = []) { | ||
for (const screenshot of screenshots) { | ||
const observer = new MutationObserver((mutations, observer) => { | ||
observer.disconnect(); | ||
const words = JSON.parse(mutations[0].target.getAttribute('wtc-ocr')); | ||
const overlay = screenshot.parentNode.querySelector('.scrub-overlay'); | ||
const parser = new DOMParser(); | ||
const sizeRatio = screenshot.clientHeight / screenshot.naturalHeight; | ||
const clientSize = { width: screenshot.clientWidth, height: screenshot.clientHeight }; | ||
for (const { word, box } of words) { | ||
const width = ((box.x1 - box.x0) * sizeRatio / clientSize.width) * 100; | ||
const height = ((box.y1 - box.y0) * sizeRatio / clientSize.height) * 100; | ||
const top = ((box.y0 * sizeRatio) / clientSize.height) * 100; | ||
const left = ((box.x0 * sizeRatio) / clientSize.width) * 100; | ||
const scrubElementHtml = ` | ||
<div | ||
class="scrub-element" | ||
wtc-word="${encodeURIComponent(JSON.stringify({ word, box }))}" | ||
style="width: ${width}%; height: ${height}%; top: ${top}%; left: ${left}%" | ||
></div> | ||
`; | ||
const scrubElement = parser.parseFromString(scrubElementHtml, 'text/html').querySelector('.scrub-element'); | ||
scrubElement.addEventListener('click', () => { | ||
scrubElement.classList.toggle('scrubbed'); | ||
scrubElement.c | ||
}); | ||
overlay.appendChild(scrubElement); | ||
} | ||
}); | ||
observer.observe(screenshot, { | ||
childList: false, | ||
subtree: false, | ||
attributes: true, | ||
attributeFilter: ['wtc-ocr'] | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as ocr from '../../deps/tesseract@4.0.2.min.js'; | ||
|
||
let worker; | ||
|
||
async function initWorker() { | ||
const w = await Tesseract.createWorker({ | ||
workerPath: './deps/worker@4.0.2.min.js', | ||
workerBlobURL: false, | ||
langPath: './deps', | ||
corePath: './deps/tesseract-core@4.0.2.wasm.js', | ||
tessedit_create_hocr: '0', | ||
tessedit_create_tsv: '0', | ||
tessedit_create_box: '0', | ||
tessedit_create_unlv: '0', | ||
tessedit_create_osd: '0', | ||
}); | ||
await w.loadLanguage('eng-fast'); | ||
await w.initialize('eng-fast'); | ||
worker = w; | ||
return w; | ||
} | ||
|
||
async function recognizeWords(element) { | ||
const result = await worker.recognize(element); | ||
return result.data.paragraphs.map(({ lines }) => { | ||
return lines.map((line) => line.words.map((word) => { | ||
return { | ||
word: word.choices[0], | ||
box: word.bbox, | ||
}; | ||
})).flat(); | ||
}).flat(); | ||
} | ||
|
||
|
||
export async function attachOcrInfo(screenshots) { | ||
document.querySelector('.ocr-loading-indicator').classList.toggle('hidden'); | ||
if (worker == null) { | ||
await initWorker(); | ||
} | ||
for (const screenshot of screenshots) { | ||
const overlay = screenshot.parentNode.querySelector('.loading-overlay'); | ||
overlay.classList.toggle('loading'); | ||
const words = await recognizeWords(screenshot); | ||
const serialized = JSON.stringify(words); | ||
screenshot.setAttribute('wtc-ocr', serialized); | ||
overlay.classList.toggle('loading'); | ||
} | ||
document.querySelector('.ocr-loading-indicator').classList.toggle('hidden'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.