remove replies after reddit front end changes

pull/2366/head
Piradata 2 months ago
parent 6cf8fef6db
commit 15ee3d8c56
No known key found for this signature in database
GPG Key ID: DB665E73A5627B46

@ -229,50 +229,33 @@ def get_screenshots_of_reddit_posts(reddit_object: dict, screenshot_num: int):
to_language=settings.config["reddit"]["thread"]["post_lang"], to_language=settings.config["reddit"]["thread"]["post_lang"],
) )
page.evaluate( page.evaluate(
'([tl_content, tl_id]) => document.querySelector(`shreddit-comment[thingid="t1_${tl_id}"] > div:nth-child(2) > div > div[data-testid="comment"] > div`).textContent = tl_content', '([tl_content, tl_id]) => document.querySelector(`shreddit-comment[thingid="t1_${tl_id}"] > div[slot="comment"] > div > p`).textContent = tl_content',
[comment_tl, comment["comment_id"]], [comment_tl, comment["comment_id"]],
) )
try: try:
target = f'shreddit-comment[thingid="t1_{comment["comment_id"]}"] div#t1_{comment["comment_id"]}-comment-rtjson-content'
visible = page.locator(target).is_visible()
if not visible: # Hide child responses/replies, other responses button and threadline arrows before taking the screenshot
class ElementVisible(Exception):pass page.evaluate(
try: '''() => {
for _ in range(30): // Hide all comments with depth > 0 (these are all replies/children)
page.evaluate(""" document.querySelectorAll('shreddit-comment[thingid="t1_${tl_id}"] > shreddit-comment[depth="1"]').forEach(el => {
(target) => { el.style.display = "none";
const element = document.querySelector(target); });
if (element) {
element.style.display = 'block'; // 'inline' // Hide the "other responses" button
element.style.visibility = 'visible'; document.querySelectorAll('shreddit-comment[thingid="t1_${tl_id}"] > faceplate-partial').forEach(el => {
} el.style.display = "none";
} });
""", target)
page.wait_for_timeout(1000) // Hide the threadline arrows
visible = page.locator(target).is_visible() // document.querySelector('shreddit-comment[thingid="t1_${tl_id}"]').shadowRoot.querySelectorAll('div.threadline').forEach(el => {
if visible: // el.style.display = "none";
raise ElementVisible // });
target = f'shreddit-comment[thingid="t1_{comment["comment_id"]}"] div#t1_{comment["comment_id"]}-comment-rtjson-content div#-post-rtjson-content' }'''
visible = page.locator(target).is_visible() )
if not visible:
for _ in range(30): # Target only the main comment content, NOW not including replies
page.evaluate("""
(target) => {
const element = document.querySelector(target);
if (element) {
element.style.display = 'block'; // 'inline'
element.style.visibility = 'visible';
}
}
""", target)
page.wait_for_timeout(1000)
visible = page.locator(target).is_visible()
if visible:
raise ElementVisible
target = f'shreddit-comment[thingid="t1_{comment["comment_id"]}"]' target = f'shreddit-comment[thingid="t1_{comment["comment_id"]}"]'
except ElementVisible:
pass
if settings.config["settings"]["zoom"] != 1: if settings.config["settings"]["zoom"] != 1:
# store zoom settings # store zoom settings

Loading…
Cancel
Save