-
Notifications
You must be signed in to change notification settings - Fork 0
/
citGadget.xml
504 lines (430 loc) · 14.4 KB
/
citGadget.xml
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Google Scholar Citation Counter"
description="A gadget which enables users to search for the total number of citations of author(s). It provides a total citation count, total number of cited publications and Jorge E. Hirsch's H-Index"
author="Jan Feyereisl"
author_email="[email protected]"
screenshot="http://citations-gadget.googlecode.com/svn/trunk/citGadget.png"
thumbnail="http://citations-gadget.googlecode.com/svn/trunk/citGadgetThumb.png"
author_location="Nottingham, UK"
author_affiliation="University of Nottingham"
author_link="http://cs.nott.ac.uk/~jqf"
scrolling="false"
height="160">
<Require feature="dynamic-height"/>
<Require feature="analytics"/>
</ModulePrefs>
<Content type="html">
<![CDATA[
<script type="text/javascript">
/* --------------------------------*/
/* Created by Jan Feyereisl - 2007 */
/* --------------------------------*/
// LIMITATIONS:
// This gadget calls Google Scholar in the same fashion as a web-browser would
// Suitable Scholar API needs to be first released in order to get a more useful and accurate code
// The gadget looks at the first 100 results returned by Scholar and caculates
// citations from those by simple string tokenization and the resulting int addition.
// The position of the author is not taken into account.
// Citation is calculated as long as the searched person is one of the named authors on the paper.
// !ISSUE! - 'enter' key has an issue in Googgle Chrome Browser
// !ISSUE! - Assumes that the number of citations per paper does not exceed 9999
// When using or - the operation has to be in capital letters if in "other" search term box
// HTML variable to generate html code to be printed out
var html = "";
// Global variable to hold the total number of returned results by Google
var totalResults = null;
// Variable which determines the number of returned paper records
var ret_results = 100;
// Global search variables
var author = "";
var other = "";
// Needs to be declared global otherwise it doesnt get recognized by the setTimeout() method
var citePages = new Array();
var publications = 0;
var pages = 0;
var done = false;
var gAuthor = "";
var gOther = "";
// -----------------------
function queryScholar(form){
// Display loading icon first
document.getElementById("loading").style.display="inline";
// HTML variable to generate html code to be printed out
html = "";
// Clear global variables for subsequent use
citePages = new Array();
publications = 0;
pages = 0;
done = false;
totalResults = null;
ret_results = 100;
author = "";
other = "";
gAuthor = "";
gOther = "";
// Variable holding the name of the author to be searched
author = form.inputbox.value;
// Variable which stores other search terms besides the author's name
other = form.other_inputbox.value;
// Convert search string into the correct Google search format
// (e.g. add "+" in-between search terms in order for Boolean operations to work)
gAuthor = author.replace(/ /gi, "+");
gOther = other.replace(/ /gi, "+");
// End of global variables declaration
// Fetch Information about total number of results returned by Google
getTotalResultsInfo(gAuthor, gOther);
}
// ----------------------
// Function to fetch vital information for retreiving full citations from multiple pages
// ----------------------
function getTotalResultsInfo(gAuthor, gOther){
// Generate correct http request
var url_to_get = "http://scholar.google.com/scholar?as_q="+gOther+"&num="+ret_results+"&as_sauthors="+gAuthor;
//var url_to_get = "http://scholar.google.com/"
_IG_FetchContent(url_to_get, function(responseText){
if (responseText == null){
_gel("sContent").innerHTML = "<i>Invalid data.</i>";
alert("There is no data.");
return;
}
// Variables used to find the correct location of the total number of returned results
var pre = '\">About';
//var post = /results \(\<b>/;
var post = /<\/b>\.\s*\<b>/;
//alert(responseText.length);
// Locate the place where the total results value is positioned
var resultPositionPre = responseText.search(pre) + pre.length;
var resultPositionPost = responseText.search(post);
var resultLength = resultPositionPost - resultPositionPre;
//alert(resultPositionPre);
//alert(resultPositionPost);
//alert(resultLength);
// Extract the total number of results returned
var tResults = responseText.substr(resultPositionPre, resultLength);
alert(tResults);
// Remove the comma representing thousands - it prevents js to treat the string as a number
while(tResults.search(',') != -1){
tResults = tResults.substr(0, tResults.search(',')) + tResults.substr(tResults.search(',')+1, tResults.length);
}
// Calculate how many pages we need to fetch
if(tResults > 100){
pages = (tResults)/ret_results;
// Temporary counter as an array indexer
var counter = 0;
// Fetch all fetchable pages (i.e. fetch 'pages' pages[Google's limit] or 10 pages)
if(pages < 10){
for(var i = 0; i < pages; i++)
{
start = i * 100;
var url_to_get = "http://scholar.google.com/scholar?as_q="+gOther+"&num="+ret_results+"&as_sauthors="+gAuthor+"&start="+start;
_IG_FetchContent(url_to_get, function(responseText1){
if (responseText == null){
_gel("sContent").innerHTML = "<i>Invalid data.</i>";
alert("There is no data.");
return;
}
citePages[counter++] = getCitationCount(responseText1);
return;
});
}
done = true;
}else{
for(var i = 0; i < 10; i++)
{
start = i * 100;
var url_to_get = "http://scholar.google.com/scholar?as_q="+gOther+"&num="+ret_results+"&as_sauthors="+gAuthor+"&start="+start;
_IG_FetchContent(url_to_get, function(responseText2){
if (responseText == null){
_gel("sContent").innerHTML = "<i>Invalid data.</i>";
alert("There is no data.");
return;
}
citePages[counter++] = getCitationCount(responseText2);
return;
});
}
done = true;
}
// Repeatedly wait until we receive all the results from the fetched pages
setTimeout("wait()", 3000);
}else{
var url_to_get = "http://scholar.google.com/scholar?as_q="+gOther+"&num="+ret_results+"&as_sauthors="+gAuthor;
_IG_FetchContent(url_to_get, function(responseText3){
if (responseText == null){
_gel("sContent").innerHTML = "<i>Invalid data.</i>";
alert("There is no data.");
return;
}
citePages[0] = getCitationCount(responseText3);
totalCites();
return;
});
} // End of checking if more than 100 results are returned if(tResults > 100)
});
}
function wait(){
if(done != true){
// TODO - TEST THIS IF IT EVER OCCURS
//alert("Waiting...: " + citePages.length);
setTimeout("wait()", 3000);
}else{
// alert("Done: " + citePages.length);
totalCites();
}
return;
}
function totalCites(){
// Calculate the total number of citations from all fetched pages
var total_citations = 0;
for(var i = 0; i < citePages.length; i++){
var citeArray = citePages[i];
for(var j = 0; j < citeArray.length; j++){
// The multiplication by one is a hack to convert the string type into a numerical type
total_citations += citeArray[j]*1;
}
}
// Print out the result to the screen
html += "<div class='stats'>Statistics:</div><br />";
html += "Citations for '<div class='sTerm'>" + author + "</div>' : <div class='citno'>" + total_citations + "</div><br />";
html += "Cited Publications: <div class='citno'>" + publications + "</div><br />";
html += "H-Index: <div class='citno'>" + h_index() + "</div><br />";
html += "<a class='link' href='http://scholar.google.com/scholar?as_q=" + gOther + "&as_sauthors=" + gAuthor + "' target='_blank'>view publications </a><br />";
html += "</div>";
// Output html in div.
_gel("sContent").innerHTML = html;
// Hide loading icon first
document.getElementById("loading").style.display="none";
// Display the results box
document.getElementById("sContent").style.display="block";
// Resize the frame
_IG_AdjustIFrameHeight();
}
function h_index(){
var hArray = new Array();
var x = 0;
for(var i = 0; i < citePages.length; i++){
var citeArray = citePages[i];
for(var j = 0; j < citeArray.length; j++){
// The multiplication by one is a hack to convert the string type into a numerical type
hArray[x++] = citeArray[j]*1;
}
}
hArray.sort(sortNumber);
//alert(hArray);
for(var i = 0; i < hArray.length; i++){
if(i > hArray[i]){
return hArray[i-1];
}
}
}
function sortNumber(a,b)
{
return b - a
}
// ----------------------
// Function to tokenize returned HTML response and sum up the Author's citation count
// ----------------------
function getCitationCount(responseText){
if (responseText == null){
_gel("sContent").innerHTML = "<i>Invalid data.</i>";
alert("There is no data.");
return;
}
var cite_exists = 1;
var cite_str_len = 14;
var len_of_Cite_by_str = 9;
var citeArray = new Array();
for(var i = 0; cite_exists > 0; i++)
{
cite_exists = responseText.search('Cited by');
if(cite_exists == -1){
//alert("No more citations for given Author!");
//return;
}else{
var tmp_string = responseText.substr(cite_exists, cite_str_len);
var end = (tmp_string.indexOf("<")-len_of_Cite_by_str);
citeArray[i] = tmp_string.substr(len_of_Cite_by_str, end);
publications++;
responseText = responseText.substr(cite_exists+cite_str_len, responseText.length);
}
}
return citeArray;
}
// ------------------------
function searchKeyUp(evt, form)
{
// If it’s Mozilla/FF use evt; else use window.event
//evt = evt ? evt : event;
var keyCode = evt.keyCode;
// figure out which key code goes with which key
// alert(evt.keyCode);
if(evt.keyCode == 13)
//if(evt.keyIdentifier == "Enter")
{
// do this if it IS the enter key
queryScholar(form);
}
else
{
// do this if it is NOT the enter key
}
}
</script>
<style type="text/css">
html, body {
background-color: #E5ECF9;
margin: 5px;
}
.instructions
{
font-size: 12px;
margin-bottom: 10px;
background-color: #FFF4C2;
border-right: 1px solid;
border-top: 1px solid;
border-left: 1px solid;
border-bottom: 1px solid;
padding: 3px;
}
#sContent
{
background-color: White;
margin-bottom: 10px;
border-right: #000000 1px solid;
border-top: #000000 1px solid;
border-left: #000000 1px solid;
border-bottom: #000000 1px solid;
font-size: 10pt;
display: none;
}
.citno
{
display: inline;
color: Blue;
}
.author
{
display: inline;
float: left;
font-size: 10pt;
font-weight: bold;
}
.other {
display: inline;
float: left;
font-size: 10pt;
font-weight: bold;
}
.author td, .other td
{
font-size: 10pt;
font-weight: bold;
}
.clear {
clear: both;
}
.submit {
margin-top: 5px;
margin-bottom: 10px;
}
.footer {
display: inline;
font-size: 10px;
}
.copyright {
display: inline;
font-size: 10px;
margin-left: 10px;
}
.stats
{
background-color: #3366CC;
font-size: 12px;
color: White;
border-bottom: black 1px solid;
}
.sTerm
{
display: inline;
font-style: italic;
color: red;
}
#loading
{
display: none;
vertical-align: middle;
}
.link
{
float: right;
text-align: right;
text-decoration: none;
display: block;
font-size: 10px;
}
</style>
<!-- Main part of HTML code //-->
<FORM NAME="cite" ACTION="" METHOD="GET">
<!-- Google Analytics Code -->
<script>
_IG_Analytics("UA-1727879-2", "/citGadget");
</script>
<div class="instructions">
<b>NOTICE</b>: <i>Unfortunately Google disallowed fetching their Scholar data. A workaround needs to be found first, before the gadget will work again. Please stay tuned.</i><br>
<br>
A Google Scholar gadget for calculating author citations and other statistical information regarding publications.
<a href="http://code.google.com/p/citations-gadget/" target="_blank">more...</a>
</div>
<!-- The dynamically generated code is inserted here //-->
<div id="sContent"></div>
<!-- </div> //-->
<div class="author">
<table>
<tr>
<td>
Author:
</td>
</tr>
<tr>
<td>
<input type="text" name="inputbox" onkeyup="searchKeyUp(event, this.form)">
</td>
</tr>
</table>
</div>
<div class="other">
<table>
<tr>
<td>
+ Other:
</td>
</tr>
<tr>
<td>
<input type="text" name="other_inputbox" onkeyup="searchKeyUp(event, this.form)">
</td>
</tr>
</table>
</div>
<div class="clear"></div>
<div class="submit">
<input type="button" name="Submit" value="Submit" onClick="queryScholar(this.form)" />
<img id="loading" src="http://citations-gadget.googlecode.com/svn/trunk/citGadgetLoading.gif" />
</div>
<div class="footer">
<a href="http://scholar.google.com" target="_blank">scholar.google.com</a>
</div>
<div class="copyright">
<a>Copyright - Jan Feyereisl (v.1.211)</a>   
<a href="http://code.google.com/p/citations-gadget/" target="_blank"> Project Page </a>
</div>
<script type="text/javascript">
// Resize the frame
_IG_AdjustIFrameHeight();
</script>
</FORM>
<!--<div id="sContent"></div> //-->
]]>
</Content>
</Module>