-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebean.js
51 lines (51 loc) · 1.53 KB
/
firebean.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultData = {
_firebean: '1',
_version: '0.0.1-alpha.26',
_close: "1" /* justClose */,
_redirect: '/',
};
exports.Actions = {
set_storage(data) {
localStorage.setItem(data.key, data.value);
},
remove_storage(data) {
localStorage.removeItem(data.key);
},
go_article(data) { },
go_comment(data) { },
go_user(data) { },
};
function stringify(inputData, baseUrl = '') {
return `${baseUrl}/_firebean?${Object.entries(Object.assign({}, exports.DefaultData, inputData))
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value.toString())}`)
.join('&')}`;
}
exports.stringify = stringify;
function exec(input = location.href) {
var data = typeof input === 'string' ? parse(input) : input;
//@ts-ignore
exports.Actions[data._type](data);
if (data._close === "1" /* justClose */) {
window.close();
}
else if (data._close === "2" /* onlyBlank */) {
if (window.opener)
window.close();
}
;
setTimeout(() => window.open(data._redirect, '_self'), 0);
}
exports.exec = exec;
function parse(url) {
var queryString = url.split('?').pop().split('#').shift();
var data = {};
for (let item of queryString.split('&')) {
let [key, value] = item.split('=');
data[decodeURIComponent(key)] = decodeURIComponent(value);
}
;
return Object.assign({}, exports.DefaultData, data);
}
exports.parse = parse;