UNPKG

@hocgin/browser-addone-kit

Version:
44 lines (42 loc) 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.authorizationScriptConfig = exports.authorizationScript = void 0; var _queryString = _interopRequireDefault(require("query-string")); var _types = require("../../types"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // 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 var authorizationScriptConfig = exports.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 */ var authorizationScript = exports.authorizationScript = function authorizationScript(browser) { // 1. 从请求参数获取到token var query = _queryString.default.parse(location.search); var onCloseTab = function onCloseTab() { window.close(); browser.runtime.sendMessage({ type: _types.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: _types.MessageType.Logged, value: token }).finally(onCloseTab); } else { onCloseTab(); } };