diff --git a/src/constants.js b/src/constants.js index 1d798c4..713ae78 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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) } diff --git a/src/psnine-plus.js b/src/psnine-plus.js index 1969757..ede3d55 100644 --- a/src/psnine-plus.js +++ b/src/psnine-plus.js @@ -6,7 +6,8 @@ import { blockPSNs, blockTopicKeywords, blockGeneElements, - blockGeneKeywords + blockGeneKeywords, + blockPlatinumBooking } from './services' // 根据路由分配功能 @@ -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 () { diff --git a/src/services/block-platinum-booking.js b/src/services/block-platinum-booking.js new file mode 100644 index 0000000..3869b70 --- /dev/null +++ b/src/services/block-platinum-booking.js @@ -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) + }) + } +} diff --git a/src/services/index.js b/src/services/index.js index f3308cb..336a4d8 100644 --- a/src/services/index.js +++ b/src/services/index.js @@ -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'