Avoid F12 cookie copy: read HttpOnly sessionid, fill dylive paste form. Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
function fillCookieForm(payload) {
|
|
const sid = document.getElementById("tiktok-sessionid");
|
|
const dc = document.getElementById("tiktok-dc-id");
|
|
const user = document.getElementById("tiktok-username");
|
|
if (!sid || !dc) {
|
|
window.dispatchEvent(new CustomEvent("dylive-tiktok-cookie", { detail: payload }));
|
|
return { ok: false, reason: "form-hidden" };
|
|
}
|
|
const setNative = (el, value) => {
|
|
const proto = Object.getPrototypeOf(el);
|
|
const desc = Object.getOwnPropertyDescriptor(proto, "value");
|
|
desc?.set?.call(el, value);
|
|
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
};
|
|
setNative(sid, payload.sessionid || "");
|
|
setNative(dc, payload.dc_id || "useast2a");
|
|
if (user && payload.tiktok_username) setNative(user, payload.tiktok_username);
|
|
return { ok: true };
|
|
}
|
|
|
|
chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
|
|
if (msg?.type !== "DYLIVE_FILL_TIKTOK_COOKIE") return;
|
|
sendResponse(fillCookieForm(msg.payload || {}));
|
|
});
|
|
|
|
window.addEventListener("dylive-tiktok-cookie-request", async () => {
|
|
try {
|
|
const data = await chrome.runtime.sendMessage({ type: "GET_TIKTOK_COOKIES" });
|
|
if (data?.ok) window.dispatchEvent(new CustomEvent("dylive-tiktok-cookie", { detail: data.payload }));
|
|
} catch {
|
|
/* popup / page 未授权时忽略 */
|
|
}
|
|
});
|