osu! mp Exporter

// ==UserScript==

Versione datata 14/07/2014. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name           osu! mp Exporter
// @description    // ==UserScript==
// @name           osu! mp Exporter
// @description    Export Multiplay result as csv
// @author         JebwizOscar
// @icon           http://osu.ppy.sh/favicon.ico
// @include        https://osu.ppy.sh/mp/*
// @include        http://osu.ppy.sh/mp/*
// @require        http://code.jquery.com/jquery-1.11.1.min.js
// @copyright      2014, Jeb
// @version        0.1.0.0
// @namespace https://greasyfork.org/users/3079
// ==/UserScript==


script = document.createElement("script");
script.innerHTML = exportToCSV;
function exportToCSV(filename) {
    csvData="";
    a={};
    $('table').each(function(){
        var $rows = $(this).find('tr:has(td,th)');
        csv="";
        $(this).parent(0).parent(0).find('div').each(function(){
            if (
                (typeof($(this).attr('class'))=="undefined")
                && 
                (typeof($(this).attr('style'))=="undefined")
            ){
                csv = csv + '"' + $(this).text() + '"' + "\n" ;
            }if (
                ($(this).attr('class')=="maintext")
            ){
                csv = csv + $(this).text() + "" ;
            }
        });
        tmpColDelim = String.fromCharCode(11),
            tmpRowDelim = String.fromCharCode(0),
                colDelim2 = '","',
                    rowDelim2 = '"\n"',
                        d = $rows.map(function (i, row) {
                            var $row = $(row),
                                $cols = $row.find('td,th');
                            return $cols.map(function (j, col) {
                                var $col = $(col),
                                    text = $col.text();
                                return text.replace('"', '""');
                            }).get().join(tmpColDelim);
                        }).get().join(rowDelim2).split(tmpColDelim).join(colDelim2) + '"';
        csv = csv + '"' + d;
        colDelim = '","',
            rowDelim = '"],\n["',
                e = '[["' + $rows.map(function (i, row) {
                    var $row = $(row),
                        $cols = $row.find('td');
                    return $cols.map(function (j, col) {
                        var $col = $(col),
                            text = $col.text();
                        return text.replace('"', '""');
                    }).get().join(tmpColDelim);
                }).get().join(rowDelim+'')
                .split(tmpColDelim).join(colDelim) + '"]]';
        j = eval('('+e+')');
        j.shift();
        x = j.sort(function(a,b){return b[1].replace(/[^0-9]/g,"")-a[1].replace(/[^0-9]/g,"")});
        for(i in x){
            if (typeof(a[x[i][3]])=='undefined')
                a[x[i][3]]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
            a[x[i][3]][parseInt(i)+1]++;
            a[x[i][3]][0]+=parseInt(x[i][1].replace(/[^0-9]/g,""));
        }
        
        csvData = csvData + encodeURIComponent(csv + "\n"+ "\n") ;
    });
    csvData = csvData + encodeURIComponent("\n"+ "\n") ;
    csvData = csvData + encodeURIComponent('"Name","Total Score"') ;
    for(o=1;o<=16;o++)
        csvData = csvData + encodeURIComponent(',"#'+o.toString()+'"') ;
    for(i in a){
        csvData = csvData + encodeURIComponent("\n"+'"'+i+'","'+a[i][0].toString()+'"') ;
        for(o=1;o<=16;o++)
            csvData = csvData + encodeURIComponent(',"'+a[i][o].toString()+'"') ;
    }
    $(this)
    .attr({
        'download': filename,
        'href': 'data:application/csv;charset=utf-8,%EF%BB%BF' + csvData,
        'target': '_blank'
    });
    
}
$('.mphistory').prepend('<center><a class="export" style="text-decoration: none;color:#000;background-color:#ddd; border: 1px solid #ccc; padding:8px;" target="_blank">Export Table data into csv</a></center>');

$(".export").on('click', function (event) {
    exportToCSV.apply(this, ['export.csv']);
});


// @author         JebwizOscar
// @icon           http://osu.ppy.sh/favicon.ico
// @include        https://osu.ppy.sh/mp/*
// @include        http://osu.ppy.sh/mp/*
// @require        //s.ppy.sh/js/jquery.min.js
// @copyright      2014, Jeb
// @version	       0.1.0.0
// ==/UserScript==


script = document.createElement("script");
script.innerHTML = exportToCSV;
function exportToCSV(filename) {
    csvData="";
    a={};
    $('table').each(function(){
        var $rows = $(this).find('tr:has(td,th)');
        csv="";
        $(this).parent(0).parent(0).find('div').each(function(){
            if (
                (typeof($(this).attr('class'))=="undefined")
                && 
                (typeof($(this).attr('style'))=="undefined")
            ){
                csv = csv + '"' + $(this).text() + '"' + "\n" ;
            }if (
                ($(this).attr('class')=="maintext")
            ){
                csv = csv + $(this).text() + "" ;
            }
        });
        tmpColDelim = String.fromCharCode(11),
            tmpRowDelim = String.fromCharCode(0),
                colDelim2 = '","',
                    rowDelim2 = '"\n"',
                        d = $rows.map(function (i, row) {
                            var $row = $(row),
                                $cols = $row.find('td,th');
                            return $cols.map(function (j, col) {
                                var $col = $(col),
                                    text = $col.text();
                                return text.replace('"', '""');
                            }).get().join(tmpColDelim);
                        }).get().join(rowDelim2).split(tmpColDelim).join(colDelim2) + '"';
        csv = csv + '"' + d;
        colDelim = '","',
            rowDelim = '"],\n["',
                e = '[["' + $rows.map(function (i, row) {
                    var $row = $(row),
                        $cols = $row.find('td');
                    return $cols.map(function (j, col) {
                        var $col = $(col),
                            text = $col.text();
                        return text.replace('"', '""');
                    }).get().join(tmpColDelim);
                }).get().join(rowDelim+'')
                .split(tmpColDelim).join(colDelim) + '"]]';
        j = eval('('+e+')');
        j.shift();
        x = j.sort(function(a,b){return b[1].replace(/[^0-9]/g,"")-a[1].replace(/[^0-9]/g,"")});
        for(i in x){
            if (typeof(a[x[i][3]])=='undefined')
                a[x[i][3]]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
            a[x[i][3]][parseInt(i)+1]++;
            a[x[i][3]][0]+=parseInt(x[i][1].replace(/[^0-9]/g,""));
        }
        
        csvData = csvData + encodeURIComponent(csv + "\n"+ "\n") ;
    });
    csvData = csvData + encodeURIComponent("\n"+ "\n") ;
    csvData = csvData + encodeURIComponent('"Name","Total Score"') ;
    for(o=1;o<=16;o++)
        csvData = csvData + encodeURIComponent(',"#'+o.toString()+'"') ;
    for(i in a){
        csvData = csvData + encodeURIComponent("\n"+'"'+i+'","'+a[i][0].toString()+'"') ;
        for(o=1;o<=16;o++)
            csvData = csvData + encodeURIComponent(',"'+a[i][o].toString()+'"') ;
    }
    $(this)
    .attr({
        'download': filename,
        'href': 'data:application/csv;charset=utf-8,%EF%BB%BF' + csvData,
        'target': '_blank'
    });
    
}
$('.mphistory').prepend('<center><a class="export" style="text-decoration: none;color:#000;background-color:#ddd; border: 1px solid #ccc; padding:8px;" target="_blank">Export Table data into csv</a></center>');

$(".export").on('click', function (event) {
    exportToCSV.apply(this, ['export.csv']);
});