Java/Greasemonkey problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • #16
    new hand moves = dab
    FFR Simfile Author
    dAnceguy117
    • Dec 2002
    • 10129

    Re: Java/Greasemonkey problem

    oops I grabbed the wrong version lmfao. compilations put back in, so you should get 11.


    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 needs better version control
            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;
    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');
    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-25-2013, 12:27 PM.

    Comment

    • #17
      FFR Wiki Admin
      noname219
      • May 2007
      • 1701

      Re: Java/Greasemonkey problem

      Awww yeah. :) Gives me the exact number on every page.

      Only thing left is to remove the appearances and everything will be perfect.

      Comment

      • #18
        new hand moves = dab
        FFR Simfile Author
        dAnceguy117
        • Dec 2002
        • 10129

        Re: Java/Greasemonkey problem

        sweeeet hahah. I'll take a crack at the final changes over the weekend.

        unless someone else wants to! QQ, I KNOW YOU'RE WATCHING

        Comment

        • #19
          new hand moves = dab
          FFR Simfile Author
          dAnceguy117
          • Dec 2002
          • 10129

          Re: Java/Greasemonkey problem

          bump, sorry again for the holdup. can't believe it's been a month, what the...

          noname, where do you put this script/run it from? knocking this out would probably be 10x faster if I could test it myself

          Comment

          • #20
            FFR Wiki Admin
            noname219
            • May 2007
            • 1701

            Re: Java/Greasemonkey problem

            Not sure if I understand your question.
            This is the website : http://rateyourmusic.com/
            The script acts everytime you load an artist page. (supposing you already have downloaded the Greasemonkey extension for Firefox/Chrome)

            Comment

            • #21
              new hand moves = dab
              FFR Simfile Author
              dAnceguy117
              • Dec 2002
              • 10129

              Re: Java/Greasemonkey problem

              Originally posted by noname219
              The script acts everytime you load an artist page. (supposing you already have downloaded the Greasemonkey extension for Firefox/Chrome)
              I haven't, haha. will grab it soon!

              Comment

              • #22
                new hand moves = dab
                FFR Simfile Author
                dAnceguy117
                • Dec 2002
                • 10129

                Re: Java/Greasemonkey problem

                working on this

                right now

                so sorry for the holdup




                edit:

                GOT IT! I hope.


                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 
                
                // also danceguy made some modifications. wow he's so cool
                
                // ==/UserScript== 
                function parseAlbum(albumType) {
                    var albums = (document.getElementById(albumType));
                    if (albums != null) {
                        albums = albums.getElementsByTagName('tr');
                
                        // get number of albums for this section, including appearances.
                        numAlbums += (albums.length - 2);
                		
                	// EXCLUDE those appearances.
                	for (var j = 2; j < albums.length; j++)
                	{
                		albumRow = albums[j];
                			
                		// IF the "title" element contains "Appears" THEN exclude the album from the running total.
                		if (albumRow.cells[1].textContent.indexOf("Appears") !== -1)
                			numAlbums--;
                	}
                
                        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 numUnfilteredAlbums = 0;
                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');
                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.
                        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.
                        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'));
                        }
                    }
                }


                Let me know what you think!

                Possible issue: an album would be excluded from the total if its title contains the word "Appears" lol. Holla back if that will be a problem.
                Last edited by dAnceguy117; 06-1-2013, 07:44 PM.

                Comment

                • #23
                  FFR Wiki Admin
                  noname219
                  • May 2007
                  • 1701

                  Re: Java/Greasemonkey problem

                  This is exactly what I wanted. Huge thanks! ;)

                  If you're curious why I needed this : http://rateyourmusic.com/list/noname219/top_artists
                  Basically, the script will automatically calculate the avg. rating, number of ratings and number of albums for every artist page I'm gonna load from now on. (I was doing this by copy/pasting the data in a Excel file and that was time consumming...)

                  Sent you as well some caps.

                  Comment

                  • #24
                    new hand moves = dab
                    FFR Simfile Author
                    dAnceguy117
                    • Dec 2002
                    • 10129

                    Re: Java/Greasemonkey problem

                    :D

                    we have a good number of those top artists in common, by the way!

                    Comment

                    • #25
                      FFR Wiki Admin
                      noname219
                      • May 2007
                      • 1701

                      Re: Java/Greasemonkey problem

                      It's the average rating of all registered members from the website, not from my personnal subjective pov. But if you're curious, you can check (http://rateyourmusic.com/collection/noname219/r4.5-5.0) or (http://rateyourmusic.com/list/noname...onus___cookie_) for stuff that I like the most.

                      If you're interested, I can create lists like this from every possible existing music genre (it just have to be listed on the website).

                      Comment

                      Working...