Skip to content

Commit

Permalink
Merge branch 'release/1.10.6' into released
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui committed Feb 2, 2020
2 parents 19dabac + b0f26f8 commit 0c33d19
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "maskbook",
"license": "AGPL-3.0-or-later",
"version": "1.10.5",
"version": "1.10.6",
"private": true,
"engines": {
"node": ">=13.2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/chrome-manifest",
"name": "Maskbook",
"version": "1.10.5",
"version": "1.10.6",
"manifest_version": 2,
"web_accessible_resources": ["*.css", "*.js", "*.jpg", "*.png"],
"permissions": ["storage", "downloads", "webNavigation", "activeTab"],
Expand Down
7 changes: 6 additions & 1 deletion src/social-network-provider/twitter.com/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ export const twitterEncoding = {
])}`,
payloadDecoder: (text: string) => {
const links: { raw: string; protocol: string; encoded: string }[] = anchorme(text, { list: true })
let links_ = links.filter(x => x.raw.endsWith('%40'))[0]?.raw
let links_ = links
.map(l => ({
...l,
raw: l.raw.replace(/…$/, ''),
}))
.filter(x => x.raw.endsWith('%40'))[0]?.raw
try {
links_ = new URL(links_).pathname
.slice(1)
Expand Down
34 changes: 28 additions & 6 deletions src/social-network-provider/twitter.com/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ import Services from '../../../extension/service'
* handle: "MisakaMirror"
* }
*/
const parseNameArea = (t: string) => {
const r = regexMatch(t, /((.+\s*)*)@(.+)/, null)!
const parseNameArea = (nameArea: string) => {
const result = regexMatch(nameArea, /([^@]*)@(.+)/, null)

if (!result) {
return {
name: '',
handle: '',
}
}
return {
name: r[1].replace(/\n+/g, ''),
handle: r[3].replace(/\n+/g, ''),
name: result[1].replace(/\n+/g, ''),
handle: result[2].replace(/\n+/g, ''),
}
}

Expand Down Expand Up @@ -92,10 +99,25 @@ export const postNameParser = (node: HTMLElement) => {
return parseNameArea(notNullable(node.querySelector<HTMLTableCellElement>('.user-info')).innerText)
} else {
const tweetElement = node.querySelector('[data-testid="tweet"]') ?? node
const nameInNoramlTweet = tweetElement.children[1]?.querySelector<HTMLAnchorElement>('a')?.innerText
const nameInUniqueAnchorTweet =
tweetElement.children[1]?.querySelector<HTMLAnchorElement>('a[aria-haspopup="false"]')?.innerText ?? ''
const nameInDoubleAnchorsTweet = Array.from(
tweetElement.children[1]?.querySelectorAll<HTMLAnchorElement>('a[aria-haspopup="false"]') ?? [],
)
.map(a => a.textContent)
.join('')
const nameInQuoteTweet = tweetElement.children[0]?.querySelector<HTMLDivElement>('[aria-haspopup="false"]')
?.innerText
return parseNameArea(notNullable(nameInNoramlTweet || nameInQuoteTweet))

return (
[nameInUniqueAnchorTweet, nameInDoubleAnchorsTweet, nameInQuoteTweet]
.filter(Boolean)
.map(n => parseNameArea(n!))
.find(r => r.name && r.handle) ?? {
name: '',
handle: '',
}
)
}
}

Expand Down

0 comments on commit 0c33d19

Please sign in to comment.