浏览代码

further webshot tweaks, add webshot test

Mike L 3 年之前
父节点
当前提交
b86dab3853
共有 6 个文件被更改,包括 46 次插入16 次删除
  1. 1 1
      dist/twitter.js
  2. 8 6
      dist/webshot.js
  3. 13 0
      dist/webshot_test.js
  4. 1 1
      src/twitter.ts
  5. 9 8
      src/webshot.ts
  6. 14 0
      src/webshot_test.js

+ 1 - 1
dist/twitter.js

@@ -144,7 +144,7 @@ class ScreenNameNormalizer {
 }
 exports.ScreenNameNormalizer = ScreenNameNormalizer;
 ScreenNameNormalizer.normalize = (username) => `${username.toLowerCase().replace(/^@/, '')}:`;
-let browserLogin = (page) => Promise.reject();
+let browserLogin = (page) => Promise.resolve();
 let browserSaveCookies = browserLogin;
 let isWaitingForLogin = false;
 const acceptCookieConsent = (page) => page.click('button:has-text("すべて許可")', { timeout: 5000 })

+ 8 - 6
dist/webshot.js

@@ -96,9 +96,10 @@ class Webshot extends CallableInstance {
                         logger.warn(`navigation timed out at ${getTimerTime()} ms`);
                         return null;
                     })
-                        .then(() => page.addStyleTag({ content: 'nav,footer,header+div,header+div+div>div>div+div,article button,canvas,' +
-                            'article section,article section+div>ul>:not(div),li [tabindex="0"] div:not(:first-child){display:none!important} ' +
-                            'section+div{overflow:hidden} section+*>*{position:relative!important} article{border-bottom:1px solid!important}',
+                        .then(() => page.addStyleTag({ content: 'nav,footer,header+div,header+div+div>div>div+div,article button,canvas,article section,article section+div>ul>:not(div),' +
+                            'article section+div>ul>div [role="button"],li [tabindex="0"] div:not(:first-child){display:none!important} ' +
+                            'section+div{overflow:hidden} section+*>*{position:relative!important} article{border-bottom:1px solid!important} ' +
+                            'article section+div>ul>div>li{padding:6px 2px 12px!important}',
                     }))
                         .then(() => page.addStyleTag({
                         content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',
@@ -111,7 +112,7 @@ class Webshot extends CallableInstance {
                         time = document.querySelector('article section~div>a>time');
                         if (time) {
                             time.innerHTML = time.title + ' ' + new Date(time.dateTime).toLocaleTimeString().slice(0, -3);
-                            time.parentElement.parentElement.style.margin = '-24px 0 12px';
+                            time.parentElement.parentElement.style.margin = '-24px 2px 12px';
                         }
                     }))
                         .then(() => utils_1.chainPromises(morePostProcessings.map(func => () => func(page))))
@@ -207,12 +208,13 @@ class Webshot extends CallableInstance {
             throw Error();
         })(/\/.*\.(.+?)\?/.exec(url)[1]));
         if (this.mode = mode) {
-            onready();
+            if (onready)
+                onready();
         }
         else {
             this.getCookies = getCookies;
             this.wsUrl = wsUrl;
-            this.connect(() => onready(this.performOnNewPage));
+            this.connect(() => onready && onready(this.performOnNewPage));
         }
     }
     webshot(lazyMediaItems, callback, webshotDelay) {

文件差异内容过多而无法显示
+ 13 - 0
dist/webshot_test.js


+ 1 - 1
src/twitter.ts

@@ -168,7 +168,7 @@ export class ScreenNameNormalizer {
   }
 }
 
-let browserLogin = (page: Page): Promise<void> => Promise.reject();
+let browserLogin = (page: Page): Promise<void> => Promise.resolve();
 
 let browserSaveCookies = browserLogin;
 

+ 9 - 8
src/webshot.ts

@@ -42,17 +42,17 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
   constructor(
     wsUrl: string, mode: number,
     getCookies: () => Cookies,
-    onready?: (doOnNewPage?: typeof Webshot.prototype.performOnNewPage) => void
+    onready: (doOnNewPage?: typeof Webshot.prototype.performOnNewPage) => void
   ) {
     super('webshot');
     // tslint:disable-next-line: no-conditional-assignment
     // eslint-disable-next-line no-cond-assign
     if (this.mode = mode) {
-      onready();
+      if (onready) onready();
     } else {
       this.getCookies = getCookies;
       this.wsUrl = wsUrl;
-      this.connect(() => onready(this.performOnNewPage));
+      this.connect(() => onready && onready(this.performOnNewPage));
     }
   }
 
@@ -132,11 +132,12 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
               logger.warn(`navigation timed out at ${getTimerTime()} ms`);
               return null;
             })
-            // hide header, footer, "more options" button, like and share count, carousel navigator, and comments
+            // hide header, footer, "more options" button, like and share count, carousel navigator, 2nd avatar, and comments
             .then(() => page.addStyleTag({content:
-              'nav,footer,header+div,header+div+div>div>div+div,article button,canvas,' +
-              'article section,article section+div>ul>:not(div),li [tabindex="0"] div:not(:first-child){display:none!important} ' +
-              'section+div{overflow:hidden} section+*>*{position:relative!important} article{border-bottom:1px solid!important}',
+              'nav,footer,header+div,header+div+div>div>div+div,article button,canvas,article section,article section+div>ul>:not(div),' +
+              'article section+div>ul>div [role="button"],li [tabindex="0"] div:not(:first-child){display:none!important} ' +
+              'section+div{overflow:hidden} section+*>*{position:relative!important} article{border-bottom:1px solid!important} ' +
+              'article section+div>ul>div>li{padding:6px 2px 12px!important}',
             }))
             .then(() => page.addStyleTag({
               content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',
@@ -149,7 +150,7 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
               time = document.querySelector('article section~div>a>time');
               if (time) {
                 time.innerHTML = time.title + ' ' + new Date(time.dateTime).toLocaleTimeString().slice(0, -3);
-                time.parentElement.parentElement.style.margin = '-24px 0 12px';
+                time.parentElement.parentElement.style.margin = '-24px 2px 12px';
               }
             }))
             .then(() => chainPromises(morePostProcessings.map(func => () => func(page))))

文件差异内容过多而无法显示
+ 14 - 0
src/webshot_test.js


部分文件因为文件数量过多而无法显示