forked from ipcjs/bilibili-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbilibili_dynamic_style.user.js
134 lines (126 loc) · 4.42 KB
/
bilibili_dynamic_style.user.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
// ==UserScript==
// @name B站主页动态提醒直接显示在顶栏
// @namespace http://tampermonkey.net/
// @version 0.7.5
// @description 可以直接看到当前的提醒的类型, 省去鼠标移过去的麻烦...
// @author ipcjs
// @include *://www.bilibili.com/
// @include *://www.bilibili.com/index.html
// @grant none
// ==/UserScript==
(function () {
'use strict';
function log(...args) {
// console.log(...args);
}
let msgStyleHtml = `
#dyn_wnd {
display: block!important;
opacity: 1!important;
background-color: transparent;
left:-400px!important;
top: -10px!important;
z-index: -10000;
box-shadow: none;
border: none;
}
#dyn_wnd > .dyn_menu > .menu > .line {
left: 5px;
}
.z_top > .z_header > .z_top_nav .b-mz {
display: none;
}
`;
let msgHideListStyleHtml = `
#dyn_wnd > .dyn_menu {
display: block!important;
}
#dyn_wnd > * {
display: none!important;
}
`;
let msgStyle = $('<style>').attr('id', 'msg_style').html(msgStyleHtml);
let msgHideListStyle = $('<style>').attr('id', 'msg_hide_list_style').html(msgHideListStyleHtml);
let head = $('head');
let dynamic = $('#i_menu_msg_btn');
head.append(msgStyle, msgHideListStyle);
let enterFromI = false, showMsgListTimeoutId;
dynamic.find('> .i-link').hover(function () {
enterFromI = true;
log('i enter');
}, function () {
log('i exit');
});
dynamic.hover(function () {
if (enterFromI) {
msgStyle.remove();
msgHideListStyle.remove();
} else {
showMsgListTimeoutId = setTimeout(msgHideListStyle.remove.bind(msgHideListStyle), 300); // 使用bind, 绑定this
// msgHideListStyle.remove();
}
log('enter');
}, function () {
if (enterFromI) {
head.append(msgStyle, msgHideListStyle);
enterFromI = false;
} else {
clearTimeout(showMsgListTimeoutId);
msgHideListStyle.appendTo(head);
}
log('exit');
});
function hoverToPopupMsg() {
function autoClick() {
if (!enterFromI) {
$(this).click();
if ($(this).attr('mode') === window.defaultDynObj.params.type) {
var b = window.defaultDynObj;
b.target.attr("loaded") || (b.initMenu(), b.init(), b.target.attr("loaded", 1));// 加载默认的视频动态
}
}
log('click');
}
let timeoutId;
dynamic.find('.dyn_menu > .menu > ul > li').mouseenter(function () {
timeoutId = setTimeout(autoClick.bind(this), 100);
}).mouseleave(function () {
clearTimeout(timeoutId);
});
}
function delayMouseover(selector, namespace) {
let frameItems = $(selector);
console.log(frameItems);
frameItems.each(function () {
let item = $(this);
let mouseoverEvents = item.getEvents().mouseover;
if (!mouseoverEvents) return; // 可能没有mouseover事件
for (let event of mouseoverEvents) {
if (event.handler && event.namespace === namespace) { // 命名空间为空的事件, 对应弹出详细内容的事件
let timeoutId;
item.off('mouseenter', event.handler); // 先移除该事件
log(item, event);
item.mouseenter(function () {
timeoutId = setTimeout(event.handler.bind(this), 300); // 重新添加延迟执行的事件
}).mouseleave(function () {
clearTimeout(timeoutId);
});
break;
}
}
});
}
$(window).load(function () {
jQuery.fn.getEvents = function () {
if (typeof (jQuery._data) == 'function') {
return jQuery._data(this.get(0), 'events') || {};
} else if (typeof (this.data) == 'function') { // jQuery version < 1.7.?
return this.data('events') || {};
}
return {};
};
delayMouseover('.z_top .z_top_nav [hasframe]', ''); // 使顶栏的中的"游戏中心"/"直播"等条目的详细内容的窗口延时弹出
delayMouseover('#i_menu_become_vip', ''); // 使"我的大会员"延时弹出
hoverToPopupMsg();
});
})();