Skip to content

Commit

Permalink
chore: 调整代码格式规则
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Nov 5, 2021
1 parent 494eac0 commit c9158b9
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 124 deletions.
9 changes: 5 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ module.exports = {
'react-app',
'standard',
'standard-jsx',
'standard-react'
'standard-react',
],
globals: {
chrome: 'readonly'
chrome: 'readonly',
},
ignorePatterns: ['build', 'tmp'],
rules: {
'react/prop-types': 0
}
'react/prop-types': 0,
'comma-dangle': ['error', 'always-multiline'],
},
}
12 changes: 6 additions & 6 deletions scripts/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ for (const entryName in config.entry) {
if (['popup', 'background'].indexOf(entryName) > -1) {
config.entry[entryName] = [
'webpack/hot/dev-server',
`webpack-dev-server/client?hot=true&hostname=localhost&port=${PORT}`
`webpack-dev-server/client?hot=true&hostname=localhost&port=${PORT}`,
].concat(config.entry[entryName])
}
}
Expand All @@ -30,18 +30,18 @@ const server = new WebpackDevServer(
host: 'localhost',
port: PORT,
static: {
directory: path.join(__dirname, '../build')
directory: path.join(__dirname, '../build'),
},
devMiddleware: {
publicPath: `http://localhost:${PORT}/`,
writeToDisk: true
writeToDisk: true,
},
headers: {
'Access-Control-Allow-Origin': '*'
'Access-Control-Allow-Origin': '*',
},
allowedHosts: 'all'
allowedHosts: 'all',
},
compiler
compiler,
)

if (process.env.NODE_ENV === 'development' && module.hot) {
Expand Down
54 changes: 27 additions & 27 deletions src/background/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ function createRequester () {
method = 'post',
baseURL = DOMAIN,
url,
data
data,
} = reqInfo
url = baseURL + url
logger.verbose('api.fetch', url, data)
const res = await fetch(url, {
method,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
'Content-Type': 'application/x-www-form-urlencoded',
},
credentials: 'same-origin',
body: createQueryParams(data)
body: createQueryParams(data),
})
const result = await res.json()
if (result?.code === 301 && !/\/weapi\/login/.test(reqInfo.url)) {
Expand All @@ -45,15 +45,15 @@ function createRequester () {
phone,
captcha,
countrycode: '86',
rememberLogin: 'true'
}
rememberLogin: 'true',
},
})
},
// 刷新登录态
loginRefresh () {
return createRequest({
url: '/weapi/login/token/refresh',
data: {}
data: {},
})
},
// 发送验证码
Expand All @@ -62,22 +62,22 @@ function createRequester () {
url: '/weapi/sms/captcha/sent',
data: {
cellphone: phone,
ctcode: '86'
}
ctcode: '86',
},
})
},
// 用户账户
getUser () {
return createRequest({
url: '/api/nuser/account/get',
data: {}
data: {},
})
},
// 退出登录
logout () {
return createRequest({
url: '/weapi/logout',
data: {}
data: {},
})
},
// 获取歌单
Expand All @@ -87,8 +87,8 @@ function createRequester () {
data: {
offset: 0,
uid,
limit: 50
}
limit: 50,
},
})
},
// 获取歌单详情
Expand All @@ -98,8 +98,8 @@ function createRequester () {
data: {
id,
n: 1000,
s: 8
}
s: 8,
},
})
},
// 获取每日推荐歌曲
Expand All @@ -109,15 +109,15 @@ function createRequester () {
data: {
offset: 0,
total: true,
limit: 50
}
limit: 50,
},
})
},
// 个性化推荐歌单
getRecommendResource () {
return createRequest({
url: '/weapi/discovery/recommend/resource',
data: {}
data: {},
})
},
// 新歌速递
Expand All @@ -126,8 +126,8 @@ function createRequester () {
url: '/weapi/v1/discovery/new/songs',
data: {
areaId,
total: true
}
total: true,
},
})
},
// 获取歌曲详情
Expand All @@ -138,8 +138,8 @@ function createRequester () {
url: '/weapi/v3/song/detail',
data: {
c: JSON.stringify(idsHash),
ids: idsStringify
}
ids: idsStringify,
},
})
},
// 获取音乐 url
Expand All @@ -148,8 +148,8 @@ function createRequester () {
url: '/weapi/song/enhance/player/url',
data: {
ids,
br
}
br,
},
})
},
// 喜欢音乐
Expand All @@ -160,10 +160,10 @@ function createRequester () {
tracks: '[object Object]',
pid: playlistId,
trackIds: `[${songId}]`,
op: isLike ? 'add' : 'del'
}
op: isLike ? 'add' : 'del',
},
})
}
},
}
}

