osu! mp Exporter

Export Multiplay result as csv

Tính đến 14-07-2014. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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