| 1665 | } |
| 1666 | |
| 1667 | function CookieUpdate(oldValue, newValue, path = 'cookie') { |
| 1668 | let item, type, name = (oldValue || newValue || '').split(/pt_pin=(.+?);/)[1]; |
| 1669 | let total = $nobyda.read('CookiesJD'); |
| 1670 | try { |
| 1671 | total = checkFormat(JSON.parse(total || '[]')); |
| 1672 | } catch (e) { |
| 1673 | $nobyda.notify("京东签到", "", "Cookie JSON格式不正确, 即将清空\n可前往日志查看该数据内容!"); |
| 1674 | console.log(`京东签到Cookie JSON格式异常: ${e.message||e}\n旧数据内容: ${total}`); |
| 1675 | total = []; |
| 1676 | } |
| 1677 | for (let i = 0; i < total.length; i++) { |
| 1678 | if (total[i].cookie && new RegExp(`pt_pin=${name};`).test(total[i].cookie)) { |
| 1679 | item = i; |
| 1680 | break; |
| 1681 | } |
| 1682 | } |
| 1683 | if (newValue && item !== undefined) { |
| 1684 | type = total[item][path] === newValue ? -1 : 2; |
| 1685 | total[item][path] = newValue; |
| 1686 | item = item + 1; |
| 1687 | } else if (newValue && path === 'cookie') { |
| 1688 | total.push({ |
| 1689 | cookie: newValue |
| 1690 | }); |
| 1691 | type = 1; |
| 1692 | item = total.length; |
| 1693 | } |
| 1694 | return { |
| 1695 | total: checkFormat(total), |
| 1696 | type, //-1: same, 1: add, 2:update |
| 1697 | item, |
| 1698 | name: decodeURIComponent(name) |
| 1699 | }; |
| 1700 | } |
| 1701 | |
| 1702 | function GetCookie() { |
| 1703 | const req = $request; |