-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
146 lines (131 loc) · 3.4 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const { boolVal } = UtilsAll();
(() => {
console.log("插件函数执行");
EmitStore();
VoicePlayBackSwich();
CopySwich();
ClickToSavePdf();
ClickOptionsNext();
ClickToSaveMd()
HasStoreage();
})();
// Voice Playback Switching - 语音播放切换
function VoicePlayBackSwich() {
$("#flexSwitchCheckChecked").on("change", function () {
if ($(this).is(":checked")) {
console.log("被选中");
SendMessage({ checked: true, type: "yuyin" });
Storage_Set("yuyin", true);
// 当checkbox被选中时执行的代码
} else {
console.log("被取消");
SendMessage({ checked: false, type: "yuyin" });
Storage_Set("yuyin", false);
// 当checkbox被取消选中时执行的代码
}
});
}
// 复制功能切换
function CopySwich() {
$("#flexSwitchCheckDefault").on("change", function () {
if ($(this).is(":checked")) {
console.log("被选中");
// 当checkbox被选中时执行的代码
SendMessage({ checked: true, type: "copy" });
Storage_Set("copy", true);
} else {
console.log("被取消");
// 当checkbox被取消选中时执行的代码
SendMessage({ checked: false, type: "copy" });
Storage_Set("copy", false);
}
});
}
// 点击导出PDF
function ClickToSavePdf() {
$("#ToSavePdf").on("click", function () {
SendMessage({ type: "tosavepdf" });
});
}
// 点击导出md文件
function ClickToSaveMd(){
$("#ToSaveMd").on("click", function () {
SendMessage({ type: "tosavemd" });
console.log('ToSaveMd')
});
}
// 点击跳转设置页
function ClickOptionsNext() {
$("#optinsNext").on("click", function () {
window.open(chrome.runtime.getURL("options.html"));
});
}
function ChromeExtentUtils() {
return (function () {
const MABE_SUPER_FN = function () {
return {
name: "MABE_SUPER_FN",
};
};
return { MABE_SUPER_FN };
})();
}
function SendMessage(data) {
const { checked, type } = data;
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var tabId = tabs[0].id;
const sendObject = {
checked,
type,
};
EmitStore();
chrome.tabs.sendMessage(tabId, sendObject, function () {
// console.log("收到响应");
});
});
}
function Storage_Set(name, data) {
return localStorage.setItem(name, data);
}
function Storage_Get(name) {
return localStorage.getItem(name);
}
function InitStorage_SetALL() {}
function HasStoreage() {
let copy = Storage_Get("copy");
let yuyin = Storage_Get("yuyin");
if (copy == null && yuyin == null) {
} else {
copy = boolVal(copy);
yuyin = boolVal(yuyin);
if (!copy) {
console.log("需要未选中-copy");
$("#flexSwitchCheckDefault").prop("checked", false);
} else {
$("#flexSwitchCheckDefault").prop("checked", true);
}
if (!yuyin) {
console.log("需要未选中-yuyin");
$("#flexSwitchCheckChecked").prop("checked", false);
} else {
$("#flexSwitchCheckChecked").prop("checked", true);
}
}
}
function EmitStore() {
const Store = {
copy: Storage_Get("copy") == null ? true : Storage_Get("copy"),
yuyin: Storage_Get("yuyin") == null ? true : Storage_Get("yuyin"),
};
chrome.storage.sync.set({ Store });
}
function UtilsAll() {
return (() => {
const boolVal = (val) => {
return val === "false" ? false : Boolean(val);
};
return {
boolVal,
};
})();
}