|
@@ -261,59 +261,56 @@ class Webshot extends CallableInstance {
|
|
|
});
|
|
|
if (this.mode === 0) {
|
|
|
const url = `https://mobile.twitter.com/${twi.user.screen_name}/status/${twi.id_str}`;
|
|
|
- promise = promise.then(() => this.renderWebshot(url, 1920, webshotDelay, (_, handle) => {
|
|
|
- const extendEntity = (cardImg) => {
|
|
|
- var _a, _b;
|
|
|
- originTwi.extended_entities = Object.assign(Object.assign({}, originTwi.extended_entities), { media: [
|
|
|
- ...(_b = (_a = originTwi.extended_entities) === null || _a === void 0 ? void 0 : _a.media) !== null && _b !== void 0 ? _b : [],
|
|
|
- cardImg,
|
|
|
- ] });
|
|
|
- };
|
|
|
- const truncateLongThread = (atId) => {
|
|
|
- if (!atId)
|
|
|
- return;
|
|
|
- logger.info(`thread too long, truncating at tweet ${atId}...`);
|
|
|
- truncatedAt = atId;
|
|
|
- };
|
|
|
- return handle.evaluate(div => {
|
|
|
- try {
|
|
|
- const selector = '[data-testid="tweet"] :nth-child(2)>:first-child a';
|
|
|
- const getProfileUrl = () => (div.querySelector(selector) || { href: '' }).href;
|
|
|
- const ownerProfileUrl = getProfileUrl();
|
|
|
- const bottom = div;
|
|
|
- while (div = div.previousElementSibling) {
|
|
|
- if (getProfileUrl() !== ownerProfileUrl || div === bottom.previousElementSibling)
|
|
|
- continue;
|
|
|
- const top = document.documentElement.scrollTop = window.scrollY + div.getBoundingClientRect().top;
|
|
|
- if (top > 10)
|
|
|
- return div.querySelector('article a[aria-label]').href.replace(/.*\/status\//, '');
|
|
|
- }
|
|
|
+ const extendEntity = (cardImg) => {
|
|
|
+ var _a, _b;
|
|
|
+ originTwi.extended_entities = Object.assign(Object.assign({}, originTwi.extended_entities), { media: [
|
|
|
+ ...(_b = (_a = originTwi.extended_entities) === null || _a === void 0 ? void 0 : _a.media) !== null && _b !== void 0 ? _b : [],
|
|
|
+ cardImg,
|
|
|
+ ] });
|
|
|
+ };
|
|
|
+ const truncateLongThread = (atId) => {
|
|
|
+ if (!atId)
|
|
|
+ return;
|
|
|
+ logger.info(`thread too long, truncating at tweet ${atId}...`);
|
|
|
+ truncatedAt = atId;
|
|
|
+ };
|
|
|
+ promise = promise.then(() => this.renderWebshot(url, 1920, webshotDelay, (_, tweetHandle) => tweetHandle.evaluate(div => {
|
|
|
+ try {
|
|
|
+ const selector = '[data-testid="tweet"] :nth-child(2)>:first-child a';
|
|
|
+ const getProfileUrl = () => (div.querySelector(selector) || { href: '' }).href;
|
|
|
+ const ownerProfileUrl = getProfileUrl();
|
|
|
+ const bottom = div;
|
|
|
+ while (div = div.previousElementSibling) {
|
|
|
+ if (getProfileUrl() !== ownerProfileUrl || div === bottom.previousElementSibling)
|
|
|
+ continue;
|
|
|
+ const top = document.documentElement.scrollTop = window.scrollY + div.getBoundingClientRect().top;
|
|
|
+ if (top > 10)
|
|
|
+ return div.querySelector('article a[aria-label]').href.replace(/.*\/status\//, '');
|
|
|
}
|
|
|
- catch (_a) { }
|
|
|
- document.documentElement.scrollTop = 0;
|
|
|
- }).then(truncateLongThread)
|
|
|
- .then(() => handle.evaluate(div => {
|
|
|
- const cardImg = div.querySelector('div[data-testid^="card.layout"][data-testid$=".media"] img');
|
|
|
- if (typeof (cardImg === null || cardImg === void 0 ? void 0 : cardImg.getAttribute('src')) === 'string') {
|
|
|
- const match = /^(.*\/card_img\/(\d+)\/.+\?format=.*)&name=/.exec(cardImg === null || cardImg === void 0 ? void 0 : cardImg.getAttribute('src'));
|
|
|
- if (match) {
|
|
|
- const [media_url_https, id_str] = match.slice(1);
|
|
|
- return {
|
|
|
- media_url: media_url_https.replace(/^https/, 'http'),
|
|
|
- media_url_https,
|
|
|
- url: '',
|
|
|
- display_url: '',
|
|
|
- expanded_url: '',
|
|
|
- type: 'photo',
|
|
|
- id: Number(id_str),
|
|
|
- id_str,
|
|
|
- sizes: undefined,
|
|
|
- };
|
|
|
- }
|
|
|
+ }
|
|
|
+ catch (_a) { }
|
|
|
+ document.documentElement.scrollTop = 0;
|
|
|
+ }).then(truncateLongThread), (_, tweetHandle) => tweetHandle.evaluate(div => {
|
|
|
+ const cardImg = div.querySelector('div[data-testid^="card.layout"][data-testid$=".media"] img');
|
|
|
+ if (typeof (cardImg === null || cardImg === void 0 ? void 0 : cardImg.getAttribute('src')) === 'string') {
|
|
|
+ const match = /^(.*\/card_img\/(\d+)\/.+\?format=.*)&name=/.exec(cardImg === null || cardImg === void 0 ? void 0 : cardImg.getAttribute('src'));
|
|
|
+ if (match) {
|
|
|
+ const [media_url_https, id_str] = match.slice(1);
|
|
|
+ return {
|
|
|
+ media_url: media_url_https.replace(/^https/, 'http'),
|
|
|
+ media_url_https,
|
|
|
+ url: '',
|
|
|
+ display_url: '',
|
|
|
+ expanded_url: '',
|
|
|
+ type: 'photo',
|
|
|
+ id: Number(id_str),
|
|
|
+ id_str,
|
|
|
+ sizes: undefined,
|
|
|
+ };
|
|
|
}
|
|
|
- })).then(cardImg => { if (cardImg)
|
|
|
- extendEntity(cardImg); });
|
|
|
- }))
|
|
|
+ }
|
|
|
+ }).then(cardImg => { if (cardImg)
|
|
|
+ extendEntity(cardImg); })))
|
|
|
.then(fileurl => {
|
|
|
if (fileurl)
|
|
|
return koishi_1.Message.Image(fileurl);
|