Skip to content

Commit bb39f96

Browse files
authored
Merge pull request #260 from molanp/patch-1
修复推文页面的推文id获取
2 parents 080c11b + a149d8a commit bb39f96

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

twitter-media-downloader/twitter-media-downloader.user.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,11 @@ const TMD = (function () {
342342
'div[aria-labelledby]>div:first-child>div[role="button"][tabindex="0"]' //for audio (experimental)
343343
]
344344
let media = article.querySelector(media_selector.join(','))
345+
let current_tweet_id = document.location.href.includes('/status/')
346+
? document.location.href.split('/status/').pop().split('/').shift()
347+
: undefined
345348
if (media) {
346-
let status_id = article.querySelector('a[href*="/status/"]').href.split('/status/').pop().split('/').shift()
349+
let status_id = current_tweet_id || article.querySelector('a[href*="/status/"]').href.split('/status/').pop().split('/').shift()
347350
let btn_group = article.querySelector('div[role="group"]:last-of-type, ul.tweet-actions, ul.tweet-detail-actions')
348351
let btn_share = Array.from(btn_group.querySelectorAll(':scope>div>div, li.tweet-action-item>a, li.tweet-detail-action-item>a')).pop().parentNode
349352
let btn_down = btn_share.cloneNode(true)
@@ -367,7 +370,7 @@ const TMD = (function () {
367370
}
368371
let imgs = article.querySelectorAll('a[href*="/photo/"]')
369372
if (imgs.length > 1) {
370-
let status_id = article.querySelector('a[href*="/status/"]').href.split('/status/').pop().split('/').shift()
373+
let status_id = current_tweet_id || article.querySelector('a[href*="/status/"]').href.split('/status/').pop().split('/').shift()
371374
let btn_group = article.querySelector('div[role="group"]:last-of-type')
372375
let btn_share = Array.from(btn_group.querySelectorAll(':scope>div>div')).pop().parentNode
373376
imgs.forEach(img => {
@@ -593,7 +596,7 @@ const TMD = (function () {
593596
info.url = media.type == 'photo' ? media.media_url_https + ':orig' : media.video_info.variants.filter(n => n.content_type == 'video/mp4').sort((a, b) => b.bitrate - a.bitrate)[0].url
594597
info.file = info.url.split('/').pop().split(/[:?]/).shift()
595598
info['file-name'] = info.file.split('.').shift()
596-
info['file-ext'] = info.file.split('.').pop()
599+
info['file-ext'] = info.file.split('.').pop();
597600
info['file-type'] = media.type.replace('animated_', '')
598601
info.out = (out.replace(/\.?\{file-ext\}/, '') + ((medias.length > 1 || index) && !out.match('{file-name}') ? '-' + (index ? index - 1 : i) : '') + '.{file-ext}').replace(/\{([^{}:]+)(:[^{}]+)?\}/g, (match, name) => info[name])
599602
return { url: info.url, name: info.out }

0 commit comments

Comments
 (0)