// ==UserScript== // @name 获取喵达cookie // @namespace http://tampermonkey.net/ // @description 获取喵达cookie // @grant GM_cookie // @grant GM_setValue // @grant GM_getValue // @grant GM_notification // @version 0.01 // @author wcj // @match https://miaoda.sina.com.cn/index/index // @match https://miaoda.sina.com.cn/comp/index // @match https://tousu.sina.com.cn/user/view // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @require https://code.jquery.com/jquery-2.0.0.min.js // @run-at document-end // @grant unsafeWindow // @license MIT // ==/UserScript== async function computeSHA256(message) { // 将字符串转换为 ArrayBuffer const encoder = new TextEncoder(); const data = encoder.encode(message); // 计算 SHA-256 哈希值 const hashBuffer = await crypto.subtle.digest('SHA-256', data); // 将 ArrayBuffer 转换为十六进制字符串 const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); return hashHex; } const companyEnum = { "橡树黑卡":"黑猫-橡树黑卡", "橡树创新":"黑猫-橡树创新", "深圳市高光时刻网络科技有限公司":"黑猫-高光时刻", "中佳保险代理":"黑猫-中佳保代" } class ClassMiaodaCookieService { constructor() { this.platform = ''; this.url = "http://localhost:8090"; this.secret = 'cc94dedd3982495b80c76089e03b13c7'; } async start() { await this.getCompany(); await this.saveCookie(); } async getCompany() { let company = "" if(location.href.startsWith("https:///miaoda")){ const res = await fetch(location.origin + '/setting/index'); const text = await res.text(); const doc = new DOMParser().parseFromString(text, 'text/html'); const el = doc.querySelector('.uname .s1'); if (el && el.innerHTML) { company = el.innerHTML; } }else if(location.href.startsWith("https://tousu")){ company = document.querySelector('.username .name')?.innerText console.log(document.querySelector('.username .name')) } this.platform = companyEnum[company] } getCookie() { return new Promise((resolve) => { GM_cookie.list({}, function (cookies, error) { resolve(cookies.map(c => `${c.name}=${c.value}`).join('; ')) }) }) } async saveCookie() { if(!this.platform){ console.log("没有查询到账户名称") return } const cookieStr = await this.getCookie(); const timestamp = Math.round(Date.now() / 1000); const sign = await computeSHA256(timestamp + this.secret); fetch(`${this.url}/api/project/customer_service/complaint_channel_cookie`, { method: 'POST', body: JSON.stringify({ sign, timestamp, platform: this.platform, cookies: cookieStr, }), }); } } (function () { 'use strict'; new ClassMiaodaCookieService().start(); })();