Index: trunk/tools/viaf/README |
— | — | @@ -1,5 +1,6 @@ |
2 | 2 | viaf.user.js, a Greasemonkey script |
3 | 3 | which detects VIAF numbers on web pages and creates related links |
| 4 | +and fetches names for the detected numbers from toolserver. |
4 | 5 | |
5 | 6 | Provisionally homepages and screenshots: |
6 | 7 | |
— | — | @@ -9,8 +10,8 @@ |
10 | 11 | http://de.wikipedia.org/wiki/Wikipedia:WikiConvention/ \ |
11 | 12 | Programm/VIAF#Greasemonkey-Skript (de) |
12 | 13 | |
13 | | -Version: 0.204 |
14 | | -README last updated: 20110901 |
| 14 | +Version: 0.306 |
| 15 | +README last updated: 20110909 |
15 | 16 | |
16 | 17 | What are VIAF numbers ? |
17 | 18 | |
— | — | @@ -41,10 +42,15 @@ |
42 | 43 | The VIAF number is then extracted from the url and also shown on the page |
43 | 44 | in cyan colour with a black dotted underline as indication. |
44 | 45 | |
45 | | -A summary box (6) lists all distinct VIAF numbers to facilitate cut & paste of |
| 46 | +The script calls asynchronously the toolserver with all detected VIAF numbers |
| 47 | +and receives as response names which correspond to the numbers, i.e. the |
| 48 | +authors' names. Names are shown on magenta labels. |
| 49 | + |
| 50 | +A summary box lsts all distinct VIAF numbers to facilitate cut & paste of |
46 | 51 | the extracted numbers; this can be disabled in the program code. |
47 | 52 | |
48 | 53 | The set of further server urls can be adapted in the program code. |
| 54 | + |
49 | 55 | It relies on jQuery and two further javascripts, which are fetched automatically |
50 | 56 | and has an integrated update checker (currently disabled) which looks for newer |
51 | 57 | versions of it and prompts the user in such case. |
— | — | @@ -54,11 +60,13 @@ |
55 | 61 | == solved == |
56 | 62 | + check why it does not work inside <span class=plainlinks> </span> tags |
57 | 63 | fixed in r95940 (0.204) |
| 64 | ++ add a ajax request module to fetch author names for numbers from toolserver |
| 65 | + and show them live on the current page; define a JSONP data format |
| 66 | + (0.306) |
58 | 67 | |
59 | 68 | == To Do == |
60 | | -* check detection and algorithm of VIAF2...VIAF9 numbers |
61 | 69 | * add a user-interface or mechanism to enable/disable the summary alert box |
62 | 70 | without the need to change program code |
63 | 71 | * revise and enable the update mechanism |
64 | | -* add a ajax request module to fetch author names for numbers from toolserver |
65 | | - and show them live on the current page; define a JSONP data format |
| 72 | +* better positioning of added links - when the come from links they are |
| 73 | + placed too far away. |
Index: trunk/tools/viaf/viaf.user.js |
— | — | @@ -4,10 +4,11 @@ |
5 | 5 | // @require https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/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. (c) T.Gries Version 0.206 201109030200 |
| 8 | +// @description locate VIAF numbers in texts and urls on web pages, fetch corresponding names from toolserver. (c)T.Gries Version 0.306 201109091200 |
9 | 9 | // @include * |
10 | 10 | // ==/UserScript== |
11 | 11 | |
| 12 | +var VERSION = "0.306"; |
12 | 13 | /*** |
13 | 14 | * Copyright (c) 2011 T. Gries |
14 | 15 | * |
— | — | @@ -33,20 +34,50 @@ |
34 | 35 | * in span class=plainlinks; added blank spans left and right |
35 | 36 | * of addedlinks for LTR/RTL pages |
36 | 37 | * 20110903 less blanks between added links |
| 38 | + * 20110907 calling a database to fetch names for detected VIAF numbers |
| 39 | + * http://www.oclc.org/developer/ may be of help (API calls) |
| 40 | + * "The OCLC Developer Network is a community of developers |
| 41 | + * collaborating to propose, discuss and test OCLC Web Services. |
| 42 | + * This open source, code-sharing infrastructure improves the |
| 43 | + * value of OCLC data for all users by encouraging new OCLC |
| 44 | + * Web Service uses." |
| 45 | + * 20110908 calling toolserver API to fetch all avaliable names for a VIAF |
| 46 | + * the first name from the server is shown on magenta background |
| 47 | + * debug parameter 0 (no debug info) .. 3 (max) |
| 48 | + * 20110909 POST instead of GET avoids server |
| 49 | + * "Error 414: Request-URI too large" for long queries |
| 50 | + * when many VIAF are found on a page |
| 51 | + * debug parameter bitwise |
| 52 | + * |
37 | 53 | ***/ |
38 | 54 | |
39 | | -// wrapper see http://www.mediawiki.org/wiki/JQuery |
| 55 | +// wrapper -- see http://www.mediawiki.org/wiki/JQuery |
40 | 56 | // to avoid possible conflicts with other scripts on the current page |
| 57 | + |
41 | 58 | ( function ( $ ) { |
42 | 59 | |
| 60 | +var debug = 0; |
| 61 | + |
| 62 | +/*** |
| 63 | + * 0 off |
| 64 | + * bit0: 1 show what has been sent to server |
| 65 | + * bit1: 2 show what has been received as server response |
| 66 | + * bit2: 4 dump the response in a readible form |
| 67 | + * bit3: 8 list the names space-separated |
| 68 | + * |
| 69 | + ***/ |
| 70 | + |
| 71 | +var showSummaryBox = false; |
| 72 | +var showAllNames = false; |
| 73 | + |
43 | 74 | var markUrlDetectedItems = true; // if detected items in Urls will be marked |
44 | 75 | var markUrlDetectedItemsCSS = { "borderBottom" : "1px orangered dotted" }; |
| 76 | +var markNamesFromServer = { "background":"magenta", "color":"white", "font-weight":"bold" }; |
45 | 77 | |
46 | 78 | // maximum of VIAF numbers which are shown in the summary box |
47 | 79 | var maxVIAFNumbers = 30; |
48 | 80 | |
49 | 81 | // Script update checker source: http://a32.me/2009/11/greasemonkey/ |
50 | | -var VERSION = "0.206"; |
51 | 82 | var SCRIPT_NAME = "viaf" |
52 | 83 | var SCRIPT_URL = "http://$$$yourhost$$$/"+SCRIPT_NAME+".user.js" |
53 | 84 | |
— | — | @@ -89,16 +120,182 @@ |
90 | 121 | } |
91 | 122 | } |
92 | 123 | |
93 | | -var out = new Array(); |
| 124 | +// utility functions |
94 | 125 | |
| 126 | +// our own sort order |
| 127 | +function numSort( a, b ) { return a-b } |
| 128 | + |
| 129 | +/** |
| 130 | + * |
| 131 | + * function : dump( array, depth ) |
| 132 | + * |
| 133 | + * source: |
| 134 | + * http://www.openjs.com/scripts/others/dump_function_php_print_r.php |
| 135 | + * |
| 136 | + * arguments: the data - array,hash(associative array),object |
| 137 | + * the depth - OPTIONAL |
| 138 | + * |
| 139 | + * returns: the textual representation of the array |
| 140 | + * |
| 141 | + * This function was inspired by the PHP print_r function. |
| 142 | + * |
| 143 | + * This will accept some data as the argument and returns a text |
| 144 | + * that will be a more readable version of the array/hash/object that is given. |
| 145 | + * |
| 146 | + **/ |
| 147 | +function dump( arr, depth ) { |
| 148 | + var dumped_text = ""; |
| 149 | + if( !depth ) depth = 0; |
| 150 | + |
| 151 | + // The padding pattern given at the beginning of the line |
| 152 | + var depth_padding = ""; |
| 153 | + |
| 154 | + for ( var j=0; j < depth+1; j++ ) { |
| 155 | + depth_padding += " "; |
| 156 | + } |
| 157 | + |
| 158 | + if ( typeof( arr ) == 'object' ) { //Array/Hashes/Objects |
| 159 | + for ( var item in arr ) { |
| 160 | + var value = arr[item]; |
| 161 | + |
| 162 | + if ( typeof( value ) == 'object' ) { //If it is an array, |
| 163 | + dumped_text += depth_padding + "'" + item + "' ...\n"; |
| 164 | + dumped_text += dump( value, depth+1 ); |
| 165 | + } else { |
| 166 | + dumped_text += depth_padding + "'" + item + "' => \"" + value + "\"\n"; |
| 167 | + } |
| 168 | + } |
| 169 | + } else { //Strings/Chars/Numbers etc. |
| 170 | + dumped_text = "===>"+arr+"<===(" + typeof( arr ) + ")"; |
| 171 | + } |
| 172 | + if ( dumped_text == '' ) { |
| 173 | + dumped_text = "no results"; |
| 174 | + } |
| 175 | + return dumped_text; |
| 176 | +} |
| 177 | + |
| 178 | +var out = Array(); |
| 179 | +var out_js = Array(); |
| 180 | +var output = ''; |
| 181 | +var nbsp = "<span> </span>"; |
| 182 | + |
| 183 | +// an animated "AJAX" loading wheel is shown and cleared in getPage2 when that page is processed |
| 184 | +// for online loader spinner image generation |
| 185 | +// http://www.google.com/search?hl=en&q=generate+animated+loading&btnG=Google+Search&aq=f&oq= |
| 186 | +// http://www.ajaxload.info/ |
| 187 | +// http://preloaders.net/ |
| 188 | +// for base64 online encoder http://www.motobit.com/util/base64-decoder-encoder.asp |
| 189 | +// for inline images http://www.elf.org/essay/inline-image.html |
| 190 | + |
| 191 | +function VIAFtoNames( items ) { |
| 192 | + |
| 193 | + if ( items.length == 0 ) return; |
| 194 | + |
| 195 | + // viaf-spinner-rotatin-arrows-cyan-80px |
| 196 | + var $spinner = $( '<img src="data:image/x-icon;base64,R0lGODlhRgBGAKUAAAT+9IT+/ET+9MT+/CT+9GT+/KT+/OT+/FT+9DT+9BT+9JT+/Ez+9NT+/Cz+9HT+/LT+/PT+/Fz+/Dz+9Az+9Iz+/ET+/Mz+/CT+/Gz+/Kz+/Oz+/FT+/Bz+9Jz+/Ez+/Nz+/Cz+/Hz+/Lz+/Pz+/Dz+/P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJCgAmACwAAAAARgBGAAAG/kCTcEgsGo/IpHLJbDqf0Kh0Sq1ar9isdsvter/gsHhMLh9Jh4F6zW6vQaTzJkKKkzcJgH7P7+szdkUkDyEFEBtlGxZ+jHuAZw97HQ9wYwcMjYyPRoN7FACTlWEgmJl8m4KRfgkGEWIgAqaOgUSdjBQPiGEHE5+evwCotaq+fRYHYSQjxY3CQ7Z9vhQOyF4kIBjAAMzOQtDbjAnVXAclsn+0zwHMjQy6WhEF4Jmf3UIbIwgKt3oUIulVSBhgN48bQCIRIPTSpkcBhINSQIQ4N4vJBlWNJrwLiLEgAAUO+tjjtGBetApYQHRoRMHAgVgVm5CoQFAPgY1TRDD0F4dU/swm8aT18QARaDZGAt75DFb0yIE8fHwJcEVlRCMFI4rAYgpFIMsGVL7NQwAQz8gkGyY0qtA0SQSoJiloQLLBQFtOBhgioBrlwCd24pLcPQJiX1QADnA6udBIwmAoEUpFAyslLyO2XUhk6NdngJSZh/VAsFYy9OgoJHSyo+DZi4ZGBj7rDH3hy2uTejx8DtCodRfLwGKjLu1nbmbejE5HgQDs07/MEm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TdxshoSWFETgQaBfPGDABDuCtRUSB0gAAZlk0LNMmH0I6YqkkYgQgmRb0qLAbpE0IYIFMBgQ5Wk85TqhUAMSTKCqAma1a8gDGtwzwL4MfMCtvQAHLPDABBds8MEIJ6zwwlQEAQA7">' ); |
| 197 | + |
| 198 | + $( $spinner ) |
| 199 | + .css( { |
| 200 | + "position":"fixed", |
| 201 | + "top":"50%", |
| 202 | + "left":"50%", |
| 203 | + "display":"none" |
| 204 | + } ) |
| 205 | + .attr( "id", "spinner" ) |
| 206 | + |
| 207 | + $( "body" ).append( $spinner ); |
| 208 | + $( "#spinner" ).fadeIn(4000); |
| 209 | + |
| 210 | + var items_str = JSON.stringify( items ); |
| 211 | + if ( debug & 1 ) output = "sent to server:\n"+items_str; |
| 212 | + |
| 213 | + // get names via Greasemonkey_xmlhttpRequest across domain borders |
| 214 | + // example using "GET" |
| 215 | + // http://toolserver.org/~apper/pd/x.php?format=json&data=name&for=[{"viaf":["15571981"]},{"viaf":["79410188"]},{"viaf":["2878675"]},{"viaf":["122255788"]}] |
| 216 | + |
| 217 | + // http://wiki.greasespot.net/GM_xmlhttpRequest#POST_request |
| 218 | + GM_xmlhttpRequest({ |
| 219 | + method: "POST", |
| 220 | + url: "http://toolserver.org/~apper/pd/x.php", |
| 221 | + data: "format=json&data=name&for="+items_str, |
| 222 | + dataType: "json", |
| 223 | + headers: { |
| 224 | + "Content-Type": "application/x-www-form-urlencoded" |
| 225 | + }, |
| 226 | + onload: function( request ) { |
| 227 | + $( "#spinner" ).hide(); |
| 228 | + if ( request.status != '200' || typeof request.responseText == 'undefined' ) { |
| 229 | + return; |
| 230 | + } else { |
| 231 | + cb_updateFromServer( request.responseText ) |
| 232 | + } |
| 233 | + } |
| 234 | + }); |
| 235 | + |
| 236 | +} |
| 237 | + |
| 238 | +// callback function |
| 239 | +function cb_updateFromServer( data ){ |
| 240 | + if ( debug & 2 ) output += "\n\nreceived from server:\n"+ data; |
| 241 | + |
| 242 | + var data_js = JSON.parse( data ); |
| 243 | + if ( debug & 4 ) alert( dump( data_js ) ); |
| 244 | + |
| 245 | + var names = ''; |
| 246 | + |
| 247 | + // for all returned viaf numbers do |
| 248 | + for ( viaf_i in data_js ) { |
| 249 | + |
| 250 | + // get the first viaf number per record, |
| 251 | + // as this was the one which was found on the web page. |
| 252 | + // |
| 253 | + // All occurences are already marked as class "viaf-<viafnr>" |
| 254 | + // when coming back here. |
| 255 | + // |
| 256 | + // Remark: the server response may contain further numbers for |
| 257 | + // persons having more than one viaf number. |
| 258 | + |
| 259 | + var viaf = data_js[viaf_i]['viaf'][0]; |
| 260 | + |
| 261 | + if ( data_js[viaf_i]['names'].length > 0 ) { |
| 262 | + |
| 263 | + // for all available names for that viaf do |
| 264 | + for ( name_i in data_js[viaf_i]['names'] ) { |
| 265 | + names += data_js[viaf_i]['names'][name_i]['name']+" "; |
| 266 | + } |
| 267 | + |
| 268 | + // replace the class "viaf-<viafnr>" |
| 269 | + // with all names string or with the first name only |
| 270 | + var nameString = ( showAllNames ) ? names : data_js[viaf_i]['names'][0]['name']; |
| 271 | + |
| 272 | + $(".viaf-" + viaf ) |
| 273 | + .text( " " + nameString + " " ) |
| 274 | + .css( markNamesFromServer ) |
| 275 | + .after( nbsp ) |
| 276 | + .before( nbsp ); |
| 277 | + |
| 278 | + } |
| 279 | + |
| 280 | + } |
| 281 | + |
| 282 | + if ( ( debug & 8 ) && ( names.length > 0 ) ) { |
| 283 | + output += "\n\n" + names; |
| 284 | + } |
| 285 | + if ( debug & (8+2+1) ) { |
| 286 | + alert( output ); |
| 287 | + } |
| 288 | + |
| 289 | +} |
| 290 | + |
| 291 | + |
95 | 292 | function doAnyOtherBusiness( viaf ) { |
96 | 293 | // add the element only if it does not exist in list |
97 | 294 | if ( out.indexOf(viaf) == -1 ) { |
98 | | - out.push(viaf); |
| 295 | + out.push( viaf ); |
| 296 | + out_js.push( { "viaf" : [ viaf ] } ); |
99 | 297 | } |
100 | 298 | } |
101 | 299 | |
102 | | - |
103 | 300 | // update checker (disabled) |
104 | 301 | // GM_registerMenuCommand("Check for update of "+SCRIPT_NAME, updateCheck2); |
105 | 302 | // updateCheck(0); |
— | — | @@ -109,7 +306,7 @@ |
110 | 307 | // but don't look in an active textareas like mediawiki input textarea |
111 | 308 | |
112 | 309 | $("body *:not(textarea)") |
113 | | - .replaceText( /(viaf[1-9]?)(:|\/|%3A|%2F|\s|ID:|=|%3D)+([0-9]+)/gi, "<span class='viaf viaf-in-text' viaf='$3'>$1$2$3</span>" ); |
| 310 | + .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>" ); |
114 | 311 | |
115 | 312 | // PASS 2 |
116 | 313 | // try to retrieve viaf numbers in urls |
— | — | @@ -136,7 +333,7 @@ |
137 | 334 | $(".viaf").each(function(){ |
138 | 335 | var $this = $(this); |
139 | 336 | var viaf = $this.attr( "viaf" ); |
140 | | - |
| 337 | + |
141 | 338 | var newLink = new Array(); |
142 | 339 | newLink.unshift( $( "<span> </span><a href='http://viaf.org/viaf/"+viaf+"/'><span class='addedlink viaf' viaf='"+viaf+"'>VIAF</span></a>" ) ); |
143 | 340 | 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>" ) ); |
— | — | @@ -147,13 +344,16 @@ |
148 | 345 | newLink.unshift( $( "<span> </span><a href='http://www.google.com/search?num=100&q=viaf+"+viaf+"'><span class='addedlink viaf' viaf='"+viaf+"'>G</span></a>" ) ); |
149 | 346 | // newLink.unshift( $( "<span> </span><label class='show-summary'><input type='checkbox' class='show-summary-checkbox' checked='checked'><span id='show-summary-text'></span></label>" ) ); |
150 | 347 | |
151 | | - newLink.unshift( $( "<span> </span>" ) ); |
| 348 | + // add a placeholder and a class for this specific viaf for the name texts |
| 349 | + // which come per xhr callback handler cb_updateFromServer |
| 350 | + newLink.unshift( $( "<span class='viaf-"+viaf+"'></span>" ) ); |
152 | 351 | for ( i in newLink ) { |
153 | 352 | $this.after( newLink[i] ) |
154 | 353 | } |
155 | 354 | doAnyOtherBusiness( viaf ); |
156 | 355 | }) |
157 | 356 | |
| 357 | + |
158 | 358 | // style all checkboxes |
159 | 359 | $( ".show-summary-checkbox" ) |
160 | 360 | .click(function(e){ |
— | — | @@ -174,9 +374,8 @@ |
175 | 375 | // style all added links |
176 | 376 | $( ".addedlink" ).css( { "background":"yellow" , "color":"black" } ); |
177 | 377 | |
178 | | -function numSort( a, b ) { return a-b } |
| 378 | +VIAFtoNames( out_js ); |
179 | 379 | |
180 | | - |
181 | 380 | // show a summary of the collected numbers |
182 | 381 | if ( out.length > 0 ) { |
183 | 382 | |
— | — | @@ -190,7 +389,11 @@ |
191 | 390 | var pluralS = ( out.length > 1 ) ? "s" : ""; |
192 | 391 | |
193 | 392 | // comment the following line if you don't want to see the summary (alert) box |
194 | | - alert( "The present page contains "+out.length+" distinct VIAF number"+pluralS+" in text or links.\nModify the script if you want to remove the alert box permanently.\n\n"+x ); |
| 393 | + if ( showSummaryBox ) { |
| 394 | + alert( "The present page contains "+out.length+" distinct VIAF number"+pluralS+" in text or links.\nModify the script if you want to remove the alert box permanently.\n\n"+x ); |
| 395 | + } |
| 396 | + |
| 397 | + |
195 | 398 | } |
196 | 399 | |
197 | 400 | }) ( jQuery ); |