Expand All @@ -182,7 +182,7 @@ function encryptData (obj) {
const encSecKey = rsaEncrypt(secKey, PUBKEY, MODULUS)
return {
params: encText,
encSecKey: encSecKey
encSecKey: encSecKey,
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/background/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@ function initContextMenu () {
const contextMenus = {
togglePlaying: (playing = COMMON_PROPS.playing) => ({
title: playing ? '暂停' : '播放',
contexts
contexts,
}),
playPrev: () => ({
title: '上一首',
contexts
contexts,
}),
playNext: () => ({
title: '下一首',
contexts
contexts,
}),
toggleMute: volumeMute => ({
title: volumeMute ? '取消静音' : '静音',
contexts
contexts,
}),
logout: userId => ({
title: '退出登录',
contexts,
visible: !!userId
})
visible: !!userId,
}),
}

chrome.contextMenus.removeAll()

Object.keys(contextMenus).forEach(id => {
chrome.contextMenus.create({
id,
...contextMenus[id]()
...contextMenus[id](),
})
})

Expand Down Expand Up @@ -176,10 +176,10 @@ function initRequestHook () {
urls: [
`${DOMAIN}/weapi/*`,
'*://*.kuwo.cn/*',
'*://*.migu.cn/*'
]
'*://*.migu.cn/*',
],
},
['requestHeaders', 'blocking', 'extraHeaders']
['requestHeaders', 'blocking', 'extraHeaders'],
)
}

Expand All @@ -196,9 +196,9 @@ function initResponseHook () {
},
{
urls: [
'*://*.migu.cn/*'
]
'*://*.migu.cn/*',
],
},
['responseHeaders', 'blocking', 'extraHeaders']
['responseHeaders', 'blocking', 'extraHeaders'],
)
}
2 changes: 1 addition & 1 deletion src/background/kuwo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function getKuWoSong (name, artists) {
const song = (result?.data?.list || []).filter(filterSong)[0]
if (!song) throw new Error()
const q = encryptQuery(
'corp=kuwo&p2p=1&type=convert_url2&sig=0&format=mp3&rid=' + song.rid
'corp=kuwo&p2p=1&type=convert_url2&sig=0&format=mp3&rid=' + song.rid,
)
res = await fetch(`${KUWO_MOBI_DOMAIN}/mobi.s?f=kuwo&q=` + q)
result = await res.text()
Expand Down
22 changes: 11 additions & 11 deletions src/background/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
logger,
chunkArr,
shuffleArr,
race
race,
} from '../utils'

// 缓存歌单
Expand All @@ -42,7 +42,7 @@ const store = proxy({ ...COMMON_PROPS, dir: 1, songUrl: '' })
export async function bootstrap () {
await Promise.all([
persistLoad(),
refreshLogin()
refreshLogin(),
])
await refreshPlaylists()
rebootAt = Date.now()
Expand Down Expand Up @@ -233,7 +233,7 @@ function persistSave () {
volume,
playMode,
playlistId: selectedPlaylist?.id || null,
songId: selectedSong?.id || null
songId: selectedSong?.id || null,
}
return saveData(data)
}
Expand All @@ -245,7 +245,7 @@ async function persistLoad () {
volume = COMMON_PROPS.volume,
playMode = COMMON_PROPS.playMode,
playlistId,
songId
songId,
} = data
logger.debug('persist.load', data)
if (playlistId) {
Expand Down Expand Up @@ -299,7 +299,7 @@ async function loadRecommendResourcePlaylist () {
throw new Error(res.message)
}
return res.recommend.slice(0, LEN_PLAYLIST_REC).map(
({ id, picUrl, name }) => ({ id, picUrl: picUrl + IMAGE_CLIP, name, type: PLAYLIST_TYPE.RECOMMEND })
({ id, picUrl, name }) => ({ id, picUrl: picUrl + IMAGE_CLIP, name, type: PLAYLIST_TYPE.RECOMMEND }),
)
} catch (err) {
logger.error('loadRecommendResourcePlaylist.err', err)
Expand Down Expand Up @@ -375,7 +375,7 @@ async function loadPlaylistDetails (playlist) {
type,
normalIndexes,
invalidIndexes: [],
shuffleIndexes
shuffleIndexes,
}
playlistDetailStore[playlist.id] = cachedPlaylistDetail
return cachedPlaylistDetail
Expand Down Expand Up @@ -408,7 +408,7 @@ async function loadSongDetails (playlistDetail, songId, retry) {
try {
url = await race([
getKuWoSong(song.name, song.artists),
getMiGuSong(song.name, song.artists)
getMiGuSong(song.name, song.artists),
])
} catch {
throw new Error('尝试第三方获取歌曲失败')
Expand Down Expand Up @@ -501,14 +501,14 @@ function createAudio (url) {
if (audio.buffered.length) {
const loadPercentage = (audio.buffered.end(audio.buffered.length - 1) / audio.duration) * 100
updateAudioState({
loadPercentage
loadPercentage,
})
}
}
audio.oncanplay = () => {
audio.onprogress()
updateAudioState({
duration: audio.duration
duration: audio.duration,
})
}
audio.onabort = () => {
Expand All @@ -530,7 +530,7 @@ function createAudio (url) {
}
audio.ontimeupdate = () => {
updateAudioState({
currentTime: audio.currentTime
currentTime: audio.currentTime,
})
}
return audio
Expand Down Expand Up @@ -558,7 +558,7 @@ function tracksToSongsMap (tracks) {
vip: !(fee === 0 || fee === 8),
picUrl: picUrl + IMAGE_CLIP,
artists: ar.map(v => v.name).join(' & '),
duration: dt
duration: dt,
}
})
const songsMap = songs.reduce((songsMap, song) => {
Expand Down
2 changes: 1 addition & 1 deletion src/popup/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function Login () {
const history = useHistory()
const [state, setState] = useState({
phone: '',
captcha: ''
captcha: '',
})
const [count, setCount] = useState(0)
const formFieldUpdate = (field, value) => {
Expand Down
Loading

0 comments on commit c9158b9

Please sign in to comment.