2022-04-21 22:20:44 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-04-24 18:22:58 +02:00
|
|
|
grab_no=0
|
|
|
|
|
2022-05-05 21:54:34 +02:00
|
|
|
grab(){
|
2022-04-24 18:22:58 +02:00
|
|
|
NOTE="$grab_no $@"
|
|
|
|
#echo $@
|
|
|
|
((grab_no++))
|
2022-04-24 18:53:27 +02:00
|
|
|
scrot --note "-f '/usr/share/fonts/noto/NotoSansMono-Medium.ttf/40' -c 255,0,0,255 -t '$NOTE'" "/opt/static/$(date -Iminutes).png"
|
2022-04-24 18:22:58 +02:00
|
|
|
#echo "not grabbing"
|
2022-04-21 22:20:44 +02:00
|
|
|
}
|
|
|
|
|
2022-04-24 19:57:01 +02:00
|
|
|
grab_screen_to_public(){
|
|
|
|
id=$1
|
|
|
|
filepath="/opt/static/$id/preview.png"
|
|
|
|
tempfile="/opt/static/$id/temp.png"
|
|
|
|
mkdir -p "/opt/static/$id"
|
|
|
|
rm -f "$tempfile"
|
|
|
|
scrot "$tempfile"
|
|
|
|
mv -f "$tempfile" "$filepath"
|
|
|
|
}
|
|
|
|
|
2022-04-21 22:20:44 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start_firefox(){
|
|
|
|
rm -rf /root/.mozilla/firefox/bifup8k5.docker/sessionstore-backups
|
|
|
|
#echo 'user_pref("layout.css.devPixelsPerPx", "1.5");' >> /root/.mozilla/firefox/bifup8k5.docker/prefs.js
|
|
|
|
firefox --devtools > /dev/null &
|
|
|
|
FIREFOX_PID=$!
|
|
|
|
sleep 3
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare_firefox(){
|
|
|
|
xdotool key Return # in case there's a "firefox closed unexpectedly" button
|
|
|
|
sleep 1
|
2022-04-24 18:22:58 +02:00
|
|
|
grab "after sleep 1"
|
2022-04-21 22:20:44 +02:00
|
|
|
click 1886 13 #maximize button
|
2022-04-24 18:22:58 +02:00
|
|
|
grab "after maximize"
|
2022-04-21 22:20:44 +02:00
|
|
|
sleep 1
|
2022-04-24 18:22:58 +02:00
|
|
|
grab "after sleep 1"
|
2022-04-24 21:54:10 +02:00
|
|
|
# no need to reopen the network tab, as it's almost certainly already open
|
|
|
|
# keycombo Control_L Shift_L e
|
|
|
|
# grab "after ctrl+shift+e"
|
|
|
|
# keycombo Shift_L F5 #profiler
|
|
|
|
# grab "after shift-c F5"
|
|
|
|
# keycombo Control_L Shift_L e
|
|
|
|
# sleep 5 # it needs some time
|
2022-04-21 22:20:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
load_website(){
|
|
|
|
URL=$1
|
|
|
|
keycombo Control_L l
|
2022-04-24 18:22:58 +02:00
|
|
|
grab ctrl+l
|
2022-04-21 22:20:44 +02:00
|
|
|
xdotool type "$URL"
|
2022-04-24 18:22:58 +02:00
|
|
|
grab type url
|
2022-04-21 22:20:44 +02:00
|
|
|
xdotool key Return
|
2022-04-24 18:22:58 +02:00
|
|
|
grab enter
|
2022-04-21 22:20:44 +02:00
|
|
|
sleep 1
|
|
|
|
echo "waiting for $URL to load..."
|
|
|
|
times=0
|
|
|
|
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-04-24 18:22:58 +02:00
|
|
|
scrot
|
2022-04-21 22:20:44 +02:00
|
|
|
times=$((times + 1))
|
2022-04-24 20:04:45 +02:00
|
|
|
if [ $times -eq 30 ]
|
2022-04-21 22:20:44 +02:00
|
|
|
then
|
2022-04-24 20:04:45 +02:00
|
|
|
echo "Could not load website in time, trying anyway"
|
2022-04-21 22:20:44 +02:00
|
|
|
break;
|
|
|
|
fi
|
|
|
|
done
|
2022-04-24 18:22:58 +02:00
|
|
|
echo "website loaded!"
|
2022-04-21 22:20:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
open_network_inspector(){
|
|
|
|
keycombo Shift_L F5 #profiler
|
|
|
|
sleep 1
|
|
|
|
keycombo Control_L Shift_L e
|
|
|
|
}
|
|
|
|
|
|
|
|
network_inspector_search(){
|
|
|
|
query=$1
|
|
|
|
keycombo Control_L f
|
|
|
|
sleep 0.2
|
2022-04-24 18:22:58 +02:00
|
|
|
keycombo Control_L a
|
|
|
|
sleep 0.1
|
2022-04-21 22:20:44 +02:00
|
|
|
xdotool type "$query"
|
|
|
|
xdotool key Escape
|
|
|
|
sleep 0.3
|
|
|
|
seq 28 | xargs -I {} xdotool key Tab
|
|
|
|
xdotool key Down
|
|
|
|
sleep 0.1
|
|
|
|
xdotool key Up
|
|
|
|
sleep 0.1
|
|
|
|
}
|
|
|
|
|
|
|
|
network_inspector_has_more_entries(){
|
|
|
|
[ $(get_pixel_color 1267 1572) = "F9F9FA" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
network_inspector_next_entry(){
|
|
|
|
xdotool key Tab
|
|
|
|
sleep 0.05
|
|
|
|
xdotool key Down
|
|
|
|
sleep 0.2
|
|
|
|
}
|