2022-03-06 22:37:08 +01:00
#!/bin/bash -x
2022-02-24 00:24:13 +01:00
2022-02-13 22:30:56 +01:00
source ./ephemeral-x.sh
2022-02-24 00:24:13 +01:00
get_pixel_color( ) {
x = $1 ;
y = $2 ;
output_path = " /tmp/ $( mktemp -u XXXXXX) .png "
scrot $output_path
magick $output_path -format " %[hex:p{ $x , $y }] " info:
}
extract_text( ) {
output_path = " /tmp/ $( mktemp -u XXXXXX) .png "
cropped_path = $output_path --cropped.png
scrot $output_path
left = $1
top = $2
width = $3
height = $4
# https://www.libvips.org/API/current/libvips-conversion.html#vips-extract-area
vips extract_area " $output_path " " $cropped_path " $left $top $width $height
tesseract " $cropped_path " stdout -l eng
}
click ( ) {
xdotool mousemove $1 $2
xdotool click 1
}
grab ( ) {
NOTE = " $@ "
echo $@
scrot --note " -f '/usr/share/fonts/noto/NotoSansMono-Medium.ttf/40' -c 255,0,0,255 -t ' $NOTE ' "
}
keycombo( ) {
for key in " $@ "
do
xdotool keydown $key
sleep 0.01
done
for key in " $@ "
do
xdotool keyup $key
sleep 0.01
done
sleep 0.5
}
2022-02-27 22:27:21 +01:00
annotate_header( ) {
header = $1
d = $( date "+%Y-%m-%d__%H_%M_%S" )
2022-03-06 22:37:08 +01:00
filename = " ${ d } __ $header .png "
cropped_filename = " ${ filename } __cropped.png "
2022-02-27 22:27:21 +01:00
left = 2056
top = 330
width = 824
height = 1260
scrot $filename
vips extract_area " $filename " " $cropped_filename " $left $top $width $height
2022-03-06 22:37:08 +01:00
coords = $( python ./get-text-position.py " $cropped_filename " | grep set-cookie | awk '{print $1 " " $2 " " $3 " " $4}' )
rect_x1 = $( echo " $coords " | awk '{print $1}' )
rect_y1 = $( echo " $coords " | awk '{print $2}' )
rect_w = $( echo " $coords " | awk '{print $3}' )
rect_h = $( echo " $coords " | awk '{print $4}' )
rect_x2 = $(( rect_x1 + rect_w))
rect_y2 = $(( rect_y1 + rect_h))
annotated_filename = " ${ cropped_filename } __annotated.png "
convert " $cropped_filename " -fill transparent -stroke red -draw " rectangle $rect_x1 , $rect_y1 $rect_x2 , $rect_y2 " " $annotated_filename "
2022-02-27 22:27:21 +01:00
}
2022-02-24 00:24:13 +01:00
rm -rf /root/.mozilla/firefox/bifup8k5.docker/sessionstore-backups
#echo 'user_pref("layout.css.devPixelsPerPx", "1.5");' >> /root/.mozilla/firefox/bifup8k5.docker/prefs.js
2022-03-05 21:21:05 +01:00
firefox --devtools > /dev/null &
# test
2022-02-13 22:30:56 +01:00
FIREFOX_PID = $!
sleep 3
2022-02-24 00:24:13 +01:00
xdotool key Return # in case there's a "firefox closed unexpectedly" button
2022-02-13 22:30:56 +01:00
sleep 1
2022-02-24 00:24:13 +01:00
# click 1424 628
2022-02-13 22:30:56 +01:00
2022-03-06 22:37:08 +01:00
# grab before maximize
2022-02-24 00:24:13 +01:00
click 1886 13 #maximize button
sleep 1
#grab after maximize before control shift E
#keycombo Control_L Shift_L e
#sleep 1
2022-03-06 22:37:08 +01:00
# grab before escape
2022-02-24 00:24:13 +01:00
2022-03-06 22:37:08 +01:00
#xdotool key Escape
2022-02-24 00:24:13 +01:00
sleep 0.1
2022-03-06 22:37:08 +01:00
# grab after escape
2022-02-24 00:24:13 +01:00
2022-03-05 21:21:05 +01:00
keycombo Control_L Shift_L e
2022-03-06 22:37:08 +01:00
#xdotool key Escape
2022-03-05 21:21:05 +01:00
keycombo Shift_L c F5 #profiler
keycombo Control_L Shift_L e
2022-03-06 22:37:08 +01:00
# grab after control shift e before ctrl L
2022-02-24 00:24:13 +01:00
keycombo Control_L l
2022-03-06 22:37:08 +01:00
# grab after control L
2022-02-13 22:30:56 +01:00
2022-02-14 22:10:01 +01:00
xdotool type "biedronka.pl"
2022-02-13 22:30:56 +01:00
xdotool key Return
2022-02-24 00:24:13 +01:00
2022-03-06 22:37:08 +01:00
# grab after return
2022-02-13 22:30:56 +01:00
2022-02-14 22:10:01 +01:00
sleep 1
scrot
2022-02-24 00:24:13 +01:00
2022-03-05 21:21:05 +01:00
2022-02-24 00:24:13 +01:00
echo "waiting for the website to load..."
2022-03-05 21:21:05 +01:00
times = 0
2022-02-24 00:24:13 +01:00
while [ $( get_pixel_color 143 122) = "2E3436" ] # the center of the X icon that becomes a "refresh" icon once the website is finished loading
do
sleep 0.5
printf "."
2022-03-05 21:21:05 +01:00
scrot
times = $(( times + 1 ))
if [ $times -eq 10 ]
then
echo "Could not load website in time"
break;
fi
2022-02-24 00:24:13 +01:00
done
2022-03-05 21:21:05 +01:00
keycombo Shift_L F5 #profiler
echo shift f5
sleep 1
echo "sleep 1"
2022-02-24 00:24:13 +01:00
keycombo Control_L Shift_L e
2022-03-05 21:21:05 +01:00
echo ctrl shift e
2022-02-24 00:24:13 +01:00
keycombo Control_L f
2022-02-14 22:10:01 +01:00
sleep 0.2
2022-02-24 00:24:13 +01:00
xdotool type "method:GET domain:adocean.pl" # can filter with more granularity: https://developer.mozilla.org/en-US/docs/Tools/Network_Monitor/request_list#filtering_by_properties
xdotool key Escape
sleep 0.3
2022-02-14 22:10:01 +01:00
scrot
2022-02-13 22:30:56 +01:00
2022-02-24 00:24:13 +01:00
seq 28 | xargs -I { } xdotool key Tab
xdotool key Down
sleep 0.1
xdotool key Up
sleep 0.1
2022-02-13 22:30:56 +01:00
scrot
2022-02-24 00:24:13 +01:00
while [ $( get_pixel_color 1267 1572) = "F9F9FA" ]
do
xdotool key Tab
sleep 0.05
xdotool key Down
2022-02-27 22:27:21 +01:00
sleep 0.2
annotate_header set-cookie
2022-03-05 21:21:05 +01:00
# use python script ^here to annotate the cropped png
2022-02-27 22:27:21 +01:00
# scrot
# echo "########## EXTRACTED TEXT: "
# extract_text 2056 330 824 1260 | grep cookie
2022-02-24 00:24:13 +01:00
done
2022-03-05 21:21:05 +01:00
echo "Done!"
2022-02-24 00:24:13 +01:00
2022-02-13 22:30:56 +01:00
kill -2 %%;
cleanup
2022-02-24 00:24:13 +01:00