first commit

This commit is contained in:
Kai Ton 2024-05-23 10:01:59 +00:00
commit 4469b3cf81
8 changed files with 1875 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

BIN
convert.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

BIN
eng.traineddata Normal file

Binary file not shown.

1805
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

9
package.json Normal file
View File

@ -0,0 +1,9 @@
{
"dependencies": {
"jsdom": "^24.0.0",
"robotjs": "^0.6.0",
"screenshot-desktop": "^1.15.0",
"sharp": "^0.33.4",
"tesseract.js": "^4.1.1"
}
}

BIN
screenshot.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

60
screenshot.js Normal file
View File

@ -0,0 +1,60 @@
/**
* NOTE: install "dark mode" on browser because tesseract need contract to detect text
* NOTE: zoom 120% on browser because below
*/
const screenshot = require('screenshot-desktop') // capture screen
const robotjs = require('robotjs')
const tesseract = require('tesseract.js')
const jsdom = require('jsdom')
const KEYWORD = 'ebay.com'
async function handleToClick(keywordToClick, fileScreenshot = 'screenshot.jpg') {
if(!fileScreenshot) {
fileScreenshot = 'screenshot.jpg'
}
const _randomInteger = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
return new Promise((res, rej) => {
screenshot({filename: fileScreenshot}).then((imgPath) => {
tesseract.recognize(imgPath)
.then(({data: {hocr, text}}) => {
console.log({hocr, text})
const dom = new jsdom.JSDOM(hocr)
const spanEls = dom.window.document.querySelectorAll('span')
for(let i = 0; i < spanEls.length; i++) {
const span = spanEls[i];
const text = span.textContent.split(' ').join('')
if(text.includes(keywordToClick)) {
const [type, left, bottom, right, top] = span.title.split(' ')
robotjs.moveMouse(
_randomInteger(10, 50) + parseInt(left), // randomInteger is prefix depreciation
parseInt(top),
)
robotjs.mouseClick()
console.log(text)
return res(true)
}
}
return rej(false)
})
})
});
}
(function recusiveScroll(countScroll = 0, limitStopScroll = 20) {
if(countScroll > limitStopScroll) {
return;
}
const [x, y] = [0, -3]
handleToClick(KEYWORD).catch(() => {
recusiveScroll(++countScroll, limitStopScroll)
}).finally(() => {
robotjs.scrollMouse(x, y)
})
}())

BIN
test.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB