Skip to content

Commit

Permalink
Add block platinum booking
Browse files Browse the repository at this point in the history
  • Loading branch information
pciapcib committed Mar 22, 2019
1 parent 1f6a240 commit 837a45e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const PSNINE_HOST = window.location.host
export const SERVICES = {
hoverPSNCard: 'PSN 卡片',
filterTrophies: '奖杯筛选',
enhanceSortTrophies: '奖杯排序增强'
enhanceSortTrophies: '奖杯排序增强',
blockPlatinumBooking: '屏蔽白金预定'
}

export const DEFAULT_SERVICES = { ...R.map(R.T, SERVICES) }
Expand Down
8 changes: 5 additions & 3 deletions src/psnine-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
blockPSNs,
blockTopicKeywords,
blockGeneElements,
blockGeneKeywords
blockGeneKeywords,
blockPlatinumBooking
} from './services'

// 根据路由分配功能
Expand All @@ -19,9 +20,10 @@ const router = {
'!/psnid/:psnId': [hoverPSNCard],
'/': [blockTopicKeywords],
'/topic': [blockTopicKeywords],
'/psngame/:gameId': [enhanceSortTrophies, filterTrophies],
'/psngame/:gameId': [enhanceSortTrophies, filterTrophies, blockPlatinumBooking],
'/psngame/:gameId/topic': [blockTopicKeywords],
'/gene': [blockGeneElements, blockGeneKeywords]
'/gene': [blockGeneElements, blockGeneKeywords],
'/trophy/:trophyId': [blockPlatinumBooking]
}

$(function () {
Expand Down
40 changes: 40 additions & 0 deletions src/services/block-platinum-booking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import R from 'ramda'

const platinumBookingList = [
'预定',
'预订'
]

function getBlockPlatinumBookingTips ($platinumTips) {
return $platinumTips.filter(function () {
const content = $(this).find('.ml64 > .content').text()
const hasBlockContent = R.any(R.contains(R.__, content), platinumBookingList)

return hasBlockContent && content.length < 100
})
}

// 屏蔽白金预订
export default function blockPlatinumBooking (config, params, query) {
const $platinumBookingTips = getBlockPlatinumBookingTips($('.list > li'))

if (params.trophyId) {
if (R.endsWith('001', params.trophyId)) {
$platinumBookingTips.hide()
}
} else if (params.gameId) {
const $platinumTipsNum = $('#1 .text-platinum + .alert-success > b')
const platinumTipsNum = $platinumTipsNum.text()

$.ajax({
method: 'GET',
url: $('#1 .text-platinum').attr('href'),
dataType: 'html'
})
.done(raw => {
const $platinumBookingTips = getBlockPlatinumBookingTips($(raw).find('.list > li'))

$platinumTipsNum.text(platinumTipsNum - $platinumBookingTips.length)
})
}
}
1 change: 1 addition & 0 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { default as blockGeneElements } from './block-gene-elements'
export { default as blockGeneKeywords } from './block-gene-keywords'
export { default as blockPSNs } from './block-psns'
export { default as blockTopicKeywords } from './block-topic-keywords'
export { default as blockPlatinumBooking } from './block-platinum-booking'
export { default as enhanceSortTrophies } from './enhance-sort-trophies'
export { default as filterTrophies } from './filter-trophies'
export { default as hoverPSNCard } from './hover-psn-card'

0 comments on commit 837a45e

Please sign in to comment.