米尼优小程序辅助
// ==UserScript==
// @name 米尼优小程序辅助
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.2
// @description 米尼优小程序辅助
// @author EmpyrealTear
// @icon https://c1.beyondh.com/maxpms/5.2.1.2/favicon.ico
// @match .*://manage.miniyj.com/HotelOrders
// @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 ? '✓' : '✕'),
_new: null,
_old: null
},
},
register: (name) => {
let val = GM_getValue(name)
options.menus[name][!val ? '_new' : '_old'] = GM_registerMenuCommand(options.menus[name].toStr(val), () => {
GM_setValue(name, !val)
options.register(name)
})
GM_unregisterMenuCommand(options.menus[name][val ? '_new' : '_old'])
},
loads: () => {
Object.keys(options.menus).forEach(v => options.register(v))
}
}
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
},
}
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($(`<tbody id="tb-01"><tr class="el-descriptions-row"><td colspan="1" class="el-descriptions-item el-descriptions-item__cell"><div class="el-descriptions-item__container"><span class="el-descriptions-item__label has-colon ">身份证号</span><span class="el-descriptions-item__content">${data.user.identity}</span></div></td></tr></tbody>`))
})
}
return result
},
})
}
return xhrOpen.apply(xhr, arguments)
}
})();