Java/Greasemonkey problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • noname219
    FFR Wiki Admin
    • May 2007
    • 1694

    #1

    Java/Greasemonkey problem

    So, I've installed a Greasemonkey script on a website and I want to give it some modifications.
    The website is rateyourmusic.com and the script in question can be downloaded here : http://userscripts.org/scripts/show/151158.
    Basically, the script automatically calculates the average rating of an artist page.

    I was able to modify it a little bit (adding more decimals and having it to calculate the bootlegs/videos and tribute releases) but I also want to have the total number of releases of the artist.

    Last picture gives you an idea of what I mean :



    Oh yeah, and there's some credit saved for anybody that helps me. :)
    Last edited by noname219; 06-1-2013, 07:16 PM.
  • noname219
    FFR Wiki Admin
    • May 2007
    • 1694

    #2
    Re: Java/Greasemonkey problem

    Bump, who here wants 50k credits ?

    Comment

    • qqwref
      stepmania archaeologist
      FFR Simfile Author
      • Aug 2005
      • 4092

      #3
      Re: Java/Greasemonkey problem

      Can't you just make a global counter (e.g. albumCnt) and add one for each album you find (e.g. albumCnt++; before ratingCtr = ratingCtr + ratings;)?
      Best AAA: Policy In The Sky [Oni] (81)
      Best SDG: PANTS (86)
      Best FC: Future Invasion (93)

      Comment

      • Untimely Friction
        D6 Challeneged
        • Aug 2012
        • 1267

        #4
        Re: Java/Greasemonkey problem

        Originally posted by noname219
        Bump, who here wants 50k credits ?
        Me! But I don't know Java/greasemonkey well...

        Comment

        • noname219
          FFR Wiki Admin
          • May 2007
          • 1694

          #5
          Re: Java/Greasemonkey problem

          The thing is, I know nothing at all about Java. I was able to modify the script by trial and error and that's about it.
          I tried messing a bit with the code again but so far, I'm stuck.

          Comment

          • qqwref
            stepmania archaeologist
            FFR Simfile Author
            • Aug 2005
            • 4092

            #6
            Re: Java/Greasemonkey problem

            This doesn't even look like Java. More like JavaScript (which is a totally different thing btw).
            Best AAA: Policy In The Sky [Oni] (81)
            Best SDG: PANTS (86)
            Best FC: Future Invasion (93)

            Comment

            • noname219
              FFR Wiki Admin
              • May 2007
              • 1694

              #7
              Re: Java/Greasemonkey problem

              Originally posted by qqwref
              This doesn't even look like Java. More like JavaScript (which is a totally different thing btw).
              Originally posted by noname219
              I know nothing at all about Java.
              lol

              Thanks for helping btw.

              Comment

              • dAnceguy117
                new hand moves = dab
                FFR Simfile Author
                • Dec 2002
                • 10097

                #8
                Re: Java/Greasemonkey problem

                qqwref is correct. Java isn't actually what you're asking for help with. you're working with JavaScript.


                I'll take a really quick stab at it. no guarantees, but hopefully I can point you in the right direction. I'll check back in tomorrow.

                Code:
                // Display the data under the artist name as the first row of the profile table 
                if (ratingCtr > 0) {
                    var mbgens = document.getElementsByClassName('mbgen');
                    var bio = mbgens[0];
                    var row = bio.insertRow(0);
                    var newCell;
                
                    if (youRated > 0) {
                        x = (-((totCtr / ratingCtr).toFixed(9) - (youRating / youRated).toFixed(9)).toFixed(9));
                        if (x >= 0) {
                            x = '+' + x.toFixed(9);
                        }
                        var rowValues = ['Artist Rating', (totCtr / ratingCtr).toFixed(9) + ' from ' + addCommas(ratingCtr) + ' ratings and ' + ratingCtr + ' releases, Your rating: ' + (youRating / youRated).toFixed(9) + ' from ' + addCommas(youRated) + ' ratings (RYM ' + x + ')'];
                    } else {
                        var rowValues = ['Artist Rating', (totCtr / ratingCtr).toFixed(9) + ' from ' + addCommas(ratingCtr) + ' ratings and ' + ratingCtr + ' releases'];
                    }
                    for (var i = 0, ii = rowValues.length; i < ii; i++) {
                        newCell = row.insertCell(i);
                        newCell.appendChild(document.createTextNode(rowValues[i]));
                    }


                edit: oops I suck. code incoming

                ctrl+f "danceguy" to see where the changes were

                Code:
                // ==UserScript== 
                // @name       RYM Artist Rating 
                // @version    0.2 
                // @description  Compiles all RYM Artist Page data and displays the Artist rating beside the artist name 
                // @match      http://rateyourmusic.com/artist/* 
                // @copyright  2012+, quiapz, AnniesBoobs 
                // ==/UserScript== 
                function parseAlbum(albumType) {
                    var albums = (document.getElementById(albumType));
                    if (albums != null) {
                        // get number of albums. danceguy is number 1
                        numAlbums = albums.length;
                        albums = albums.getElementsByTagName('tr');
                        var artistRating = albums.length;
                        for (var j = 2; j < artistRating; j++) {
                            albumRow = albums[j];
                            if ((!albumRow.hasAttribute("class")) && (albumRow.cells[4].textContent != '') && (albumRow.cells[6].textContent != '')) {
                                ratings = parseInt((albumRow.cells[4].textContent).replace(/\,/g, ''));
                                score = parseFloat(albumRow.cells[6].textContent);
                                ratingCtr = ratingCtr + ratings;
                                scoreCtr = scoreCtr + score;
                                totCtr = totCtr + (ratings * score);
                                if (albumType != 'album_disc_c') {
                                    if (1919 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1930) {
                                        decadeStats[0][1] = decadeStats[0][1] + (ratings * score);
                                        decadeStats[0][2] = decadeStats[0][2] + ratings;
                                    } else if (1929 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1940) {
                                        decadeStats[1][1] = decadeStats[1][1] + (ratings * score);
                                        decadeStats[1][2] = decadeStats[1][2] + ratings;
                                    } else if (1939 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1950) {
                                        decadeStats[2][1] = decadeStats[2][1] + (ratings * score);
                                        decadeStats[2][2] = decadeStats[2][2] + ratings;
                                    } else if (1949 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1960) {
                                        decadeStats[3][1] = decadeStats[3][1] + (ratings * score);
                                        decadeStats[3][2] = decadeStats[3][2] + ratings;
                                    } else if (1959 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1970) {
                                        decadeStats[4][1] = decadeStats[4][1] + (ratings * score);
                                        decadeStats[4][2] = decadeStats[4][2] + ratings;
                                    } else if (1969 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1980) {
                                        decadeStats[5][1] = decadeStats[5][1] + (ratings * score);
                                        decadeStats[5][2] = decadeStats[5][2] + ratings;
                                    } else if (1979 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1990) {
                                        decadeStats[6][1] = decadeStats[6][1] + (ratings * score);
                                        decadeStats[6][2] = decadeStats[6][2] + ratings;
                                    } else if (1989 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 2000) {
                                        decadeStats[7][1] = decadeStats[7][1] + (ratings * score);
                                        decadeStats[7][2] = decadeStats[7][2] + ratings;
                                    } else if (1999 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 2010) {
                                        decadeStats[8][1] = decadeStats[8][1] + (ratings * score);
                                        decadeStats[8][2] = decadeStats[8][2] + ratings;
                                    } else if (2009 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 2020) {
                                        decadeStats[9][1] = decadeStats[9][1] + (ratings * score);
                                        decadeStats[9][2] = decadeStats[9][2] + ratings;
                                    }
                                }
                                if (!isNaN(parseInt(albumRow.cells[7].textContent))) {
                                    youRating = youRating + parseFloat(albumRow.cells[7].textContent.substring(0, 4));
                                    youRated++;
                                }
                            }
                        }
                    }
                }
                
                function addCommas(nStr) {
                    nStr += '';
                    y = nStr.split('.');
                    y1 = y[0];
                    y2 = y.length > 1 ? '.' + y[1] : '';
                    var rgx = /(\d+)(\d{3})/;
                    while (rgx.test(y1)) {
                        y1 = y1.replace(rgx, '$1' + ',' + '$2');
                    }
                    return y1 + y2;
                }
                // Go through the Album discography and compute Artist Rating using Ratings and Overall Score of each album 
                var ratingCell, scoreCell, albumRow;
                var numAlbums = 0;
                var scoreCtr = 0;
                var ratingCtr = 0;
                var totCtr = 0;
                var youRating = 0;
                var youRated = 0;
                var decadeStats = [
                    ['1920s: ', 0, 0],
                    ['1930s: ', 0, 0],
                    ['1940s: ', 0, 0],
                    ['1950s: ', 0, 0],
                    ['1960s: ', 0, 0],
                    ['1970s: ', 0, 0],
                    ['1980s: ', 0, 0],
                    ['1990s: ', 0, 0],
                    ['2000s: ', 0, 0],
                    ['2010s: ', 0, 0]
                ];
                parseAlbum('album_disc_s');
                parseAlbum('album_disc_i');
                parseAlbum('album_disc_e');
                parseAlbum('album_disc_c');
                // Display the data under the artist name as the first row of the profile table 
                if (ratingCtr > 0) {
                    var mbgens = document.getElementsByClassName('mbgen');
                    var bio = mbgens[0];
                    var row = bio.insertRow(0);
                    var newCell;
                
                    if (youRated > 0) {
                        x = (-((totCtr / ratingCtr).toFixed(9) - (youRating / youRated).toFixed(9)).toFixed(9));
                        if (x >= 0) {
                            x = '+' + x.toFixed(9);
                        }
                        // include the number of albums in the second element of the row. danceguy is amazing omg
                        var rowValues = ['Artist Rating', (totCtr / ratingCtr).toFixed(9) + ' from ' + addCommas(ratingCtr) + ' ratings and ' + numAlbums + ' releases, Your rating: ' + (youRating / youRated).toFixed(9) + ' from ' + addCommas(youRated) + ' ratings (RYM ' + x + ')'];
                    } else {
                        // include the number of albums in the second element of the row. danceguy listens to better music than you
                        var rowValues = ['Artist Rating', (totCtr / ratingCtr).toFixed(9) + ' from ' + addCommas(ratingCtr) + ' ratings and ' + numAlbums + ' releases'];
                    }
                    for (var i = 0, ii = rowValues.length; i < ii; i++) {
                        newCell = row.insertCell(i);
                        newCell.appendChild(document.createTextNode(rowValues[i]));
                    }
                
                    var row = bio.insertRow(bio.getElementsByTagName("TR").length);
                    var newCell;
                    newCell1 = row.insertCell(0);
                    newCell1.appendChild(document.createTextNode('Music stats'));
                    newCell = row.insertCell(1);
                    x = document.createElement('b');
                    newCell.appendChild(x);
                    x.appendChild(document.createTextNode('Average by Decade:'));
                    for (d = 0; d < decadeStats.length; d++) {
                        if (decadeStats[d][2] > 0) {
                            newCell.appendChild(document.createElement('br'));
                            newCell.appendChild(document.createTextNode(decadeStats[d][0] + (decadeStats[d][1] / decadeStats[d][2]).toFixed(2) + ', from ' + addCommas(decadeStats[d][2]) + ' ratings'));
                        }
                    }
                }
                Last edited by dAnceguy117; 04-24-2013, 04:02 PM.

                Comment

                • noname219
                  FFR Wiki Admin
                  • May 2007
                  • 1694

                  #9
                  Re: Java/Greasemonkey problem

                  Gives me no number of releases, just an "undefined" value.

                  You can also add this at rows 99-101 (so it will calculate bootlegs, videos and tributes) :
                  Code:
                  parseAlbum('album_disc_b');
                  parseAlbum('album_disc_d');
                  parseAlbum('album_disc_t');
                  Last edited by noname219; 04-24-2013, 07:10 PM.

                  Comment

                  • dAnceguy117
                    new hand moves = dab
                    FFR Simfile Author
                    • Dec 2002
                    • 10097

                    #10
                    Re: Java/Greasemonkey problem

                    ohh wow, I misread everything. qq had it right.

                    let me know how this one goes. I'm not testing anything, haha.

                    Code:
                    // ==UserScript== 
                    // @name       RYM Artist Rating 
                    // @version    0.2 
                    // @description  Compiles all RYM Artist Page data and displays the Artist rating beside the artist name 
                    // @match      http://rateyourmusic.com/artist/* 
                    // @copyright  2012+, quiapz, AnniesBoobs 
                    // ==/UserScript== 
                    function parseAlbum(albumType) {
                        var albums = (document.getElementById(albumType));
                        if (albums != null) {
                            albums = albums.getElementsByTagName('tr');
                    
                            // get number of albums. danceguy sucks at coding
                            numAlbums = albums.length - 2;
                    
                            var artistRating = albums.length;
                            for (var j = 2; j < artistRating; j++) {
                                albumRow = albums[j];
                                if ((!albumRow.hasAttribute("class")) && (albumRow.cells[4].textContent != '') && (albumRow.cells[6].textContent != '')) {
                                    ratings = parseInt((albumRow.cells[4].textContent).replace(/\,/g, ''));
                                    score = parseFloat(albumRow.cells[6].textContent);
                                    ratingCtr = ratingCtr + ratings;
                                    scoreCtr = scoreCtr + score;
                                    totCtr = totCtr + (ratings * score);
                                    if (albumType != 'album_disc_c') {
                                        if (1919 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1930) {
                                            decadeStats[0][1] = decadeStats[0][1] + (ratings * score);
                                            decadeStats[0][2] = decadeStats[0][2] + ratings;
                                        } else if (1929 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1940) {
                                            decadeStats[1][1] = decadeStats[1][1] + (ratings * score);
                                            decadeStats[1][2] = decadeStats[1][2] + ratings;
                                        } else if (1939 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1950) {
                                            decadeStats[2][1] = decadeStats[2][1] + (ratings * score);
                                            decadeStats[2][2] = decadeStats[2][2] + ratings;
                                        } else if (1949 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1960) {
                                            decadeStats[3][1] = decadeStats[3][1] + (ratings * score);
                                            decadeStats[3][2] = decadeStats[3][2] + ratings;
                                        } else if (1959 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1970) {
                                            decadeStats[4][1] = decadeStats[4][1] + (ratings * score);
                                            decadeStats[4][2] = decadeStats[4][2] + ratings;
                                        } else if (1969 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1980) {
                                            decadeStats[5][1] = decadeStats[5][1] + (ratings * score);
                                            decadeStats[5][2] = decadeStats[5][2] + ratings;
                                        } else if (1979 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1990) {
                                            decadeStats[6][1] = decadeStats[6][1] + (ratings * score);
                                            decadeStats[6][2] = decadeStats[6][2] + ratings;
                                        } else if (1989 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 2000) {
                                            decadeStats[7][1] = decadeStats[7][1] + (ratings * score);
                                            decadeStats[7][2] = decadeStats[7][2] + ratings;
                                        } else if (1999 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 2010) {
                                            decadeStats[8][1] = decadeStats[8][1] + (ratings * score);
                                            decadeStats[8][2] = decadeStats[8][2] + ratings;
                                        } else if (2009 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 2020) {
                                            decadeStats[9][1] = decadeStats[9][1] + (ratings * score);
                                            decadeStats[9][2] = decadeStats[9][2] + ratings;
                                        }
                                    }
                                    if (!isNaN(parseInt(albumRow.cells[7].textContent))) {
                                        youRating = youRating + parseFloat(albumRow.cells[7].textContent.substring(0, 4));
                                        youRated++;
                                    }
                                }
                            }
                        }
                    }
                    
                    function addCommas(nStr) {
                        nStr += '';
                        y = nStr.split('.');
                        y1 = y[0];
                        y2 = y.length > 1 ? '.' + y[1] : '';
                        var rgx = /(\d+)(\d{3})/;
                        while (rgx.test(y1)) {
                            y1 = y1.replace(rgx, '$1' + ',' + '$2');
                        }
                        return y1 + y2;
                    }
                    // Go through the Album discography and compute Artist Rating using Ratings and Overall Score of each album 
                    var ratingCell, scoreCell, albumRow, numAlbums;
                    var scoreCtr = 0;
                    var ratingCtr = 0;
                    var totCtr = 0;
                    var youRating = 0;
                    var youRated = 0;
                    var decadeStats = [
                        ['1920s: ', 0, 0],
                        ['1930s: ', 0, 0],
                        ['1940s: ', 0, 0],
                        ['1950s: ', 0, 0],
                        ['1960s: ', 0, 0],
                        ['1970s: ', 0, 0],
                        ['1980s: ', 0, 0],
                        ['1990s: ', 0, 0],
                        ['2000s: ', 0, 0],
                        ['2010s: ', 0, 0]
                    ];
                    parseAlbum('album_disc_s');
                    parseAlbum('album_disc_i');
                    parseAlbum('album_disc_e');
                    parseAlbum('album_disc_c');
                    // Display the data under the artist name as the first row of the profile table 
                    if (ratingCtr > 0) {
                        var mbgens = document.getElementsByClassName('mbgen');
                        var bio = mbgens[0];
                        var row = bio.insertRow(0);
                        var newCell;
                    
                        if (youRated > 0) {
                            x = (-((totCtr / ratingCtr).toFixed(9) - (youRating / youRated).toFixed(9)).toFixed(9));
                            if (x >= 0) {
                                x = '+' + x.toFixed(9);
                            }
                            // include the number of albums in the second element of the row. danceguy is amazing omg
                            var rowValues = ['Artist Rating', (totCtr / ratingCtr).toFixed(9) + ' from ' + addCommas(ratingCtr) + ' ratings and ' + numAlbums + ' releases, Your rating: ' + (youRating / youRated).toFixed(9) + ' from ' + addCommas(youRated) + ' ratings (RYM ' + x + ')'];
                        } else {
                            // include the number of albums in the second element of the row. danceguy listens to better music than you
                            var rowValues = ['Artist Rating', (totCtr / ratingCtr).toFixed(9) + ' from ' + addCommas(ratingCtr) + ' ratings and ' + numAlbums + ' releases'];
                        }
                        for (var i = 0, ii = rowValues.length; i < ii; i++) {
                            newCell = row.insertCell(i);
                            newCell.appendChild(document.createTextNode(rowValues[i]));
                        }
                    
                        var row = bio.insertRow(bio.getElementsByTagName("TR").length);
                        var newCell;
                        newCell1 = row.insertCell(0);
                        newCell1.appendChild(document.createTextNode('Music stats'));
                        newCell = row.insertCell(1);
                        x = document.createElement('b');
                        newCell.appendChild(x);
                        x.appendChild(document.createTextNode('Average by Decade:'));
                        for (d = 0; d < decadeStats.length; d++) {
                            if (decadeStats[d][2] > 0) {
                                newCell.appendChild(document.createElement('br'));
                                newCell.appendChild(document.createTextNode(decadeStats[d][0] + (decadeStats[d][1] / decadeStats[d][2]).toFixed(2) + ', from ' + addCommas(decadeStats[d][2]) + ' ratings'));
                            }
                        }
                    }

                    Comment

                    • noname219
                      FFR Wiki Admin
                      • May 2007
                      • 1694

                      #11
                      Re: Java/Greasemonkey problem

                      Copypasting everything gives me 3 albums for Broken Bells. (should be 6 albums instead)
                      (http://rateyourmusic.com/artist/broken_bells_f1)
                      Last edited by noname219; 04-25-2013, 06:47 AM.

                      Comment

                      • dAnceguy117
                        new hand moves = dab
                        FFR Simfile Author
                        • Dec 2002
                        • 10097

                        #12
                        Re: Java/Greasemonkey problem

                        interesting. let's try fudging the numbers, lmfao. these should be correct for Broken Bells but probably won't work for other artists.

                        replace the line that's spaced out near the top with one of these at a time.

                        Code:
                        // get number of albums. danceguy sucks at coding
                                numAlbums = albums.length + 1;
                        Code:
                        // get number of albums. danceguy sucks at coding
                                numAlbums = (albums.length - 2) * 2;


                        hmmm. now that I look at the link in your above post, I think this problem could be pretty tricky. which six releases are the ones you want included?

                        Comment

                        • noname219
                          FFR Wiki Admin
                          • May 2007
                          • 1694

                          #13
                          Re: Java/Greasemonkey problem

                          Originally posted by dAnceguy117
                          Code:
                          // get number of albums. danceguy sucks at coding
                                  numAlbums = albums.length + 1;
                          Code:
                          // get number of albums. danceguy sucks at coding
                                  numAlbums = (albums.length - 2) * 2;
                          Those two lines gives me 6 albums for each of them, but they don't make sense with other artists.

                          Originally posted by dAnceguy117
                          hmmm. now that I look at the link in your above post, I think this problem could be pretty tricky. which six releases are the ones you want included?
                          It's actually 7 albums (with the bootleg) :
                          Broken Bells (album)
                          Meyrin Fields EP
                          The High Road
                          The Ghost Inside
                          October
                          Meyrin Fields
                          The MySpace Transmissions
                          (no appearances, but they shouldn't be included by default)

                          You should add this in the code :
                          Code:
                          parseAlbum('album_disc_b');
                          parseAlbum('album_disc_d');
                          parseAlbum('album_disc_t');
                          (should add the cumulative rating of other sections I mentioned above - post#9)
                          Last edited by noname219; 04-25-2013, 09:06 AM.

                          Comment

                          • dAnceguy117
                            new hand moves = dab
                            FFR Simfile Author
                            • Dec 2002
                            • 10097

                            #14
                            Re: Java/Greasemonkey problem

                            I'm an idiot

                            give this one a shot. extra parseAlbum lines included, but I removed
                            parseAlbum('album_disc_c');
                            because I don't think you want to include the compilations. right?

                            Code:
                            // ==UserScript== 
                            // @name       RYM Artist Rating 
                            // @version    0.2 
                            // @description  Compiles all RYM Artist Page data and displays the Artist rating beside the artist name 
                            // @match      http://rateyourmusic.com/artist/* 
                            // @copyright  2012+, quiapz, AnniesBoobs 
                            // ==/UserScript== 
                            function parseAlbum(albumType) {
                                var albums = (document.getElementById(albumType));
                                if (albums != null) {
                            
                                    // get number of albums. danceguy enjoys leaving verbose comments
                                    numAlbums += (albums.length - 2);
                            
                                    albums = albums.getElementsByTagName('tr');
                                    var artistRating = albums.length;
                                    for (var j = 2; j < artistRating; j++) {
                                        albumRow = albums[j];
                                        if ((!albumRow.hasAttribute("class")) && (albumRow.cells[4].textContent != '') && (albumRow.cells[6].textContent != '')) {
                                            ratings = parseInt((albumRow.cells[4].textContent).replace(/\,/g, ''));
                                            score = parseFloat(albumRow.cells[6].textContent);
                                            ratingCtr = ratingCtr + ratings;
                                            scoreCtr = scoreCtr + score;
                                            totCtr = totCtr + (ratings * score);
                                            if (albumType != 'album_disc_c') {
                                                if (1919 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1930) {
                                                    decadeStats[0][1] = decadeStats[0][1] + (ratings * score);
                                                    decadeStats[0][2] = decadeStats[0][2] + ratings;
                                                } else if (1929 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1940) {
                                                    decadeStats[1][1] = decadeStats[1][1] + (ratings * score);
                                                    decadeStats[1][2] = decadeStats[1][2] + ratings;
                                                } else if (1939 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1950) {
                                                    decadeStats[2][1] = decadeStats[2][1] + (ratings * score);
                                                    decadeStats[2][2] = decadeStats[2][2] + ratings;
                                                } else if (1949 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1960) {
                                                    decadeStats[3][1] = decadeStats[3][1] + (ratings * score);
                                                    decadeStats[3][2] = decadeStats[3][2] + ratings;
                                                } else if (1959 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1970) {
                                                    decadeStats[4][1] = decadeStats[4][1] + (ratings * score);
                                                    decadeStats[4][2] = decadeStats[4][2] + ratings;
                                                } else if (1969 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1980) {
                                                    decadeStats[5][1] = decadeStats[5][1] + (ratings * score);
                                                    decadeStats[5][2] = decadeStats[5][2] + ratings;
                                                } else if (1979 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 1990) {
                                                    decadeStats[6][1] = decadeStats[6][1] + (ratings * score);
                                                    decadeStats[6][2] = decadeStats[6][2] + ratings;
                                                } else if (1989 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 2000) {
                                                    decadeStats[7][1] = decadeStats[7][1] + (ratings * score);
                                                    decadeStats[7][2] = decadeStats[7][2] + ratings;
                                                } else if (1999 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 2010) {
                                                    decadeStats[8][1] = decadeStats[8][1] + (ratings * score);
                                                    decadeStats[8][2] = decadeStats[8][2] + ratings;
                                                } else if (2009 < albumRow.cells[0].textContent && albumRow.cells[0].textContent < 2020) {
                                                    decadeStats[9][1] = decadeStats[9][1] + (ratings * score);
                                                    decadeStats[9][2] = decadeStats[9][2] + ratings;
                                                }
                                            }
                                            if (!isNaN(parseInt(albumRow.cells[7].textContent))) {
                                                youRating = youRating + parseFloat(albumRow.cells[7].textContent.substring(0, 4));
                                                youRated++;
                                            }
                                        }
                                    }
                                }
                            }
                            
                            function addCommas(nStr) {
                                nStr += '';
                                y = nStr.split('.');
                                y1 = y[0];
                                y2 = y.length > 1 ? '.' + y[1] : '';
                                var rgx = /(\d+)(\d{3})/;
                                while (rgx.test(y1)) {
                                    y1 = y1.replace(rgx, '$1' + ',' + '$2');
                                }
                                return y1 + y2;
                            }
                            // Go through the Album discography and compute Artist Rating using Ratings and Overall Score of each album 
                            var ratingCell, scoreCell, albumRow;
                            var numAlbums = 0;
                            var scoreCtr = 0;
                            var ratingCtr = 0;
                            var totCtr = 0;
                            var youRating = 0;
                            var youRated = 0;
                            var decadeStats = [
                                ['1920s: ', 0, 0],
                                ['1930s: ', 0, 0],
                                ['1940s: ', 0, 0],
                                ['1950s: ', 0, 0],
                                ['1960s: ', 0, 0],
                                ['1970s: ', 0, 0],
                                ['1980s: ', 0, 0],
                                ['1990s: ', 0, 0],
                                ['2000s: ', 0, 0],
                                ['2010s: ', 0, 0]
                            ];
                            parseAlbum('album_disc_s');
                            parseAlbum('album_disc_i');
                            parseAlbum('album_disc_e');
                            parseAlbum('album_disc_b');
                            parseAlbum('album_disc_d');
                            parseAlbum('album_disc_t');
                            // Display the data under the artist name as the first row of the profile table 
                            if (ratingCtr > 0) {
                                var mbgens = document.getElementsByClassName('mbgen');
                                var bio = mbgens[0];
                                var row = bio.insertRow(0);
                                var newCell;
                            
                                if (youRated > 0) {
                                    x = (-((totCtr / ratingCtr).toFixed(9) - (youRating / youRated).toFixed(9)).toFixed(9));
                                    if (x >= 0) {
                                        x = '+' + x.toFixed(9);
                                    }
                                    // include the number of albums in the second element of the row. danceguy is amazing omg
                                    var rowValues = ['Artist Rating', (totCtr / ratingCtr).toFixed(9) + ' from ' + addCommas(ratingCtr) + ' ratings and ' + numAlbums + ' releases, Your rating: ' + (youRating / youRated).toFixed(9) + ' from ' + addCommas(youRated) + ' ratings (RYM ' + x + ')'];
                                } else {
                                    // include the number of albums in the second element of the row. danceguy listens to better music than you
                                    var rowValues = ['Artist Rating', (totCtr / ratingCtr).toFixed(9) + ' from ' + addCommas(ratingCtr) + ' ratings and ' + numAlbums + ' releases'];
                                }
                                for (var i = 0, ii = rowValues.length; i < ii; i++) {
                                    newCell = row.insertCell(i);
                                    newCell.appendChild(document.createTextNode(rowValues[i]));
                                }
                            
                                var row = bio.insertRow(bio.getElementsByTagName("TR").length);
                                var newCell;
                                newCell1 = row.insertCell(0);
                                newCell1.appendChild(document.createTextNode('Music stats'));
                                newCell = row.insertCell(1);
                                x = document.createElement('b');
                                newCell.appendChild(x);
                                x.appendChild(document.createTextNode('Average by Decade:'));
                                for (d = 0; d < decadeStats.length; d++) {
                                    if (decadeStats[d][2] > 0) {
                                        newCell.appendChild(document.createElement('br'));
                                        newCell.appendChild(document.createTextNode(decadeStats[d][0] + (decadeStats[d][1] / decadeStats[d][2]).toFixed(2) + ', from ' + addCommas(decadeStats[d][2]) + ' ratings'));
                                    }
                                }
                            }




                            edit:

                            the magic number here should be 8. excluding anything with "Appears on" would be the finishing touch.

                            if it gives you 4 albums for Broken Bells, let me know. that's an easy fix.
                            Last edited by dAnceguy117; 04-25-2013, 11:15 AM.

                            Comment

                            • noname219
                              FFR Wiki Admin
                              • May 2007
                              • 1694

                              #15
                              Re: Java/Greasemonkey problem

                              Gives me a NaN...

                              And compilations will get included as well, but if you remove it, you'll affect the average rating at the same time.

                              Comment

                              Working...