Skip to content

Commit

Permalink
增加ip属地渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
jooooock committed Sep 24, 2024
1 parent 5e2a3ae commit 30f7439
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/ArticleItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function download(link: string, title: string) {
const zip = await packHTMLAssets(fullHTML, title)
const blob = await zip.generateAsync({type: 'blob'})
saveAs(blob, title)
saveAs(blob, title + '.zip')
await uploadProxy()
} catch (e: any) {
Expand Down
24 changes: 24 additions & 0 deletions utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export async function downloadArticleHTMLs(articles: DownloadableArticle[], call
return results
}


/**
* 打包 html 中的资源
* @param html
Expand All @@ -145,6 +146,29 @@ export async function packHTMLAssets(html: string, title: string, zip?: JSZip) {
el.remove()
})

// 渲染ip属地
function getIpWoridng(ipConfig: any) {
let ipWording = '';
if (parseInt(ipConfig.countryId, 10) === 156) {
ipWording = ipConfig.provinceName;
} else if (ipConfig.countryId) {
ipWording = ipConfig.countryName;
}
return ipWording;
}
const ipWrp = document.getElementById('js_ip_wording_wrp')!
const ipWording = document.getElementById('js_ip_wording')!
const ipWordingMatchResult = html.match(/window\.ip_wording = (?<data>{\s+countryName: '[^']+',[^}]+})/s)
if (ipWordingMatchResult && ipWordingMatchResult.groups && ipWordingMatchResult.groups.data) {
const json = ipWordingMatchResult.groups.data
eval('window.ip_wording = ' + json)
const ipWordingDisplay = getIpWoridng((window as any).ip_wording)
if (ipWordingDisplay !== '') {
ipWording.innerHTML = ipWordingDisplay;
ipWrp.style.display = 'inline-block';
}
}


zip.folder('assets')

Expand Down

0 comments on commit 30f7439

Please sign in to comment.