Skip to content

Commit 985fd4b

Browse files
committed
refacto
1 parent 6cf8bcd commit 985fd4b

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

main.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ def refreshPage(driver):
2121
driver.refresh()
2222
return driver.page_source
2323

24+
prefs = {
25+
# 2: Block all images (and video elements)
26+
"profile.managed_default_content_settings.images": 2,
27+
# 2: Block notifications
28+
"profile.default_content_setting_values.notifications": 2,
29+
# 2: Disable stylesheets
30+
"profile.managed_default_content_settings.stylesheets": 2,
31+
# 2: Block JavaScript
32+
"profile.managed_default_content_settings.javascript": 2
33+
}
34+
2435
def main():
2536
global stop
2637
options = Options()
@@ -32,9 +43,7 @@ def main():
3243
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
3344
options.add_argument(f"user-agent={user_agent}")
3445

35-
# Disable images to speed up the process by uncommenting the following lines
36-
# prefs = {"profile.managed_default_content_settings.images": 2}
37-
# options.add_experimental_option("prefs", prefs)
46+
options.add_experimental_option("prefs", prefs)
3847

3948
caps = DesiredCapabilities().CHROME
4049
caps["pageLoadStrategy"] = "eager"
@@ -45,14 +54,19 @@ def main():
4554
listener = keyboard.Listener(on_press=on_press)
4655
listener.start()
4756

48-
print(f'{"\033[31m"}Press "Esc" to stop the script\n{"\033[0m"}')
57+
print(f'{"\033[36m"}Press "Esc" to stop the script\n{"\033[0m"}')
4958

5059
try:
5160
while not stop:
5261
start_time = time.time()
5362
refreshPage(driver)
5463
end_time = time.time()
55-
print(f"Page refreshed in {end_time - start_time:.2f} seconds")
64+
if end_time - start_time > 2:
65+
print(f"{"\033[31m"}Page refreshed in {end_time - start_time:.2f} seconds{"\033[0m"}")
66+
elif end_time - start_time > 1:
67+
print(f"{"\033[33m"}Page refreshed in {end_time - start_time:.2f} seconds{"\033[0m"}")
68+
else:
69+
print(f"{"\033[32m"}Page refreshed in {end_time - start_time:.2f} seconds{"\033[0m"}")
5670
finally:
5771
listener.stop()
5872
driver.quit()

0 commit comments

Comments
 (0)