|
@@ -94,7 +94,10 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
throw error;
|
|
|
});
|
|
|
|
|
|
- private renderWebshot = (url: string, height: number, webshotDelay: number): Promise<string> => {
|
|
|
+ private renderWebshot = (
|
|
|
+ url: string, height: number, webshotDelay: number,
|
|
|
+ ...morePostProcessings: ((page: Page) => Promise<any>)[]
|
|
|
+ ): Promise<string> => {
|
|
|
temp.track();
|
|
|
const jpeg = (data: Readable) => data.pipe(sharp()).jpeg({quality: 90, trellisQuantisation: true});
|
|
|
const sharpToFile = (pic: sharp.Sharp) => new Promise<string>(resolve => {
|
|
@@ -129,7 +132,7 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
logger.warn(`navigation timed out at ${getTimerTime()} ms`);
|
|
|
return null;
|
|
|
})
|
|
|
- // hide header, "more options" button, like and retweet count
|
|
|
+ // hide header, footer, "more options" button, like and share count, carousel navigator, and comments
|
|
|
.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 button,canvas{display:none!important} ' +
|
|
@@ -138,6 +141,7 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
.then(() => page.addStyleTag({
|
|
|
content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',
|
|
|
}))
|
|
|
+ // display absolute date and time
|
|
|
.then(() => page.evaluate(() => {
|
|
|
let time: HTMLTimeElement;
|
|
|
time = document.querySelector('div>div>time');
|
|
@@ -148,6 +152,7 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
time.parentElement.parentElement.style.margin = '-24px 0 12px';
|
|
|
}
|
|
|
}))
|
|
|
+ .then(() => chainPromises(morePostProcessings.map(func => () => func(page))))
|
|
|
.then(() => page.screenshot())
|
|
|
.then(screenshot => {
|
|
|
new PNG({
|
|
@@ -197,10 +202,11 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
.catch(reject);
|
|
|
});
|
|
|
return promise.then(data => {
|
|
|
- if (data.boundary === null) return this.renderWebshot(url, height + 1920, webshotDelay);
|
|
|
- else return data.path;
|
|
|
+ if (data.boundary === null) {
|
|
|
+ return this.renderWebshot(url, height + 1920, webshotDelay, ...morePostProcessings);
|
|
|
+ } else return data.path;
|
|
|
}).catch(error => this.reconnect(error)
|
|
|
- .then(() => this.renderWebshot(url, height, webshotDelay))
|
|
|
+ .then(() => this.renderWebshot(url, height, webshotDelay, ...morePostProcessings))
|
|
|
);
|
|
|
};
|
|
|
|
|
@@ -262,7 +268,14 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
// invoke webshot
|
|
|
if (this.mode === 0) {
|
|
|
const url = linkBuilder({postUrlSegment: item.code});
|
|
|
- promise = promise.then(() => this.renderWebshot(url, 1920, webshotDelay))
|
|
|
+ promise = promise.then(() => this.renderWebshot(url, 1920, webshotDelay, page =>
|
|
|
+ // display full name
|
|
|
+ page.addStyleTag({content:
|
|
|
+ 'header div div div *{text-align:left!important} header div div div a::after{' +
|
|
|
+ `content:"${item.user.full_name}";` +
|
|
|
+ 'display:block; font-size:smaller; color: #8e8e8e; line-height:1.25}',
|
|
|
+ })
|
|
|
+ ))
|
|
|
.then(fileurl => {
|
|
|
if (fileurl) return Message.Image(fileurl);
|
|
|
return author + text;
|
|
@@ -294,7 +307,7 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
if (1 - this.mode % 2) promise = promise.then(() => {
|
|
|
if (item.carousel_media) {
|
|
|
return chainPromises(item.carousel_media.map(carouselItem =>
|
|
|
- fetchBestCandidate(
|
|
|
+ () => fetchBestCandidate(
|
|
|
(carouselItem as unknown as MediaItem).video_versions ||
|
|
|
carouselItem.image_versions2.candidates,
|
|
|
type(carouselItem)
|