Go Back   Flash Flash Revolution > General Discussion > Technology
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 04-23-2013, 03:41 PM   #1
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default Java/Greasemonkey problem resolved

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 at 08:16 PM..
noname219 is offline   Reply With Quote
Old 04-24-2013, 10:38 AM   #2
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default Re: Java/Greasemonkey problem

Bump, who here wants 50k credits ?
noname219 is offline   Reply With Quote
Old 04-24-2013, 12:10 PM   #3
qqwref
stepmania archaeologist
Retired StaffFFR Simfile AuthorFFR Veteran
 
qqwref's Avatar
 
Join Date: Aug 2005
Age: 34
Posts: 4,090
Default 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)
qqwref is offline   Reply With Quote
Old 04-24-2013, 12:24 PM   #4
Untimely Friction
D6 Challeneged
Retired StaffFFR Veteran
 
Untimely Friction's Avatar
 
Join Date: Aug 2012
Age: 31
Posts: 1,267
Default Re: Java/Greasemonkey problem

Quote:
Originally Posted by noname219 View Post
Bump, who here wants 50k credits ?
Me! But I don't know Java/greasemonkey well...
Untimely Friction is offline   Reply With Quote
Old 04-24-2013, 12:24 PM   #5
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default 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.
noname219 is offline   Reply With Quote
Old 04-24-2013, 12:28 PM   #6
qqwref
stepmania archaeologist
Retired StaffFFR Simfile AuthorFFR Veteran
 
qqwref's Avatar
 
Join Date: Aug 2005
Age: 34
Posts: 4,090
Default 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)
qqwref is offline   Reply With Quote
Old 04-24-2013, 12:30 PM   #7
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default Re: Java/Greasemonkey problem

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

Thanks for helping btw.
noname219 is offline   Reply With Quote
Old 04-24-2013, 04:44 PM   #8
dAnceguy117
new hand moves = dab
FFR Simfile AuthorFFR Veteran
 
dAnceguy117's Avatar
 
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
Default 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 at 05:02 PM..
dAnceguy117 is offline   Reply With Quote
Old 04-24-2013, 08:07 PM   #9
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default 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 at 08:10 PM..
noname219 is offline   Reply With Quote
Old 04-25-2013, 01:39 AM   #10
dAnceguy117
new hand moves = dab
FFR Simfile AuthorFFR Veteran
 
dAnceguy117's Avatar
 
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
Default 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'));
        }
    }
}
dAnceguy117 is offline   Reply With Quote
Old 04-25-2013, 07:30 AM   #11
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default 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 at 07:47 AM..
noname219 is offline   Reply With Quote
Old 04-25-2013, 09:39 AM   #12
dAnceguy117
new hand moves = dab
FFR Simfile AuthorFFR Veteran
 
dAnceguy117's Avatar
 
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
Default 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?
dAnceguy117 is offline   Reply With Quote
Old 04-25-2013, 09:52 AM   #13
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default Re: Java/Greasemonkey problem

Quote:
Originally Posted by dAnceguy117 View Post
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.

Quote:
Originally Posted by dAnceguy117 View Post
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 at 10:06 AM..
noname219 is offline   Reply With Quote
Old 04-25-2013, 12:10 PM   #14
dAnceguy117
new hand moves = dab
FFR Simfile AuthorFFR Veteran
 
dAnceguy117's Avatar
 
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
Default 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 at 12:15 PM..
dAnceguy117 is offline   Reply With Quote
Old 04-25-2013, 12:17 PM   #15
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default 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.
noname219 is offline   Reply With Quote
Old 04-25-2013, 12:24 PM   #16
dAnceguy117
new hand moves = dab
FFR Simfile AuthorFFR Veteran
 
dAnceguy117's Avatar
 
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
Default 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 at 12:27 PM..
dAnceguy117 is offline   Reply With Quote
Old 04-25-2013, 12:30 PM   #17
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default 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.
noname219 is offline   Reply With Quote
Old 04-25-2013, 12:40 PM   #18
dAnceguy117
new hand moves = dab
FFR Simfile AuthorFFR Veteran
 
dAnceguy117's Avatar
 
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
Default 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
dAnceguy117 is offline   Reply With Quote
Old 05-20-2013, 07:38 PM   #19
dAnceguy117
new hand moves = dab
FFR Simfile AuthorFFR Veteran
 
dAnceguy117's Avatar
 
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
Default 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
dAnceguy117 is offline   Reply With Quote
Old 05-20-2013, 07:46 PM   #20
noname219
FFR Wiki Admin
Wiki Administrator
Retired StaffFFR Veteran
 
noname219's Avatar
 
Join Date: May 2007
Location: Quebec, Canada
Age: 33
Posts: 1,694
Send a message via Skype™ to noname219
Default 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)
noname219 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:33 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution