// ==UserScript== // @name 订餐问卷一键填写 // @version 0.0.2 // @namespace ly525 // @description 订餐问卷一键填写, 不要忘记订餐😂 // @author ly525 // @match *://*.www.wenjuan.com/* // @run-at document-end // @license MIT // @downloadURL none // ==/UserScript== (function(){ var config = { name: '刘岩', breakfast: '公司用餐', lunch: '公司盒饭', dinner: '公司盒饭', location: '舜天', department: 'TaurusX Group' } var nameLabel = '姓名' var locationLabel = '办公地点' var breakfastLabel = '早餐' var lunchLabel = '午餐' var dinnerLabel = '晚餐' var departmentLabel = '部门' function fillName(el) { el.querySelector('input[type=text]').value = config.name } function fillOption(el, labelKey) { // el.querySelectorAll('input[type=radio]')[1].checked = true var cells = [].slice.apply(el.querySelectorAll('.option_cell')) cells.forEach(function(cell) { if (cell.innerHTML.includes(config[labelKey])) { cell.querySelector('input[type=radio]').checked = true } }) } function autoFill() { var question_boxs = [].slice.apply(document.querySelectorAll('.wjques.maxtop.question')) question_boxs.forEach(function(el) { var content = el.innerHTML if (content.includes(nameLabel)) { fillName(el) } else if (content.includes(locationLabel)) { fillOption(el, 'location') } else if (content.includes(breakfastLabel)) { fillOption(el, 'breakfast') } else if (content.includes(lunchLabel)) { fillOption(el, 'lunch') } else if (content.includes(dinnerLabel)) { fillOption(el, 'dinner') } else if (content.includes(departmentLabel)) { fillOption(el, 'department') } }) } function addOneClickBtn() { var btn = document.createElement('button'); btn.classList.add('WJButton'); btn.innerHTML = '一键订餐'; btn.style = `position: absolute; right: 50px; top: 50px; width: 120px; height: 50px; background: rebeccapurple; z-index: 1000;`; document.body.appendChild(btn); btn.addEventListener('click', function() { autoFill(); var confirmBnt = document.querySelector('#next_button') confirm.style.width = '120px'; confirm.style.width = '50px'; }) } function addConfirmBtn() { var btn = document.createElement('button'); btn.classList.add('WJButton'); btn.style = `position: absolute; right: 50px; top: 50px; width: 120px; height: 50px; background: rebeccapurple; z-index: 1000;`; document.body.appendChild(btn); } var btn = addOneClickBtn() })()