|
@@ -103,7 +103,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
.then(() => page.goto(url, {waitUntil: 'load', timeout: getTimeout()}))
|
|
|
// hide header, "more options" button, like and retweet count
|
|
|
.then(() => page.addStyleTag({
|
|
|
- content: 'header{display:none!important}path[d=\'M20.207 7.043a1 1 0 0 0-1.414 0L12 13.836 5.207 7.043a1 1 0 0 0-1.414 1.414l7.5 7.5a.996.996 0 0 0 1.414 0l7.5-7.5a1 1 0 0 0 0-1.414z\'],div[role=\'button\']{display: none;}',
|
|
|
+ content: 'header{display:none!important}div[role=\'button\'],[data-testid="tweet"]+*>[class*=" "]+*{display:none}',
|
|
|
}))
|
|
|
.then(() => page.addStyleTag({
|
|
|
content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',
|
|
@@ -167,7 +167,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
|
const idx = (x: number, y: number) => (this.width * y + x) << 2;
|
|
|
let boundary: number = null;
|
|
|
- let x = zoomFactor * 2;
|
|
|
+ const x = zoomFactor * 2;
|
|
|
for (let y = 0; y < this.height; y += zoomFactor) {
|
|
|
if (
|
|
|
this.data[idx(x, y)] !== 255 &&
|
|
@@ -187,44 +187,6 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
|
|
|
this.data = this.data.slice(0, idx(this.width, boundary));
|
|
|
this.height = boundary;
|
|
|
|
|
|
- boundary = null;
|
|
|
- x = Math.floor(16 * zoomFactor);
|
|
|
- let flag = false;
|
|
|
- let cnt = 0;
|
|
|
- for (let y = this.height - 1 - zoomFactor; y >= 0; y -= zoomFactor) {
|
|
|
- if ((this.data[idx(x, y)] === 255) === flag) {
|
|
|
- cnt++;
|
|
|
- flag = !flag;
|
|
|
- } else continue;
|
|
|
-
|
|
|
- // line above the "comment", "retweet", "like", "share" button row
|
|
|
- if (cnt === 2) {
|
|
|
- boundary = y + 1;
|
|
|
- }
|
|
|
-
|
|
|
- // if there are a "retweet" count and "like" count row, this will be the line above it
|
|
|
- if (cnt === 4) {
|
|
|
- const b = y + 1;
|
|
|
- if (Math.abs(this.height - boundary - (boundary - b)) <= 3 * zoomFactor) {
|
|
|
- boundary = b;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // if "retweet" count and "like" count are two rows, this will be the line above the first
|
|
|
- if (cnt === 6) {
|
|
|
- const c = y + 1;
|
|
|
- if (Math.abs(this.height - boundary - 2 * (boundary - c)) <= 3 * zoomFactor) {
|
|
|
- boundary = c;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (boundary !== null) {
|
|
|
- logger.info(`found boundary at ${boundary}, trimming 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});
|