// ==UserScript== // @name PCR图书馆辅助计算器 // @namespace http://tampermonkey.net/ // @version 2.3.3 // @description 辅助计算所需体力,总次数等等 // @author winrey,colin,hymbz // @license MIT // @supportURL https://github.com/winrey/pcr-wiki-helper/issues // @homepage https://github.com/winrey/pcr-wiki-helper // @run-at document-start // @connect cdn.jsdelivr.net // @match *://pcredivewiki.tw/Armory // @grant unsafeWindow // @grant GM_getValue // @grant GM_setValue // @grant GM_info // @grant GM.getValue // @grant GM.setClipboard // @grant GM.setValue // @grant GM.deleteValue // @grant GM.info // @grant GM_addStyle // @require https://cdn.jsdelivr.net/npm/jquery@3.4.0/dist/jquery.min.js // @require https://cdn.jsdelivr.net/gh/winrey/pcr-wiki-helper@master/js/solver.js // @downloadURL none // ==/UserScript== (function() { 'use strict'; const sleep = time => new Promise(r => setTimeout(r,time)); $(document).ready(function() { GM_addStyle(` .helper--calc-result-cell.helper--show-deleted-btn::after { content: '\u2716'; position: absolute; bottom: 70px; background-color: #ff0000; color: #fff; line-height: 0.9rem; border-radius: 30%; padding: 3px; opacity: 50%; cursor: pointer; z-index: 10000; } .helper--calc-result-cell.helper--show-deleted-btn.multiSelect-no::after { content: '\u00A0\u00A0\u00A0'; } .helper--calc-result-cell.helper--show-deleted-btn.multiSelect-yes::after { content: '\u2714'; } .mapDrop-table .helper-oddTri { right: .3rem; top: 1.6rem; color: black; } .mapDrop-table .helper--calc-result-cell{ width: 70px; height: 70px; margin: 0 auto; position: relative; } .mapDrop-table .helper--calc-result-cell.un--wanted{ opacity: 0.4; } .mapDrop-table .helper-block { top: 1.6rem; right: .12rem; } #helper--bottom-btn-group { position: fixed; right: calc(60px + 1% - 2px); bottom: 90px; overflow: visible; display: flex; flex-wrap: wrap; flex-direction: column; } .helper--nav-to-level.helper--important::after { content: "独"; color: #e60c0c; font-size: .5em; position: relative; top: -0.8em; } #helper--modal-content:not(.helper--drop) input[item-name] { display: none; } #helper--modal-content input[item-name] { width: 6em; } #helper--popBox, .helper--modal-backdrop { display: none !important; } #popBox.modal.fade.show.helper, div.modal-backdrop.fade.show.helper { display: none !important; } a.singleSelect{ display: none } a.singleSelect.ready{ display: inline } .switch-multiSelectBtnState { display: none; width: 70px; height: 32px; border: solid 2px #ddd; border-radius: 30px; background-color: #FFF; position: relative; padding-left: 2.6rem; -webkit-transition: background-color 0.3s; transition: background-color 0.3s; -webkit-user-select: none; font-size: 14px; left: 5.1rem; } .switch-multiSelectBtnState.ready { display: inline; } .switch-handler.ready{ display: inline-block; } .switch-multiSelectBtnState.selected-completedBtn{ pointer-events: none; } .switch-multiSelectBtnState::before { right: 4rem; content: '多选'; position: absolute; width: 2rem; font-size: 15px; top: -0.1rem; margin-right: -1rem; transition: width 0s 0s,margin-right .3s ,top 0.3s,content 0s 1s; } .switch-multiSelectBtnState.active.selected-completedBtn::before { right: 3rem; content: '已选完成'; font-size: 14px; top: -0.08rem; margin-right: 0rem; border-radius: 11%; width: 4rem; border: 2px outset #f5d68e; pointer-events: all; line-height: 15.9px; transition: box-shadow 0.3s } .switch-multiSelectBtnState.selected-completedBtn:hover::before { box-shadow: -0.7px 1px 5.1px #000; } .switch-handler { position: relative; left: 2.5rem; top: 0.25rem; width: 1rem; height: 1rem; background-color: #FFF; border-radius: 100% 100%; -webkit-box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.52); box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.52); -webkit-transition: all 0.3s; transition: all 0.3s; display: none; } .switch-multiSelectBtnState.active { border-color: #4cd964; background-color: #4cd964; } .switch-handler.ready.active { left: 3.9rem; } .switch-handler::after { color: #000000; content: '关'; position: relative; bottom: 0.25rem; left: -0.6rem; padding-left: 1rem; -webkit-transition: color .3s 0.1s; } .switch-handler.active::after { content: ' '; color: #fff0; position: relative; left: -4rem; } .switch-handler.active::before { content: '开'; color: #f5f5f5; right: 1.4rem; padding-right: 1.4rem; } .switch-handler::before { content: '\u00A0\u00A0\u00A0'; color: #fff0; width: 2.6rem; bottom: 0.2rem; -webkit-transition: color .3s .1s; position: relative; } `) const saveTeamData = async() => { // 点击“存储队伍”按钮 document.querySelector('.sticky-top button:nth-child(6)').click(); let d=document.querySelector('a[href="##"]') d&&d.click() await sleep(2000); document.querySelector('#popBox.modal.fade.show').classList.toggle('helper',true) document.querySelector('div.modal-backdrop.fade.show').classList.toggle('helper',true) } function autoSwitch2MapList() { $(".title-fixed-wrap .armory-function").children()[2].click(); } function selectNumInOnePage(num,event) { const $select = $("#app > .main > .container > .item-box > .row.mb-3 > div:nth-child(3) > .row > div:nth-child(3) select"); if (num){ const changeEvent = new Event('change'); $select.val(1000) $select[0].dispatchEvent(changeEvent) } else return $select.val(); } function toPage(num) { const $table = $(".mapDrop-table:not(.helper)"); const $pages = $($table.find("tr").toArray().pop()); const $frist = $($pages.find("li").toArray()[num || 1]); $frist.children()[0].click() } async function getMapData() { function rowParser($tr, page, index) { function parseItem($item) { const url = $($item.find("a")[0]).attr("href"); const name = $($item.find("img")[0]).attr("title"); const img = $($item.find("img")[0]).attr("src"); const requireItemID=img.match(/\d{6}/)[0] //pcredivewiki.tw/static/images/equipment/icon_equipment_115221.png const odd = parseInt($($item.find("h6.dropOdd")[0]).text()) / 100; // %不算在parseInt内 let count=parseInt($($item.find(".py-1")[0]).text()); const id = /\d+/.exec(img)[0]; return { url, name, img, odd, count, id }; } const children = $tr.children().map(function(){return $(this)}); const name = children[0].text(); const requirement = parseInt(children[1].text()); const items = $(children[2].children()[0]).children().toArray().map(v => parseItem($(v))); return { name: name, requirement: requirement, items: items, page: page, index: index }; } function next($table) { const $pages = $($table.find("tr").toArray().pop()); const $next = $($pages.find("li").toArray().pop()); if ($next.hasClass("disabled")) return false; $next.children()[0].click() return true; } let $table = $(".mapDrop-table:not(.helper)"); const data = []; toPage(1); let page = 1; await sleep(20); do { await sleep(20); $table = $(".mapDrop-table:not(.helper)"); const pageData = $table.find("tr") .toArray() .map($) .slice(0,-1) // 最后一行是分页栏 .map((m, i) => rowParser(m, page, i)); data.push.apply(data, pageData); page += 1; } while(next($table)) toPage(1); return data; } function getCost(name) { if (name === "1-1") return 6 if (name.startsWith("1-")) return 8; if (name.startsWith("2-")) return 8; if (name.startsWith("3-")) return 8; if (name.startsWith("4-")) return 9; if (name.startsWith("5-")) return 9; if (name.startsWith("6-")) return 9; return 10; } function calcResult(data) { data = data.map(chan => { const sum = (...arr) => [].concat(...arr).reduce((acc, val) => acc + val, 0); chan.exception = sum(chan.items.map(v => v.count * v.odd)); chan.max = Math.max.apply(null, chan.items.map(v => v.count / v.odd)); chan.min = Math.min.apply(null, chan.items.filter(v => v.count).map(v => v.count / v.odd)); chan.effective = sum.apply(null, chan.items.map(v => v.count ? v.odd : 0)); return chan; }); const model = { "optimize": "cost", "opType": "min", "constraints": (() => { const equis = {}; data.forEach(c => c.items.forEach(e => equis[e.name] = {"min": e.count})); return equis; })(), "variables": (() => { const challs = {}; data.forEach(c => { const cMap = {}; c.items.forEach(item => cMap[item.name] = item.odd); cMap.cost = getCost(c.name); challs[c.name] = cMap; }); return challs; })(), }; console.log("model", model); const lp_result = solver.Solve(model); console.log(lp_result); for(let k in lp_result) { if (!k.includes("-")) continue; const target = data.find(c => c.name === k); if (target) target.times = lp_result[k] || 0; } return { total: lp_result.result, map: data .sort((a, b) => b.times - a.times) .sort((a, b) => b.effective - a.effective) }; } const BOUNS_KEY = "___bouns"; function askBouns() { const bouns = parseInt(prompt("请输入关卡倍数(如n3,n2等,默认为1倍)") || "1") || 1; sessionStorage.setItem(BOUNS_KEY, bouns); return bouns; } function getBouns() { let bouns = parseInt(sessionStorage.getItem("___bouns")); if (!bouns) { bouns = askBouns(); } return bouns } function showResult(data) { const bouns = getBouns(); const table = genTable(data.map.filter(m => m.times)); const comment = $.parseHTML('说明'); const commentLines = []; commentLines.push("推荐使用方法:按照列表顺序刷图,数量不要超过「适用」和「推荐」两者的最小值,完成后修改数量,重新根据新情景计算。"); commentLines.push(""); commentLines.push("注意:如果您尚缺好感,请考虑以1,6,11次扫荡为单位刷图,这样可以好感获得最大化。"); commentLines.push(""); commentLines.push("---表头说明---"); commentLines.push("『章节』关卡编号。点击可以自动跳转到图书馆原表中关卡所在页数。方便修改数量。关卡后的“独”表示这里存在独有装备。"); commentLines.push("『优先』标识。高亮装备是全地图唯一最高效率。请无脑刷满高亮装备图。"); commentLines.push("『需求』关卡需求。图中所需装备总数。"); commentLines.push("『效率』装备效率。图中所有有效装备掉落的概率和。"); commentLines.push("『适用』有效次数。预计能保持「效率」不变的次数。"); commentLines.push("『推荐』推荐次数。假设概率固定,由考虑体力的线性规划算法计算出的总最优刷图次数。"); commentLines.push("『最大』最大次数。最近该图需要的最高次数。"); $(comment[0]).click(e => { alert(commentLines.join('\n')); e.preventDefault(); e.stopPropagation()}); const quickModifyBtn = $.parseHTML(`快速修改`); $(quickModifyBtn[0]).click(e => { document.querySelector('table button:nth-child(1)').click(); document.getElementById('helper--modal-content').classList.toggle('helper--drop',modifyState); deleteItem(modifyState) modifyState&&document.querySelector('span.switch-multiSelectBtnState').addEventListener(`click`,multiItemChange) modifyState&&document.querySelector('span.switch-handler').addEventListener(`click`,(e)=>{ multiSelectState(switchMultBtnState("active", !document.querySelector('span.switch-multiSelectBtnState.active')));e.stopImmediatePropagation()}) modifyState = !modifyState; return false; }); const reCalcBtn = $.parseHTML(`重新计算`); const multipleBtn = $.parseHTML( ``) $(reCalcBtn[0]).click(() => {handleClickCalcBtn(); return false;}); showModalByDom(`总体力需求:${Math.round(data.total / bouns)} 当前倍率:${bouns} `, comment, quickModifyBtn, reCalcBtn,multipleBtn, table); } function createModal(...content) { const containerStyle = ` top: 0; left: 0; width: 100%; height: 100%; position: fixed; z-index: 10000; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: all ease-in-out 0.5s; `; const maskStyle = ` top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); position: absolute; z-index: 11000; `; const boxStyle = ` min-width: 80%; z-index: 12000; `; const contentStyle = ` width: 100%; margin-bottom: 10px; max-height: 80vh; overflow: scroll; ` const html = `
| 章节 | 需求 | 效率 | 适用 | 推荐 | 最大 | 掉落一覽 | ${mapData.map(m => `
|---|---|---|---|---|---|---|
| ${m.name} | ${m.requirement} | ${Math.round(m.effective * 100)}% | ${Math.ceil(m.min / bouns)} | ${Math.ceil(m.times / bouns)} | ${Math.ceil(m.max / bouns)} | ${genItemsGroup(m.items)} |