-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
59 lines (49 loc) · 1.59 KB
/
content.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
const iCalButtonLocation = "#container > aside > div.title > ol";
$().ready(function () {
iCalUiAttach();
createButton("iCal", "tableCustom", "light image export").appendTo(iCalButtonLocation);
$('[data-modal="tableCustom"]').on("click", async () => {openIcalUi();});
});
async function openIcalUi() {
const table = await new Table();
const ical = new Ical(table);
downloadIcal(ical);
}
function iCalUiAttach() {
$.get(chrome.runtime.getURL('/icalUI.html'), function (data) {
htmlInject(data);
formatterInit($("#subjectFormatters"), $("#icalTitle"));
formatterInit($("#descriptionFormatters"), $("#icalDescription"));
moveElementToCenter($("#tableCustom"));
});
}
function moveElementToCenter($element) {
$element.css({
"margin-left": -($element.outerWidth() / 2),
"margin-top": -($element.outerHeight() / 2),
"display": "none"
});
}
function createButton(text, liModal, aClass, handler) {
const $newButton = $("<li>").attr("data-modal", liModal);
$newButton.click(handler);
const $a = $("<a>").addClass(aClass).text(text);
$newButton.append($a);
return $newButton;
}
function downloadIcal(ical) {
const url = ical.createIcalURL();
const a = document.createElement("a");
a.href = url;
a.download = ical.table.year + "년 " + ical.table.semester + "학기_" + ical.table.name + ".ics";
a.click();
a.remove();
window.URL.revokeObjectURL(url);
}
function htmlInject(data) {
$($.parseHTML(data)).appendTo('#container');
$("a.close", "#tableCustom").on("click", function () {
$("div.modalwrap").remove();
$("#tableCustom").hide();
});
}