|
@@ -137,7 +137,7 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
.then(() => page.addStyleTag({content:
|
|
|
'nav,footer,main>*>*+*,header div>[class$=" "]>[class]+div,main button,canvas,main section,main section+div>ul>:not(div),' +
|
|
|
'main section+div>ul>div [role="button"],section+div h2,article>*>:first-child+*>*>:first-child+*{display:none!important} ' +
|
|
|
- 'section+div{overflow:hidden} section+*>*{position:relative!important} article{border-bottom:1px solid!important} ' +
|
|
|
+ 'section+div{overflow:hidden} section+*>*{position:relative!important} main>div{margin-bottom:0!important}' +
|
|
|
'main section+div>ul{width:auto!important;padding:16px 0!important} main section+div>ul>div>li{padding:6px 2px 12px!important}',
|
|
|
}))
|
|
|
.then(() => page.addStyleTag({content:
|
|
@@ -159,47 +159,21 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
}))
|
|
|
.then(() => chainPromises(morePostProcessings.map(func => () => func(page))))
|
|
|
.then(() => promisify(setTimeout)(getTimeout()))
|
|
|
- .then(() => page.screenshot())
|
|
|
+ .then(() => page.$('article').then(article => article.screenshot()))
|
|
|
.then(screenshot => {
|
|
|
new PNG({
|
|
|
filterType: 4,
|
|
|
deflateLevel: 0,
|
|
|
}).on('parsed', function () {
|
|
|
- const idx = (x: number, y: number) => (this.width * y + x) << 2;
|
|
|
- let boundary: number = null;
|
|
|
- for (let y = this.height - 1; y > this.height - 3840; y -= zoomFactor) {
|
|
|
- if (
|
|
|
- this.data[idx(zoomFactor, y)] <= 38 &&
|
|
|
- this.data[idx(zoomFactor, y)] === this.data[idx(this.width - zoomFactor, y)] &&
|
|
|
- this.data[idx(zoomFactor, y + zoomFactor)] === this.data[idx(zoomFactor, y - 2 * zoomFactor)]
|
|
|
- ) {
|
|
|
- boundary = y - 1;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (boundary !== null) {
|
|
|
- logger.info(`found boundary at ${boundary}, cropping image`);
|
|
|
- this.data = this.data.slice(0, idx(this.width, boundary));
|
|
|
- this.height = boundary;
|
|
|
-
|
|
|
- sharpToFile(jpeg(this.pack())).then(path => {
|
|
|
- logger.info(`finished webshot for ${url}`);
|
|
|
- resolve({path, boundary});
|
|
|
- });
|
|
|
- } else if (height >= 8 * 1920) {
|
|
|
- logger.warn('too large, consider as a bug, returning');
|
|
|
- sharpToFile(jpeg(this.pack())).then(path => {
|
|
|
- resolve({path, boundary: 0});
|
|
|
- });
|
|
|
- } else {
|
|
|
- logger.info('unable to find boundary, try shooting a larger image');
|
|
|
- resolve({path: '', boundary});
|
|
|
- }
|
|
|
+ sharpToFile(jpeg(this.pack())).then(path => {
|
|
|
+ logger.info(`finished webshot for ${url}`);
|
|
|
+ resolve({path, boundary: this.height});
|
|
|
+ });
|
|
|
}).parse(screenshot);
|
|
|
})
|
|
|
.catch(err => {
|
|
|
if (err instanceof Error && err.name !== 'TimeoutError') throw err;
|
|
|
- logger.error(`error shooting webshot for ${url}, could not load web page of tweet`);
|
|
|
+ logger.error(`error shooting webshot for ${url}, could not load web page of post`);
|
|
|
resolve({path: '', boundary: 0});
|
|
|
})
|
|
|
.finally(() => { page.close(); });
|
|
@@ -209,7 +183,7 @@ class Webshot extends CallableInstance<[LazyMediaItem[], (...args) => void, numb
|
|
|
});
|
|
|
return promise.then(data => {
|
|
|
if (data.boundary === null) {
|
|
|
- return this.renderWebshot(url, height + 3840, webshotDelay, ...morePostProcessings);
|
|
|
+ return this.renderWebshot(url, height + 1920, webshotDelay, ...morePostProcessings);
|
|
|
} else return data.path;
|
|
|
}).catch(error => this.reconnect(error)
|
|
|
.then(() => this.renderWebshot(url, height, webshotDelay, ...morePostProcessings))
|
|
@@ -274,7 +248,7 @@ 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, 3840, webshotDelay, page =>
|
|
|
+ promise = promise.then(() => this.renderWebshot(url, 1920, webshotDelay, page =>
|
|
|
// display full name
|
|
|
page.addStyleTag({content:
|
|
|
'header>div>div+div{font-size:12px; line-height:15px; padding-top:0!important}' +
|