-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
104 lines (88 loc) · 2.35 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var user_info = null;
var ehdl = $('#meltdowneditor').meltdown({
openPreview: true,
fullscreen: true,
sidebyside: true,
previewHeight: "auto",
parser: window.marked.parse
});
var curpostLocal;
$('.meltdown_control-fullscreen').remove();
$('.meltdown_control-sidebyside').remove();
$('.meltdown_preview-header').text('.');
$('.meltdown_bar').remove();
var picCacheList = {};
var skin = 'dark';
//Fetch config
// Skin:
// - Default: Dark
// - Switch: Light
chrome.storage.local.get({
'workingpost': {
content: 'Please start blogging.',
sha: null,
title: 'Untitled'
},
'skin': 'dark'
}, function (obj) {
curpostLocal = obj.workingpost;
skin = obj.skin;
$('.posttitle').text(obj.workingpost['title']);
getLocalPost(function (o) {
if (o == null) {
curpost = curpostLocal;
} else {
curpost = o;
}
loadPost(curpost['content']);
});
// Skin Chooser
$('head').append('<link id="stylehdl" rel="stylesheet"type="text/css"href="styles-' + skin + '.css"/>');
})
function handlePic(url) {
return url;
}
hashCode = function (s) {
return s.split("").reduce(function (a, b) { a = ((a << 5) - a) + b.charCodeAt(0); return a & a }, 0);
}
//Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function (from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
var fontpath = chrome.runtime.getURL('assets');
var fontstr = "@font-face {font-family: 'Kesong';src: url('" + fontpath + "/font.otf') format('truetype');}";
$('body').append('<style>' + fontstr + '</style>');
/* Initialization to check the token! */
/* Utils for timer */
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Formalize the YYYY-MM-DD
function normalizeDate(dateStr) {
const parts = dateStr.split('-');
if (parts.length !== 3) {
throw new Error('Invalid date format, should be YYYY-MM-DD');
}
const year = parts[0];
let month = parts[1];
let day = parts[2];
if (month.length === 1) {
month = '0' + month;
}
if (day.length === 1) {
day = '0' + day;
}
return year + '-' + month + '-' + day;
}
//=> Refer to github.js as it's the key async
async function init() {
//Wait for github instance ready
while (gh == null)
await sleep(100)
while (gh.access_token() == null)
await sleep(100)
gh.getUserInfo(false);
}
init();