Index: trunk/tools/viaf/README |
— | — | @@ -10,8 +10,8 @@ |
11 | 11 | http://de.wikipedia.org/wiki/Wikipedia:WikiConvention/ \ |
12 | 12 | Programm/VIAF#Greasemonkey-Skript (de) |
13 | 13 | |
14 | | -Version: 0.306 |
15 | | -README last updated: 20110909 |
| 14 | +Version: 0.309 |
| 15 | +README last updated: 20110924 |
16 | 16 | |
17 | 17 | What are VIAF numbers ? |
18 | 18 | |
— | — | @@ -124,13 +124,15 @@ |
125 | 125 | ] |
126 | 126 | |
127 | 127 | == solved == |
128 | | -+ check why it does not work inside <span class=plainlinks> </span> tags |
129 | | - fixed in r95940 (0.204) |
| 128 | ++ searching now also PND and GND number |
130 | 129 | + add a ajax request module to fetch author names for numbers from toolserver |
131 | 130 | and show them live on the current page; define a JSONP data format |
132 | 131 | (0.306) |
| 132 | ++ check why it does not work inside <span class=plainlinks> </span> tags |
| 133 | + fixed in r95940 (0.204) |
133 | 134 | |
134 | 135 | == To Do == |
| 136 | +* adding Toolserver software and requests to also fetch names for PND/GMD number |
135 | 137 | * add a user-interface or mechanism to enable/disable the summary alert box |
136 | 138 | without the need to change program code |
137 | 139 | * revise and enable the update mechanism |
Index: trunk/tools/viaf/viaf.user.js |
— | — | @@ -4,11 +4,11 @@ |
5 | 5 | // @require https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js |
6 | 6 | // @require http://svn.wikimedia.org/svnroot/mediawiki/trunk/tools/viaf/jquery.cookie.js |
7 | 7 | // @require http://svn.wikimedia.org/svnroot/mediawiki/trunk/tools/viaf/jquery.ba-replacetext.js |
8 | | -// @description locate VIAF numbers in texts and urls on web pages, fetch corresponding names from toolserver. (c)T.Gries Version 0.307 201109200845 |
| 8 | +// @description locate VIAF numbers in texts and urls on web pages, fetch corresponding names from toolserver. (c)T.Gries Version 0.309 201109241230 |
9 | 9 | // @include * |
10 | 10 | // ==/UserScript== |
11 | 11 | |
12 | | -var VERSION = "0.307"; |
| 12 | +var VERSION = "0.309"; |
13 | 13 | /*** |
14 | 14 | * Copyright (c) 2011 T. Gries |
15 | 15 | * |
— | — | @@ -50,6 +50,7 @@ |
51 | 51 | * debug parameter bitwise |
52 | 52 | * 20110920 removed parent() and add the new links close after the place |
53 | 53 | * where the VIAF was found; jQuery 1.6.4 |
| 54 | + * 20110923 beginning to detect and link PND numbers as well |
54 | 55 | * |
55 | 56 | ***/ |
56 | 57 | |
— | — | @@ -176,7 +177,8 @@ |
177 | 178 | return dumped_text; |
178 | 179 | } |
179 | 180 | |
180 | | -var out = Array(); |
| 181 | +var viaf = Array(); |
| 182 | +var pnd = Array(); |
181 | 183 | var out_js = Array(); |
182 | 184 | var output = ''; |
183 | 185 | var nbsp = "<span> </span>"; |
— | — | @@ -189,7 +191,7 @@ |
190 | 192 | // for base64 online encoder http://www.motobit.com/util/base64-decoder-encoder.asp |
191 | 193 | // for inline images http://www.elf.org/essay/inline-image.html |
192 | 194 | |
193 | | -function VIAFtoNames( items ) { |
| 195 | +function numberToNames( numberType, items ) { |
194 | 196 | |
195 | 197 | if ( items.length == 0 ) return; |
196 | 198 | |
— | — | @@ -239,7 +241,6 @@ |
240 | 242 | // callback function |
241 | 243 | function cb_updateFromServer( data ){ |
242 | 244 | if ( debug & 2 ) output += "\n\nreceived from server:\n"+ data; |
243 | | - |
244 | 245 | var data_js = JSON.parse( data ); |
245 | 246 | if ( debug & 4 ) alert( dump( data_js ) ); |
246 | 247 | |
— | — | @@ -275,9 +276,7 @@ |
276 | 277 | .css( markNamesFromServer ) |
277 | 278 | .after( nbsp ) |
278 | 279 | .before( nbsp ); |
279 | | - |
280 | 280 | } |
281 | | - |
282 | 281 | } |
283 | 282 | |
284 | 283 | if ( ( debug & 8 ) && ( names.length > 0 ) ) { |
— | — | @@ -290,11 +289,19 @@ |
291 | 290 | } |
292 | 291 | |
293 | 292 | |
294 | | -function doAnyOtherBusiness( viaf ) { |
| 293 | +function doAnyOtherBusiness( numberType, number ) { |
295 | 294 | // add the element only if it does not exist in list |
296 | | - if ( out.indexOf(viaf) == -1 ) { |
297 | | - out.push( viaf ); |
298 | | - out_js.push( { "viaf" : [ viaf ] } ); |
| 295 | + if ( numberType == "viaf" ) { |
| 296 | + if ( viaf.indexOf( number ) == -1 ) { |
| 297 | + viaf.push( number ); |
| 298 | + out_js.push( { "viaf" : [number] } ); |
| 299 | + } |
| 300 | + } else { |
| 301 | + if ( pnd.indexOf( number ) == -1 ) { |
| 302 | + pnd.push( number ); |
| 303 | +// FIXME |
| 304 | + // out_js.push( { "pnd" : [number] } ); |
| 305 | + } |
299 | 306 | } |
300 | 307 | } |
301 | 308 | |
— | — | @@ -308,7 +315,12 @@ |
309 | 316 | // but don't look in an active textareas like mediawiki input textarea |
310 | 317 | |
311 | 318 | $("body *:not(textarea)") |
312 | | - .replaceText( /(viaf[1-9]?)(:|\/|%2B|%3A|%2F|\s|ID:|=|%3D)+\s*([0-9]+)/gi, "<span class='viaf viaf-in-text' viaf='$3'>$1$2$3</span>" ); |
| 319 | + .replaceText( /(viaf[1-9]?)(:|\/|%2B|%3A|%2F|\s|ID:|=|%3D)+\s*([0-9]+)/gi, "<span class='viaf viaf-in-text' viaf='$3'>$1$2$3</span>" ) |
| 320 | +// .replaceText( /([pg]nd[1-9]?)(:|\/|%2B|%3A|%2F|\s|ID:|=|%3D)+\s*([0-9]+x?)/gi, "<span class='pnd pnd-in-text' viaf='$3'>$1$2$3</span>" ); |
| 321 | + .replaceText( /([pg]nd[1-9]?)(:|\/|%2B|%3A|%2F|\s|ID:|=|%3D)+\s*([0-9]+x?)/gi, function( s0, s1, s2, s3 ){ |
| 322 | + s3 = s3.toUpperCase(); |
| 323 | + return "<span class='pnd pnd-in-text' pnd='" + s3 + "'>" + s1 + s2 + s3 + "</span>" |
| 324 | + }); |
313 | 325 | |
314 | 326 | // PASS 2 |
315 | 327 | // try to retrieve viaf numbers in urls |
— | — | @@ -316,6 +328,7 @@ |
317 | 329 | $("a").each(function(){ |
318 | 330 | var $this = $(this); |
319 | 331 | if ( $this.find(".viaf").length != 0 ) return; // in PASS 2, skip all entries which have this attribute from PASS 1 |
| 332 | + if ( $this.find(".pnd").length != 0 ) return; // in PASS 2, skip all entries which have this attribute from PASS 1 |
320 | 333 | var url = $this.attr("href"); |
321 | 334 | |
322 | 335 | var magicUrlRegExp = new RegExp( /(http:\/\/viaf.org\/(viaf\/)?(\d+)|http:\/\/www.librarything.de\/commonknowledge\/search.php?f=13&exact=1&q=VIAF%3A(\d)+)/gi ); |
— | — | @@ -334,8 +347,8 @@ |
335 | 348 | |
336 | 349 | $(".viaf").each(function(){ |
337 | 350 | var $this = $(this); |
| 351 | + |
338 | 352 | var viaf = $this.attr( "viaf" ); |
339 | | - |
340 | 353 | var newLink = new Array(); |
341 | 354 | newLink.unshift( $( "<span> </span><a href='http://viaf.org/viaf/"+viaf+"/'><span class='addedlink viaf' viaf='"+viaf+"'>VIAF</span></a>" ) ); |
342 | 355 | newLink.unshift( $( "<span> </span><a href='http://www.librarything.de/commonknowledge/search.php?f=13&exact=1&q=VIAF%3A"+viaf+"'><span class='addedlink viaf' viaf='"+viaf+"'>LT de</span></a>" ) ); |
— | — | @@ -352,10 +365,33 @@ |
353 | 366 | for ( i in newLink ) { |
354 | 367 | $this.after( newLink[i] ) |
355 | 368 | } |
356 | | - doAnyOtherBusiness( viaf ); |
| 369 | + |
| 370 | + doAnyOtherBusiness( "viaf", viaf ); |
357 | 371 | }) |
358 | 372 | |
| 373 | +$(".pnd").each(function(){ |
| 374 | + var $this = $(this); |
359 | 375 | |
| 376 | + var pnd = $this.attr( "pnd" ); |
| 377 | + var newLink = new Array(); |
| 378 | + |
| 379 | + newLink.unshift( $( "<span> </span><a href='http://d-nb.info/gnd/"+pnd+"/'><span class='addedlink pnd' pnd='"+pnd+"'>DNB</span></a>" ) ); |
| 380 | + newLink.unshift( $( "<span> </span><a href='http://opac.bib-bvb.de/InfoGuideClient.fasttestsis/start.do?Query=100%3D%22"+pnd+"%22'><span class='addedlink pnd' pnd='"+pnd+"'>BVB</span></a>" ) ); |
| 381 | + newLink.unshift( $( "<span> </span><a href='http://mi.librarything.com/commonknowledge/search.php?f=13&exact=1&q=VIAF%3APND%3A"+pnd+"'><span class='addedlink pnd' pnd='"+pnd+"'>LT mi</span></a>" ) ); |
| 382 | + newLink.unshift( $( "<span> </span><a href='http://toolserver.org/~apper/pd/person/pnd/"+pnd+"'><span class='addedlink pnd' pnd='"+pnd+"'>TS</span></a>" ) ); |
| 383 | + // newLink.unshift( $( "<span> </span><label class='show-summary'><input type='checkbox' class='show-summary-checkbox' checked='checked'><span id='show-summary-text'></span></label>" ) ); |
| 384 | + |
| 385 | + // add a placeholder and a class for this specific pnd for the name texts |
| 386 | + // which come per xhr callback handler cb_updateFromServer |
| 387 | + newLink.unshift( $( "<span class='pnd-"+pnd+"'></span>" ) ); |
| 388 | + for ( i in newLink ) { |
| 389 | + $this.after( newLink[i] ) |
| 390 | + } |
| 391 | + |
| 392 | + doAnyOtherBusiness( "pnd", pnd ); |
| 393 | +}) |
| 394 | + |
| 395 | + |
360 | 396 | // style all checkboxes |
361 | 397 | $( ".show-summary-checkbox" ) |
362 | 398 | .click(function(e){ |
— | — | @@ -369,14 +405,17 @@ |
370 | 406 | |
371 | 407 | // style all detected numbers |
372 | 408 | $( ".viaf" ).css( { "background":"cyan", "color":"black" } ); |
| 409 | +$( ".pnd" ).css( { "background":"cyan", "color":"black" } ); |
373 | 410 | |
374 | 411 | // style all detected numbers in urls |
375 | 412 | $( ".viaf-in-url" ).css( "border-bottom", "1px dotted black" ); |
| 413 | +$( ".pnd-in-url" ).css( "border-bottom", "1px dotted black" ); |
376 | 414 | |
377 | 415 | // style all added links |
378 | 416 | $( ".addedlink" ).css( { "background":"yellow" , "color":"black" } ); |
379 | 417 | |
380 | | -VIAFtoNames( out_js ); |
| 418 | +numberToNames( "viaf", out_js ); |
| 419 | +// numberToNames( "pnd", out_js ); |
381 | 420 | |
382 | 421 | // show a summary of the collected numbers |
383 | 422 | if ( out.length > 0 ) { |