UNPKG

@hocgin/browser-addone-kit

Version:
38 lines (36 loc) 1.33 kB
import qs from 'query-string'; import { MessageType } from "../../types"; // https://sso.hocgin.top/addone/567gsvdbjb&delay=0 // http://127.0.0.1:8000/forward?grantType=token&redirectUrl=https://sso.hocgin.top/ext/567gsvdbjb&delay=0 export var authorizationScriptConfig = function authorizationScriptConfig(entries, id) { return { matches: ["http://sso.hocgin.top/addone/".concat(id, "/redirect*"), "http://sso.hocgin.com/addone/".concat(id, "/redirect*"), "https://sso.hocgin.top/addone/".concat(id, "/redirect*"), "https://sso.hocgin.com/addone/".concat(id, "/redirect*")], entries: entries, runAt: 'document_start' }; }; /** * 授权登陆页面 * @param browser */ export var authorizationScript = function authorizationScript(browser) { // 1. 从请求参数获取到token var query = qs.parse(location.search); var onCloseTab = function onCloseTab() { window.close(); browser.runtime.sendMessage({ type: MessageType.CloseTab }); window.open("https://sso.hocgin.top/welcome", "_self").close(); }; var token = query === null || query === void 0 ? void 0 : query.token; if (token) { // 2. 设置 token, 通知用户登陆 browser.runtime.sendMessage({ type: MessageType.Logged, value: token }).finally(onCloseTab); } else { onCloseTab(); } };