IEEExplore PDF + frame replacement

Replaces all PDF links on IEEE Xplore with the direct link to the file, bypassing the annoying frameset.

  1. // ==UserScript==
  2. // @name IEEExplore PDF + frame replacement
  3. // @description Replaces all PDF links on IEEE Xplore with the direct link to the file, bypassing the annoying frameset.
  4. // @namespace userscripts
  5. // @include http://ieeexplore.ieee.org/*
  6. // @version 0.7
  7. // ==/UserScript==
  8.  
  9. // a function that loads jQuery and calls a callback function when jQuery has finished loading
  10. function addJQuery(callback) {
  11. var script = document.createElement("script");
  12. script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
  13. script.addEventListener('load', function() {
  14. var script = document.createElement("script");
  15. script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
  16. document.body.appendChild(script);
  17. }, false);
  18. document.body.appendChild(script);
  19. }
  20.  
  21. // the guts of this userscript
  22. function main() {
  23. // this replaces the links
  24. function ieee_replace_links() {
  25. jQ('a[href^="/xpl/ebooks/bookPdfWithBanner.jsp"]').each(function process() {
  26. jQ(this).attr("href").match(/\/xpl\/ebooks\/bookPdfWithBanner\.jsp\?fileName=(\d+)\.pdf\&bkn\=(\d+)/g);
  27. jQ(this).attr("href", "/ebooks/" + RegExp.$2 + "/" + RegExp.$1 + ".pdf?bkn=" + RegExp.$2);
  28. });
  29. jQ('a[href^="/stamp/stamp"]').each(function process() {jQ(this).attr("href", jQ(this).attr("href").replace("stamp/stamp", "stampPDF/getPDF")); });
  30. }
  31. // this redirects the frameset if we end up there somehow (e.g. following a link)
  32. function ieee_redir_frame() {
  33. var hh = document.location.href.replace("stamp/stamp", "stampPDF/getPDF");
  34. // ieee doesn't like leading zeroes
  35. hh = hh.replace(/arnumber=0*/g, "arnumber=");
  36. // setting the location reloads the page, we don't want that
  37. if (hh != document.location.href)
  38. document.location.href = hh;
  39. }
  40. ieee_redir_frame();
  41. ieee_replace_links();
  42. // some pages have dynamically loaded links (e.g. cited by)
  43. document.body.addEventListener('DOMNodeInserted', function(event) { ieee_replace_links(); }, false);
  44. }
  45.  
  46. // load jQuery and execute the main function
  47. addJQuery(main);