osu! mp Exporter

// ==UserScript==

Stan na 14-07-2014. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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']);
});