// ==UserScript== // @name 米尼优小程序辅助 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.1.3 // @description 米尼优小程序辅助 // @author EmpyrealTear // @icon https://c1.beyondh.com/maxpms/5.2.1.2/favicon.ico // @match .*://manage.miniyj.com/.* // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js // @require https://scriptcat.org/lib/513/2.0.0/ElementGetter.js // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // ==/UserScript== (function () { 'use strict'; unsafeWindow.jQuery = $; const options = { menus: { isShowIdentity: { toStr: (x) => '显示身份证号:' + (x ? '✓' : '✕') }, isShowYesterdayPrice: { 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 apis = { GetMixSingleRoomOccupationInfo: (id) => { let res = null $.ajax({ url: `https://mn.beyondh.com:8111/api/Room/GetMixSingleRoomOccupationInfo?roomNumber=${id}`, type: 'GET', xhrFields: { withCredentials: true }, dataType: 'json', async: false, success: (data) => { res = data } }) return res }, } const utils = { formatDateTime: (date, format = 'yyyy-MM-dd') => { const o = { "M+": date.getMonth() + 1, // 月份 "d+": date.getDate(), // 日 "h+": date.getHours() % 12 === 0 ? 12 : date.getHours() % 12, // 小时 "H+": date.getHours(), // 小时 "m+": date.getMinutes(), // 分 "s+": date.getSeconds(), // 秒 "q+": Math.floor((date.getMonth() + 3) / 3), // 季度 S: date.getMilliseconds(), // 毫秒 a: date.getHours() < 12 ? "上午" : "下午", // 上午/下午 A: date.getHours() < 12 ? "AM" : "PM", // AM/PM }; if (/(y+)/.test(format)) { format = format.replace( RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length) ); } for (let k in o) { if (new RegExp("(" + k + ")").test(format)) { format = format.replace( RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length) ); } } return format; } } elmGetter.selector('jquery') const xhrOpen = XMLHttpRequest.prototype.open XMLHttpRequest.prototype.open = function () { const xhr = this let isModify = false if (/Manage\/HotelOrder\/Info\?id\=/.test(arguments[1]) && GM_getValue('isShowIdentity')) { const getter = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, "response").get Object.defineProperty(xhr, "response", { get: () => { let result = getter.call(xhr) let data = JSON.parse(result).data if (!isModify) { isModify = true elmGetter.get('table.el-descriptions__table:contains("姓名"):not(:contains("身份证号"))').then(e => { $('tbody:contains("身份证号")').remove() e.append($(`
身份证号${data.user.identity}
`)) }) } return result }, }) } else if (/Manage\/Hotel\/PriceBoardDatesV2\?start_at\=/.test(arguments[1]) && GM_getValue('isShowYesterdayPrice')) { let start_at = arguments[1].split('?')[1].split('=')[1] let current_at = utils.formatDateTime(new Date(), 'yyyy-MM-dd') console.log(start_at, current_at) if (start_at == current_at && new Date() < new Date(current_at)) { elmGetter.get('form label[for="start_at"]').then(div => { let form = $(div).closest('form')[0] setTimeout(() => { form.__vue__.$options.propsData.model.start_at = utils.formatDateTime(new Date(new Date().setDate(new Date().getDate() - 1)), 'yyyy-MM-dd') $(form).find('[type=submit]').click() }, 500) }) } } return xhrOpen.apply(xhr, arguments) } })();