1
1
// ==UserScript==
2
2
// @name Google scholar conditional highlight
3
3
// @namespace wang19891218
4
- // @version 0.40
4
+ // @version 0.41
5
5
// @description Save some time
6
6
// @author coco
7
7
// @updateURL https://github.com/wang19891218/tampermonkey-scripts/raw/master/google_scholar/google_scholar_conditional_highlight.user.js
13
13
// ==/UserScript==
14
14
15
15
16
- function FunctionHighlightCitation ( ) {
17
- // Highlight citation
18
- var List_Class = document . getElementsByClassName ( "gs_fl" ) ;
19
- var var_h_coord = window . innerWidth - 220
20
- // div_Control.style.left = var_h_coord+"px"
21
- var Int_Threshold_Value_Cite = div_Input_Cite . value
22
- for ( var i_Class = 0 ; i_Class < List_Class . length ; i_Class ++ ) {
23
- List_a_Tag = List_Class [ i_Class ] . getElementsByTagName ( "a" ) ;
24
- for ( var i_a_Tag = 0 ; i_a_Tag < List_a_Tag . length ; i_a_Tag ++ ) {
25
- if ( List_a_Tag [ i_a_Tag ] . textContent . indexOf ( Str_search_Text ) == 0 ) {
26
- Str_Citation_Number = List_a_Tag [ i_a_Tag ] . textContent
27
- Value_Citation_Number = parseInt ( Str_Citation_Number . substring ( 9 , Str_Citation_Number . length ) )
28
- if ( Value_Citation_Number >= Int_Threshold_Value_Cite ) {
29
- List_a_Tag [ 2 ] . style . backgroundColor = 'powderblue' ;
30
- List_a_Tag [ 2 ] . style . border = "2px dashed black" ;
31
- // List_a_Tag[2].style.padding = "0.03em 0.05em";
32
- console . log ( List_a_Tag [ 2 ] . style . border ) ;
33
- } else {
34
- List_a_Tag [ 2 ] . style . backgroundColor = '' ;
35
- List_a_Tag [ 2 ] . style . border = "" ;
36
- }
37
- }
38
- }
39
- }
40
- document . cookie = "Input_Cite_Value=" + div_Input_Cite . value
41
- return true
42
- }
43
-
44
- function Function_Highlight_Year ( ) {
45
- // Highe light year
46
- var Array_gs_a = document . getElementsByClassName ( 'gs_a' )
47
- var Int_Threshold_Year = div_Input_Year . value
48
- for ( var i_gs = 0 ; i_gs < Array_gs_a . length ; i_gs ++ ) {
49
- var Div_gs_a = Array_gs_a [ i_gs ]
50
- var Str_Year = Div_gs_a . textContent . match ( / [ 0 - 9 ] [ 0 - 9 ] [ 0 - 9 ] [ 0 - 9 ] / g) [ 0 ]
51
- // var Int_Start = Div_gs_a.textContent.lastIndexOf(',')
52
- // var Int_Ended = Div_gs_a.textContent.lastIndexOf('-')
53
- // var Str_Year = Div_gs_a.textContent.substring(Int_Start + 1,Int_Ended)
54
- var Int_Year = parseInt ( Str_Year )
55
- var strStyle = "background-color:powderblue;display: inline-block; border: 2px dashed black; padding: 0.03em 0.05em;"
56
- Div_gs_a . innerHTML = Div_gs_a . innerHTML . replace ( strStyle , '' ) ;
57
- if ( Int_Year >= Int_Threshold_Year ) {
58
- // console.log(Div_gs_a.innerHTML);
59
- Div_gs_a . innerHTML = Div_gs_a . innerHTML . replace ( Str_Year , '<b style=\"' + strStyle + '\">' + Str_Year + '</b>' ) ;
60
- } else {
61
-
62
- }
63
- // console.log(Str_Year)
64
- }
65
- document . cookie = "Input_Year_Threshold=" + div_Input_Year . value
66
- return true
67
- }
68
-
69
- function FunctionAddAverageCitation ( ) {
70
- // Highe light year
16
+ function FunctionModifyItems ( ) {
17
+ // Modify items following current condition selection
71
18
var ListGSRI = document . getElementsByClassName ( 'gs_ri' )
72
19
for ( var i_GSRI = 0 ; i_GSRI < ListGSRI . length ; i_GSRI ++ ) {
20
+ // Get current year
73
21
var d = new Date ( ) ;
74
22
var floatCurrentYear = parseFloat ( d . getFullYear ( ) ) ;
23
+ // Get publication year of item
75
24
var GSRI = ListGSRI [ i_GSRI ]
76
25
var Div_gs_a = GSRI . getElementsByTagName ( "div" ) [ 0 ]
77
26
var Str_Year = Div_gs_a . textContent . match ( / [ 0 - 9 ] [ 0 - 9 ] [ 0 - 9 ] [ 0 - 9 ] / g) [ 0 ]
78
27
var floatPublichYear = parseFloat ( Str_Year )
79
-
28
+ // Get citation number
80
29
var arrayA = GSRI . getElementsByTagName ( "div" ) [ 2 ] . getElementsByTagName ( "a" )
81
30
var aCitationNumer = arrayA [ 2 ] ;
82
31
var floatCitationNumber = parseFloat ( aCitationNumer . textContent . match ( / [ 0 - 9 ] { 1 , } / ) [ 0 ] )
32
+ // Get citation per year
83
33
var floatAverageCitation = floatCitationNumber / ( floatCurrentYear + 1 - floatPublichYear )
84
34
35
+ // Add citation per year to the item
85
36
var textAvgCitation = aCitationNumer . cloneNode ( )
86
37
textAvgCitation . textContent = ", " + floatAverageCitation . toFixed ( 2 ) . toString ( ) + ' per year'
87
38
textAvgCitation . style = ''
88
39
arrayA [ 2 ] . parentNode . insertBefore ( textAvgCitation , aCitationNumer . nextSibling ) ;
89
- // arrayA.splice(3,0, divAvgCitation)
90
- // console.log(textAvgCitation)
91
- // console.log(arrayA[2].parentNode)
40
+
41
+ // Highlight year
42
+ console . log ( "year highlighted" )
43
+ var strStyle = "background-color:powderblue;display: inline-block; border: 2px dashed black; padding: 0.03em 0.05em;"
44
+ if ( floatPublichYear >= div_Input_Year . value ) {
45
+ Div_gs_a . innerHTML = Div_gs_a . innerHTML . replace ( Str_Year , '<b style=\"' + strStyle + '\">' + Str_Year + '</b>' ) ;
46
+ } else {
47
+ Div_gs_a . innerHTML = Div_gs_a . innerHTML . replace ( strStyle , '' ) ;
48
+ }
49
+
50
+ // Highlight citation
51
+ if ( floatCitationNumber >= div_Input_Cite . value ) {
52
+ aCitationNumer . style . backgroundColor = 'powderblue' ;
53
+ aCitationNumer . style . border = "2px dashed black" ;
54
+ // console.log(aCitationNumer.style.border);
55
+ } else {
56
+ aCitationNumer . style . backgroundColor = '' ;
57
+ aCitationNumer . style . border = "" ;
58
+ }
59
+
60
+ // Change alpha of unmatched item
61
+ if ( floatPublichYear < div_Input_Year . value || floatCitationNumber < div_Input_Cite . value ) {
62
+ GSRI . style . opacity = 0.5 ;
63
+ }
64
+ else {
65
+ GSRI . style . opacity = 1 ;
66
+ }
67
+
92
68
}
93
69
document . cookie = "Input_Year_Threshold=" + div_Input_Year . value
70
+ document . cookie = "Input_Cite_Value=" + div_Input_Cite . value
94
71
return true
95
72
}
96
73
74
+
75
+
97
76
var gs_bdy_sb_in = document . getElementById ( "gs_bdy_sb_in" )
98
77
99
78
var Str_search_Text = "Cited" ;
@@ -109,22 +88,7 @@ gs_bdy_sb_in.appendChild(div_Control)
109
88
110
89
var var_v_coord = 120
111
90
var var_h_coord = window . innerWidth - 220
112
- // div_Control.style.position = "fixed";
113
- // div_Control.style.left = var_h_coord+"px"
114
- // div_Control.style.position = "absolute"
115
- // div_Control.style.top = "0"
116
-
117
- // div_Control.style.top = var_v_coord+"px"
118
- // div_Control.style.right = "20px"
119
- // div_Control.style.width = "200px";
120
- // div_Control.style.height = "120px";
121
- // div_Control.style.background = "rgba(255, 0, 0, 0.3)";
122
- // div_Control.style.color = "white";
123
- // div_Control.style.border = "solid"
124
- // div_Control.style.padding = "12px";
125
91
div_Control . id = "id_coco_scholar_control"
126
- // div_Control.className = "input-group"
127
- // div_Control.innerHTML = "Control";
128
92
div_Control . className = "gs_bdy_sb_sec"
129
93
130
94
@@ -181,21 +145,19 @@ div_Input_Year.className ="form-control"
181
145
div_Input_Year . id = "id_coco_scholar_control_input_year"
182
146
div_Input_Year . value = parseInt ( getCookie ( "Input_Year_Threshold" ) ) ;
183
147
if ( isNaN ( div_Input_Year . value ) ) div_Input_Year . value = 2000 ;
148
+
184
149
document . cookie = "Input_Year_Threshold=" + div_Input_Year . value
185
- // div_Input_Year.onchange = function(){Function_Highlight_Year()}
186
150
div_Input_Year . style . width = "60px"
187
151
188
- window . addEventListener ( "resize" , FunctionHighlightCitation ) ;
152
+ window . addEventListener ( "resize" , FunctionModifyItems ) ;
189
153
190
154
var ButtonHighLight = document . createElement ( "button" ) ;
191
155
ButtonHighLight . className = "btn"
192
156
ButtonHighLight . style . margin = "5px"
193
157
console . log ( ButtonHighLight . style . padding )
194
158
ButtonHighLight . textContent = "highlight"
195
159
ButtonHighLight . onclick = function ( ) {
196
- FunctionHighlightCitation ( ) ;
197
- Function_Highlight_Year ( ) ;
198
- FunctionAddAverageCitation ( ) ;
160
+ FunctionModifyItems ( )
199
161
}
200
162
201
163
div_Control . appendChild ( div_Input_Cite_Title )
@@ -204,9 +166,7 @@ div_Control.appendChild(div_Input_Year_Title)
204
166
div_Control . appendChild ( div_Input_Year )
205
167
div_Control . appendChild ( ButtonHighLight )
206
168
207
- // document.getElementsByTagName("body")[0].appendChild(div_Control)
208
-
209
-
210
- FunctionHighlightCitation ( )
211
- Function_Highlight_Year ( )
212
- FunctionAddAverageCitation ( )
169
+ FunctionModifyItems ( )
170
+ // FunctionHighlightCitation()
171
+ // Function_Highlight_Year()
172
+ // FunctionAddAverageCitation()
0 commit comments