-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
79 lines (73 loc) · 2.36 KB
/
background.js
File metadata and controls
79 lines (73 loc) · 2.36 KB
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
paoding.addEventListener({
"is_user_scope": false,
"is_once_callback": false,
"event_id": "Startup",
"handler": function () {
paoding.newDockedWindow({
"url": "https://fanyi.baidu.com/#auto/zh/",
"location": "left",
"width": 400,
"user_agent_override": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
});
paoding.newWebWindow({
"url": chrome.runtime.getURL("index.html"),
"title": "联合笔记",
"width": 500,
"height": 600,
"show_title": true,
"center_in_window": true,
"can_resize": true,
"can_minimize": true,
"can_maximize": true,
"dockable_window": true,
"reusable_window": true
});
// Enable Python
paoding.launchPythonInterpreter({});
}
});
function parseFileIdentifier(url) {
if (url == "about:blank" || !url) {
return "about:blank";
}
let path = new URL(url).pathname;
return path.substring(path.lastIndexOf('/') + 1);
}
paoding.addEventListener({
"is_user_scope": true,
"is_once_callback": false,
"event_id": "PDF_VIEWER_MOST_VISIBLE_PAGE_CHANGED",
"handler": function (e) {
if (chrome.storage) {
chrome.storage.local.set({
"location": {
"id": parseFileIdentifier(e.originalUrl) + ":" + e.pageIndex,
"originalUrl": e.originalUrl,
"pageIndex": e.pageIndex
}
});
}
}
});
paoding.addEventListener({
"is_user_scope": true,
"is_once_callback": false,
"event_id": "PDF_VIEWER_TEXT_SELECTION_CHANGED",
"handler": function (selectedText) {
paoding.dispatchEvent({
"event_id": "TranslateTextChanged",
"event_args": [
selectedText
]
})
}
});
// Only allow sending messages from within a ServiceWorker.
paoding.addEventListener({
"is_user_scope": true,
"is_once_callback": false,
"event_id": "SendToPythonInterpreter",
"handler": function (data) {
paoding.sendToPythonInterpreter(data);
}
});