// ==UserScript== // @name 携程商家辅助-大道店 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.0.3 // @description 轮询调价记录、显示房价房态日历隐藏的卖价等 // @author EmpyrealTear // @icon https://ebooking.ctrip.com/favicon.ico // @match *://ebooking.ctrip.com/* // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js // @require https://scriptcat.org/lib/513/2.1.0/ElementGetter.js // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_notification // ==/UserScript== (function () { 'use strict'; unsafeWindow.jQuery = $ const options = { menus: { isNotify: { toStr: (x) => '是否桌面通知:' + (x ? '✓' : '✕') }, isShowOriginalPrice: { toStr: (x) => '是否显示卖价:' + (x ? '✓' : '✕') }, }, loads: function () { Object.keys(this.menus).forEach(v => { let val = GM_getValue(v) this.menus[v]['_menu'] = GM_registerMenuCommand(this.menus[v].toStr(val), () => { GM_setValue(v, !val) Object.keys(this.menus).forEach(v => GM_unregisterMenuCommand(this.menus[v]['_menu'])) this.loads() }) }) } } options.loads() const ajax = { GET: (url, isAsync = false) => { let res = null $.ajax({ url: url, type: 'GET', xhrFields: { withCredentials: true }, dataType: 'json', async: isAsync, success: (e) => { res = e } }) return res }, POST: (url, data, isAsync = false) => { let res = null $.ajax({ url: url, type: 'POST', xhrFields: { withCredentials: true }, data: JSON.stringify(data), contentType: 'application/json', dataType: 'json', async: isAsync, success: (e) => { res = e } }) return res } } // 轮询检查最后一次调价记录,是否为携程调价助手自动调价 setInterval(() => { let response = ajax.POST( 'https://ebooking.ctrip.com/ebkovsroom/api/inventory/search/getroompricereq', { "roomIds": [], "changeDate": new Date().format('yyyy-MM-dd'), "submitMonth": new Date().format('yyyy-MM'), "submitor": "", "appStatus": "A", "reqId": -1 }) let data = response?.data?.reqList if (data && data.length > 0) { if (!/EBK&.*&app/.test(data[0].operater)) { let preReqId = GM_getValue('reqId') let reqId = data[0].reqId if (preReqId != reqId) { if (GM_getValue('isNotify')) GM_notification(`${data[0].source}于${data[0].operateDate}发起调价`, '调价提醒') GM_setValue('reqId', reqId) } } } }, 1000 * 60) const xhrOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function () { const xhr = this // 是否显示默认被隐藏的卖价 if (GM_getValue('isShowOriginalPrice') && /ebkovsroom\/api\/inventory\/roomsv2/.test(arguments[1])) { const setRoomPPPriceAuthority = (room, value = 'T') => { return { ...room, roomInfos: room.roomInfos.map(info => ({ ...info, // origin: https://ws-s.tripcdn.cn/modules/EBooking/ebkroom-resource/1.1.69/js/inventory/calendarv9.js // isHidePrice => ppPriceAuthority: T=显示卖价, F=隐藏卖价 ppPriceAuthority: 'T' })) } } const getter = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, "responseText").get Object.defineProperty(xhr, "responseText", { get: () => { let result = JSON.parse(getter.call(xhr)) result.data = result.data.map(rooms => { if (Object.prototype.toString.call(rooms) == '[object Array]') return rooms.map(room => setRoomPPPriceAuthority(room)) return setRoomPPPriceAuthority(rooms) }) return JSON.stringify(result) }, }) } return xhrOpen.apply(xhr, arguments) } })();