Langbahn Team – Weltmeisterschaft

User:Nischayn22/OCLC.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
( function( $ ) {

  $( document ).ready( function () { //jquery
      $( 'span.Z3988' ).each( function ( i, member ) {
          var attributes_str = ($(member).attr('title'));
          var rft_attribs = attributes_str.replace("ctx_ver=Z39.88-2004&", "");
          var oclc_url = "//fulltext.wmflabs.org/local-reference-api/jake.php";

          $.ajax({
              url: oclc_url,
                headers: { 'params' : rft_attribs },
                success: function( data ) {
                data = JSON.parse(data);
                if (data === undefined || data === null || data[0] === undefined) return;
                if (data[0]['url'] === undefined)
                  $(member).prepend("  <a href=" + data[0]['linkerurl'] + ">LINK</a>")
                else
                  $(member).prepend("  <a href=" + data[0]['url'] + ">LINK</a>")
              }
            });
        } );
    } );


} )( $ );