| 47 | } |
| 48 | |
| 49 | function GetCookie() { |
| 50 | try { |
| 51 | if ($request.headers && $request.url.indexOf("GetJDUserInfoUnion") > -1) { |
| 52 | var CV = $request.headers["Cookie"] || $request.headers["cookie"]; |
| 53 | if (CV.match(/(pt_key=.+?pt_pin=|pt_pin=.+?pt_key=)/)) { |
| 54 | var CookieValue = CV.match(/pt_key=.+?;/) + CV.match(/pt_pin=.+?;/); |
| 55 | var UserName = CookieValue.match(/pt_pin=([^; ]+)(?=;?)/)[1]; |
| 56 | var DecodeName = decodeURIComponent(UserName); |
| 57 | var CookiesData = getCache(); |
| 58 | var updateCookiesData = [...CookiesData]; |
| 59 | var updateIndex; |
| 60 | var CookieName = "【账号】"; |
| 61 | var updateCodkie = CookiesData.find((item, index) => { |
| 62 | var ck = item.cookie; |
| 63 | var Account = ck |
| 64 | ? ck.match(/pt_pin=.+?;/) |
| 65 | ? ck.match(/pt_pin=([^; ]+)(?=;?)/)[1] |
| 66 | : null |
| 67 | : null; |
| 68 | const verify = UserName === Account; |
| 69 | if (verify) { |
| 70 | updateIndex = index; |
| 71 | } |
| 72 | return verify; |
| 73 | }); |
| 74 | var tipPrefix = ""; |
| 75 | if (updateCodkie) { |
| 76 | updateCookiesData[updateIndex].cookie = CookieValue; |
| 77 | CookieName = `【账号${updateIndex + 1}】`; |
| 78 | tipPrefix = "更新京东"; |
| 79 | } else { |
| 80 | updateCookiesData.push({ |
| 81 | userName: DecodeName, |
| 82 | cookie: CookieValue, |
| 83 | }); |
| 84 | CookieName = "【账号" + updateCookiesData.length + "】"; |
| 85 | tipPrefix = "首次写入京东"; |
| 86 | } |
| 87 | const cacheValue = JSON.stringify(updateCookiesData, null, "\t"); |
| 88 | $.write(cacheValue, CacheKey); |
| 89 | $.notify( |
| 90 | "用户名: " + DecodeName, |
| 91 | "", |
| 92 | tipPrefix + CookieName + "Cookie成功 🎉" |
| 93 | ); |
| 94 | } else { |
| 95 | $.notify("写入京东Cookie失败", "", "请查看脚本内说明, 登录网页获取 ‼️"); |
| 96 | } |
| 97 | $.done(); |
| 98 | return; |
| 99 | } else { |
| 100 | $.notify("写入京东Cookie失败", "", "请检查匹配URL或配置内脚本类型 ‼️"); |
| 101 | } |
| 102 | } catch (eor) { |
| 103 | $.write("", CacheKey); |
| 104 | $.notify("写入京东Cookie失败", "", "已尝试清空历史Cookie, 请重试 ⚠️"); |
| 105 | console.log( |
| 106 | `\n写入京东Cookie出现错误 ‼️\n${JSON.stringify( |