mirror of
https://github.com/webxoss/wixoss-fetch.git
synced 2024-11-20 05:49:55 +01:00
Robustness of illust
This commit is contained in:
parent
eeeb72b6cd
commit
36a97064d3
3 changed files with 55 additions and 53 deletions
103
dist/index.js
vendored
103
dist/index.js
vendored
|
@ -374,9 +374,9 @@ const Tar = require('tar-js')
|
||||||
|
|
||||||
/* utils */
|
/* utils */
|
||||||
const toArr = obj => {
|
const toArr = obj => {
|
||||||
if (!obj) return []
|
if (!obj) return []
|
||||||
if (typeof obj === 'string') return []
|
if (typeof obj === 'string') return []
|
||||||
return Array.prototype.slice.call(obj,0)
|
return Array.prototype.slice.call(obj,0)
|
||||||
}
|
}
|
||||||
const $fetch = (...arg) => {
|
const $fetch = (...arg) => {
|
||||||
return fetch(arg).then(res => {
|
return fetch(arg).then(res => {
|
||||||
|
@ -390,24 +390,24 @@ const stringToUint8 = str => {
|
||||||
|
|
||||||
/* parser */
|
/* parser */
|
||||||
function toCardType(str) {
|
function toCardType(str) {
|
||||||
let map = {
|
let map = {
|
||||||
'ルリグ': 'LRIG',
|
'ルリグ': 'LRIG',
|
||||||
'アーツ': 'ARTS',
|
'アーツ': 'ARTS',
|
||||||
'シグニ': 'SIGNI',
|
'シグニ': 'SIGNI',
|
||||||
'スペル': 'SPELL',
|
'スペル': 'SPELL',
|
||||||
}
|
}
|
||||||
return map[str] || str
|
return map[str] || str
|
||||||
}
|
}
|
||||||
function toColor(str) {
|
function toColor(str) {
|
||||||
let map = {
|
let map = {
|
||||||
'白': 'WHITE',
|
'白': 'WHITE',
|
||||||
'黒': 'BLACK',
|
'黒': 'BLACK',
|
||||||
'赤': 'RED',
|
'赤': 'RED',
|
||||||
'青': 'BLUE',
|
'青': 'BLUE',
|
||||||
'緑': 'GREEN',
|
'緑': 'GREEN',
|
||||||
'無': 'COLORLESS',
|
'無': 'COLORLESS',
|
||||||
}
|
}
|
||||||
return map[str] || str
|
return map[str] || str
|
||||||
}
|
}
|
||||||
function toCardText(el) {
|
function toCardText(el) {
|
||||||
let text = toArr(el.childNodes).map(node => {
|
let text = toArr(el.childNodes).map(node => {
|
||||||
|
@ -424,48 +424,49 @@ function toCardText(el) {
|
||||||
}).join('')
|
}).join('')
|
||||||
}
|
}
|
||||||
function toFaq(el) {
|
function toFaq(el) {
|
||||||
let faq = {}
|
let faq = {}
|
||||||
faq.q = el.querySelector('.card_ruleFAQ_q').textContent.replace(/^\s+/,'').replace(/\s+$/,'')
|
faq.q = el.querySelector('.card_ruleFAQ_q').textContent.replace(/^\s+/,'').replace(/\s+$/,'')
|
||||||
faq.a = el.querySelector('.card_ruleFAQ_a').textContent.replace(/^\s+/,'').replace(/\s+$/,'')
|
faq.a = el.querySelector('.card_ruleFAQ_a').textContent.replace(/^\s+/,'').replace(/\s+$/,'')
|
||||||
return faq
|
return faq
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function toInfo(doc, id) {
|
function toInfo(doc, id) {
|
||||||
let info = {}
|
let info = {}
|
||||||
info.pid = id
|
info.pid = id
|
||||||
info.timestamp = Date.now()
|
info.timestamp = Date.now()
|
||||||
info.wxid = doc.querySelector('.card_detail_title > p').textContent
|
info.wxid = doc.querySelector('.card_detail_title > p').textContent
|
||||||
info.name = doc.querySelector('.card_detail_title > h3').firstChild.textContent
|
info.name = doc.querySelector('.card_detail_title > h3').firstChild.textContent
|
||||||
info.kana = doc.querySelector('.card_detail_kana').textContent.slice(1,-1)
|
info.kana = doc.querySelector('.card_detail_kana').textContent.slice(1,-1)
|
||||||
info.rarity = doc.querySelector('.card_rarity').textContent.replace(/\s/g,'')
|
info.rarity = doc.querySelector('.card_rarity').textContent.replace(/\s/g,'')
|
||||||
|
|
||||||
let trs = doc.querySelectorAll('.card_date_box tr')
|
let trs = doc.querySelectorAll('.card_date_box tr')
|
||||||
// info.cardType = toCardType(trs[0].children[1].textContent)
|
// info.cardType = toCardType(trs[0].children[1].textContent)
|
||||||
info.cardType = trs[0].children[1].textContent
|
info.cardType = trs[0].children[1].textContent
|
||||||
info.class = trs[0].children[3].textContent
|
info.class = trs[0].children[3].textContent
|
||||||
// info.color = toColor(trs[1].children[1].textContent)
|
// info.color = toColor(trs[1].children[1].textContent)
|
||||||
info.color = trs[1].children[1].textContent
|
info.color = trs[1].children[1].textContent
|
||||||
info.level = trs[1].children[3].textContent
|
info.level = trs[1].children[3].textContent
|
||||||
info.growCost = trs[2].children[1].textContent
|
info.growCost = trs[2].children[1].textContent
|
||||||
info.cost = trs[2].children[3].textContent
|
info.cost = trs[2].children[3].textContent
|
||||||
info.limit = trs[3].children[1].textContent
|
info.limit = trs[3].children[1].textContent
|
||||||
info.power = trs[3].children[3].textContent
|
info.power = trs[3].children[3].textContent
|
||||||
info.limiting = trs[4].children[1].textContent
|
info.limiting = trs[4].children[1].textContent
|
||||||
info.guard = trs[4].children[3].textContent
|
info.guard = trs[4].children[3].textContent
|
||||||
|
|
||||||
let el = doc.querySelector('.card_skill')
|
let el = doc.querySelector('.card_skill')
|
||||||
info.cardSkill = el? toCardText(el) : ''
|
info.cardSkill = el? toCardText(el) : ''
|
||||||
|
|
||||||
info.cardTexts = toArr(doc.querySelectorAll('.card_text:not(.card_skill)')).map(toCardText)
|
info.cardTexts = toArr(doc.querySelectorAll('.card_text:not(.card_skill)')).map(toCardText)
|
||||||
|
|
||||||
// info.imgUrl = domain + doc.querySelector('.card_img > img').getAttribute('src')
|
// info.imgUrl = domain + doc.querySelector('.card_img > img').getAttribute('src')
|
||||||
info.imgUrl = doc.querySelector('.card_img > img').getAttribute('src')
|
info.imgUrl = doc.querySelector('.card_img > img').getAttribute('src')
|
||||||
info.illust = doc.querySelector('.card_img').textContent.match(/Illust (.*)$/)[1]
|
info.illust = (doc.querySelector('.card_img').textContent.match(/Illust (.*)$/) || [])[1] || ''
|
||||||
|
if (!info.illust) console.warn(`${info.pid}: no illust!`)
|
||||||
|
|
||||||
info.faqs = toArr(doc.querySelectorAll('.card_FAQ > p')).map(toFaq)
|
info.faqs = toArr(doc.querySelectorAll('.card_FAQ > p')).map(toFaq)
|
||||||
|
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fetch */
|
/* fetch */
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -92,7 +92,8 @@ function toInfo(doc, id) {
|
||||||
|
|
||||||
// info.imgUrl = domain + doc.querySelector('.card_img > img').getAttribute('src')
|
// info.imgUrl = domain + doc.querySelector('.card_img > img').getAttribute('src')
|
||||||
info.imgUrl = doc.querySelector('.card_img > img').getAttribute('src')
|
info.imgUrl = doc.querySelector('.card_img > img').getAttribute('src')
|
||||||
info.illust = doc.querySelector('.card_img').textContent.match(/Illust (.*)$/)[1]
|
info.illust = (doc.querySelector('.card_img').textContent.match(/Illust (.*)$/) || [])[1] || ''
|
||||||
|
if (!info.illust) console.warn(`${info.pid}: no illust!`)
|
||||||
|
|
||||||
info.faqs = toArr(doc.querySelectorAll('.card_FAQ > p')).map(toFaq)
|
info.faqs = toArr(doc.querySelectorAll('.card_FAQ > p')).map(toFaq)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue