asphr.de certificate download.

Download perfectly named HR reports from sage portal.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         asphr.de certificate download.
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Download perfectly named HR reports from sage portal.
// @author       TechnischNichtMoeglich
// @match        https://*.asphr.de/mportal/content/Mitarbeiterbereich/Stammdaten/Bescheinigungen.aspx
// @grant        unsafeWindow
// @require      http://code.jquery.com/jquery-latest.js
// ==/UserScript==


// Load report from given URL and save with given filename.
// Just providing a link with download attribute does not work
// since Content-Disposition http header overrules the proposed
// file name.
function DownloadReport(url, fname) {
    window.URL = window.URL || window.webkitURL;

    var xhr = new XMLHttpRequest(),
        a = document.createElement('a'), file;

    xhr.open('GET', '../../' + url, true);
    xhr.responseType = 'blob';
    xhr.onload = function () {
        file = new Blob([xhr.response], { type : 'application/octet-stream' });
        a.href = window.URL.createObjectURL(file);
        a.download = fname;  // Set to whatever file name you want
        // Now just click the link you created
        // Note that you may have to append the a element to the body somewhere
        // for this to work in Firefox
        a.click();
    };
    xhr.send();
}


unsafeWindow.DownloadReport = DownloadReport;

// Extract table data, compile an DownloadReport link, and inject it right next
// to the existing OpenReport image.
(function() {
    'use strict';
    var $url, $date, $name, $fname, $tds;
    var $trs = $( "tr[id ^= 'ctl00_cphContent_gridBescheinigungen_DXDataRow']" );
    $.each($trs, function() {
        $date = $(this).find("td:nth-child(2)").text().trim();
        $name = $(this).find("td:nth-child(1)").text().trim();
        $fname = $date + "_" + $name + ".pdf";
        $url = $(this).find("td:nth-child(4)").find("img").attr("onclick").replace("OpenReport('","").replace("');","");
        $(this).find("td:nth-child(4)").append('<a style="cursor: pointer" onclick="DownloadReport(\'' + $url + '\',\'' + $fname + '\');">SAVE</a>' );
    });
})();