asphr.de certificate download.

Download perfectly named HR reports from sage portal.

  1. // ==UserScript==
  2. // @name asphr.de certificate download.
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Download perfectly named HR reports from sage portal.
  6. // @author TechnischNichtMoeglich
  7. // @match https://*.asphr.de/mportal/content/Mitarbeiterbereich/Stammdaten/Bescheinigungen.aspx
  8. // @grant unsafeWindow
  9. // @require http://code.jquery.com/jquery-latest.js
  10. // ==/UserScript==
  11.  
  12.  
  13. // Load report from given URL and save with given filename.
  14. // Just providing a link with download attribute does not work
  15. // since Content-Disposition http header overrules the proposed
  16. // file name.
  17. function DownloadReport(url, fname) {
  18. window.URL = window.URL || window.webkitURL;
  19.  
  20. var xhr = new XMLHttpRequest(),
  21. a = document.createElement('a'), file;
  22.  
  23. xhr.open('GET', '../../' + url, true);
  24. xhr.responseType = 'blob';
  25. xhr.onload = function () {
  26. file = new Blob([xhr.response], { type : 'application/octet-stream' });
  27. a.href = window.URL.createObjectURL(file);
  28. a.download = fname; // Set to whatever file name you want
  29. // Now just click the link you created
  30. // Note that you may have to append the a element to the body somewhere
  31. // for this to work in Firefox
  32. a.click();
  33. };
  34. xhr.send();
  35. }
  36.  
  37.  
  38. unsafeWindow.DownloadReport = DownloadReport;
  39.  
  40. // Extract table data, compile an DownloadReport link, and inject it right next
  41. // to the existing OpenReport image.
  42. (function() {
  43. 'use strict';
  44. var $url, $date, $name, $fname, $tds;
  45. var $trs = $( "tr[id ^= 'ctl00_cphContent_gridBescheinigungen_DXDataRow']" );
  46. $.each($trs, function() {
  47. $date = $(this).find("td:nth-child(2)").text().trim();
  48. $name = $(this).find("td:nth-child(1)").text().trim();
  49. $fname = $date + "_" + $name + ".pdf";
  50. $url = $(this).find("td:nth-child(4)").find("img").attr("onclick").replace("OpenReport('","").replace("');","");
  51. $(this).find("td:nth-child(4)").append('<a style="cursor: pointer" onclick="DownloadReport(\'' + $url + '\',\'' + $fname + '\');">SAVE</a>' );
  52. });
  53. })();