Selaa lähdekoodia

better time format on webshots

Mike L 4 vuotta sitten
vanhempi
commit
922d2170b8
4 muutettua tiedostoa jossa 25 lisäystä ja 2 poistoa
  1. 1 0
      dist/twitter.js
  2. 12 1
      dist/webshot.js
  3. 1 0
      src/twitter.ts
  4. 11 1
      src/webshot.ts

+ 1 - 0
dist/twitter.js

@@ -191,6 +191,7 @@ class default_1 {
                                         else
                                             return itemIds;
                                     }
+                                    logger.info('unable to find a smaller id than target, trying on next page...');
                                     return null;
                                 });
                             };

+ 12 - 1
dist/webshot.js

@@ -97,11 +97,22 @@ class Webshot extends CallableInstance {
                         return null;
                     })
                         .then(() => page.addStyleTag({ content: 'nav,footer,header+div,header+div+div>div>div+div,header div div div+div,' +
-                            'article section,article section+div>ul>:not(div),article section+div~div,article button,canvas{display:none!important} ' +
+                            'article section,article section+div>ul>:not(div),article button,canvas{display:none!important} ' +
                             'section+div{overflow:hidden} section+*>*{position:relative!important} article{border-bottom:1px solid!important}',
                     }))
                         .then(() => page.addStyleTag({
                         content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',
+                    }))
+                        .then(() => page.evaluate(() => {
+                        let time;
+                        time = document.querySelector('div>div>time');
+                        if (time)
+                            time.parentElement.parentElement.style.display = 'none';
+                        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';
+                        }
                     }))
                         .then(() => page.screenshot())
                         .then(screenshot => {

+ 1 - 0
src/twitter.ts

@@ -308,6 +308,7 @@ export default class {
                       if (id && BigNumOps.compare(id, targetId) > 0) itemIds.push(id);
                       else return itemIds;
                     }
+                    logger.info('unable to find a smaller id than target, trying on next page...');
                     return null; // has more
                   });
                 };

+ 11 - 1
src/webshot.ts

@@ -132,12 +132,22 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
             // hide header, "more options" button, like and retweet count
             .then(() => page.addStyleTag({content:
               'nav,footer,header+div,header+div+div>div>div+div,header div div div+div,' +
-              'article section,article section+div>ul>:not(div),article section+div~div,article button,canvas{display:none!important} ' +
+              'article section,article section+div>ul>:not(div),article button,canvas{display:none!important} ' +
               'section+div{overflow:hidden} section+*>*{position:relative!important} article{border-bottom:1px solid!important}',
             }))
             .then(() => page.addStyleTag({
               content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',
             }))
+            .then(() => page.evaluate(() => {
+              let time: HTMLTimeElement;
+              time = document.querySelector('div>div>time');
+              if (time) time.parentElement.parentElement.style.display = 'none';
+              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';
+              }
+            }))
             .then(() => page.screenshot())
             .then(screenshot => {
               new PNG({