Ver Fonte

Merge branch 'koishi-production' into mediaonly-koishi

Mike L há 3 anos atrás
pai
commit
2c58b3d9f5
2 ficheiros alterados com 10 adições e 7 exclusões
  1. 3 3
      dist/webshot.js
  2. 7 4
      src/webshot.ts

+ 3 - 3
dist/webshot.js

@@ -86,7 +86,7 @@ class Webshot extends CallableInstance {
                     ]))
                         .then(() => page.addStyleTag({
                         content: 'header,#layers{display:none!important}article{background-color:transparent!important}' +
-                            '[data-testid="caret"],[role="group"],[data-testid="tweet"]+*>[class*=" "]+div:nth-last-child(2){display:none}',
+                            '[data-testid="caret"],[role="group"],[data-testid="tweet"] [class*=" "]+:last-child>*+[class*=" "]~div{display:none}',
                     }))
                         .then(() => page.addStyleTag({
                         content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',
@@ -101,7 +101,7 @@ class Webshot extends CallableInstance {
                             });
                         }, 250);
                     }))
-                        .then(() => page.waitForSelector('xpath=//section/*/*/div[.//article[not(.//*[@data-testid]//time)]]', { timeout: getTimeout() }))
+                        .then(() => page.waitForSelector('xpath=//section/*/*/div[.//article[not(.//time[not(ancestor::div[@aria-labelledby])])]]', { timeout: getTimeout() }))
                         .then(handle => handle.$$('xpath=..//a[contains(@href,"content_you_see")]/../../..//*[@role="button"]')
                         .then(sensitiveToggles => {
                         const count = sensitiveToggles.length;
@@ -122,7 +122,7 @@ class Webshot extends CallableInstance {
                             throw new puppeteer.errors.TimeoutError();
                         return handle.evaluate(div => {
                             try {
-                                const selector = '[data-testid="tweet"]>:nth-child(2)>:first-child a';
+                                const selector = '[data-testid="tweet"] :nth-child(2)>:first-child a';
                                 const getProfileUrl = () => (div.querySelector(selector) || { href: '' }).href;
                                 const ownerProfileUrl = getProfileUrl();
                                 while (div = div.previousElementSibling) {

+ 7 - 4
src/webshot.ts

@@ -112,7 +112,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
             // hide header, "more options" button, like and retweet count
             .then(() => page.addStyleTag({
               content: 'header,#layers{display:none!important}article{background-color:transparent!important}' +
-                '[data-testid="caret"],[role="group"],[data-testid="tweet"]+*>[class*=" "]+div:nth-last-child(2){display:none}',
+                '[data-testid="caret"],[role="group"],[data-testid="tweet"] [class*=" "]+:last-child>*+[class*=" "]~div{display:none}',
             }))
             .then(() => page.addStyleTag({
               content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',
@@ -129,7 +129,10 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
               }, 250);
             }))
             // find main tweet
-            .then(() => page.waitForSelector('xpath=//section/*/*/div[.//article[not(.//*[@data-testid]//time)]]', {timeout: getTimeout()}))
+            .then(() => page.waitForSelector(
+              'xpath=//section/*/*/div[.//article[not(.//time[not(ancestor::div[@aria-labelledby])])]]',
+              {timeout: getTimeout()}
+            ))
             // toggle visibility of sensitive tweets
             .then(handle => handle.$$('xpath=..//a[contains(@href,"content_you_see")]/../../..//*[@role="button"]')
               .then(sensitiveToggles => {
@@ -146,12 +149,12 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
               logger.warn(`navigation timed out at ${getTimerTime()} seconds`);
               return null;
             })
-            // scroll to last tweet by owner in thread, if any, or top of thread
+            // scroll to 2nd last tweet by owner in thread, if any, or top of thread
             .then((handle: puppeteer.ElementHandle<HTMLDivElement>) => {
               if (handle === null) throw new puppeteer.errors.TimeoutError();
               return handle.evaluate(div => {
                 try {
-                  const selector = '[data-testid="tweet"]>:nth-child(2)>:first-child a';
+                  const selector = '[data-testid="tweet"] :nth-child(2)>:first-child a';
                   const getProfileUrl = () => (div.querySelector<HTMLAnchorElement>(selector) || {href: ''}).href;
                   const ownerProfileUrl = getProfileUrl();
                   // eslint-disable-next-line no-cond-assign