-
Notifications
You must be signed in to change notification settings - Fork 2
/
nlc-qikan.user.js
50 lines (45 loc) · 1.95 KB
/
nlc-qikan.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
// ==UserScript==
// @name 国家图书馆-龙源期刊文字版-辅助工具
// @version 0.1
// @description 国家图书馆-辅助工具
// @match http://nlc.vip.qikan.com.cn/text/*
// @grant none
// @author lgh06
// @require https://lib.sinaapp.com/js/jquery/2.2.4/jquery-2.2.4.min.js
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
var $ = jQuery.noConflict();
var url = window.location.href;
// 龙源电子期刊 文本版 文章页面 右侧目录 跟随浮动
if(url.match(/http\:\/\/nlc\.vip\.qikan\.com\.cn\/text\/Article.aspx/)){
var $firstA = $('.eiboxrightbody0dlcase').find('a')[0];
$(window).scroll((e)=>{
if(!isInPage($firstA)){
$('.eitextbox').css('display','none');
$('.eiboxrightbody0dlcase').css({position:'fixed',top:0});
}
if(isInPage($('.eiboxrightbody0')[0])){
$('.eitextbox').css('display','block');
$('.eiboxrightbody0dlcase').css({position:'static'});
}
});
$('.eiboxrightbody0dlcase').find('a').attr('target', '_self');
var nowId = window.location.href.match(/titleid=.*/)[0].replace('titleid=','');
var $nowA = $(`.eiboxrightbody0 a[href*=${nowId}]`);
var $nowAContainer = $('.eiboxrightbody0dlcase');
var length = $nowA.offset().top - $nowAContainer.offset().top;
console.log(length);
$nowAContainer.scrollTop($nowA.offset().top - $nowAContainer.offset().top - 10);
}
function isInPage(elem){
var rect = elem.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
}
})();