first commit
This commit is contained in:
commit
4469b3cf81
|
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 103 KiB |
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 98 KiB |
|
|
@ -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)
|
||||||
|
})
|
||||||
|
}())
|
||||||
Loading…
Reference in New Issue