-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy path22auto-scroll-thumbnail.js
32 lines (32 loc) · 1.24 KB
/
22auto-scroll-thumbnail.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
// 更多功能请使用Chartero:https://github.com/volatile-static/Chartero
let err;
// 滚动阅读器缩略图
function scrollThumbnailView() {
const reader = Zotero.Reader.getByTabID(Zotero_Tabs.selectedID);
const layout = reader._iframeWindow.document.getElementById('thumbnailView');
layout.getElementsByTagName('a')[reader.state.pageIndex].scrollIntoView();
}
try {
const notifierID = Zotero.Notifier.registerObserver({
notify: (event, type, ids, extraData) => {
if (event === 'select' && type === 'tab') { // 选择标签页
const reader = Zotero.Reader.getByTabID(Zotero_Tabs.selectedID);
if (!reader) return;
const viewer = reader._iframeWindow.document.getElementById('viewer');
// 防止重复添加
viewer.removeEventListener('mouseup', scrollThumbnailView, false);
viewer.addEventListener('mouseup', scrollThumbnailView, false);
}
}
}, ["tab"]);
window.addEventListener(
"unload",
function (e) {
Zotero.Notifier.unregisterObserver(notifierID);
},
false
);
} catch (error) {
err = error;
}
err || 'success'