議論 » 開発

Please help me make this userscript from USO work again

§
投稿日: 2014/10/09
編集日: 2014/10/09

Please help me make this userscript from USO work again

I'm trying to make this script from USO "Rotten Tomatoes Decimal Rating" work again.
His developer, erosman, had done it, based on a request of mine, but I can't contact him now about this.
(I don't think that he's a member here in greasyfork). That script does two things:

  • multiplies the Audience Score *2, and
  • changes the text in the tooltip so that it says "7 stars or higher" instead of "3.5 stars or higher"

http://s3.amazonaws.com/uso_ss/25646/large.jpg?1394307357: http://s3.amazonaws.com/uso_ss/25647/large.jpg?1394307380

I've tweaked it a bit from

// ==UserScript==
// @name          Rotten Tomatoes Decimal Rating
// @namespace     erosman
// @description   Change Base 5 Rating of Rotten Tomatoes to Base 10
// @updateURL     https://userscripts.org/scripts/source/407724.meta.js
// @downloadURL   https://userscripts.org/scripts/source/407724.user.js
// @include       http://www.rottentomatoes.com/*
// @grant         none
// @author        erosman
// @version       1.0
// ==/UserScript==
/* --------- Note ---------
  This script changes the Base 5 rating of Rotten Tomatoes to Base 10.
  (per request: http://userscripts.org/topics/205596)
  --------- History ---------
   1.0 Initial release */


(function() { // anonymous function wrapper, used for error checking & limiting scope
'use strict';

if (window.self !== window.top) { return; } // end execution if in a frame

var elem = document.getElementsByClassName('fan_side');
if (!elem[0]) { return; }  // end execution if not found

var help = elem[0].getElementsByClassName('help');
if (help[0]) {
  help[0].setAttribute('tip', 
  help[0].getAttribute('tip').replace(/([\d.]+) star/, function(m) { return 2*parseFloat(m)+ ' star'; }));
}

var critic = elem[0].getElementsByClassName('critic_stats');
if (critic[0]) {
  critic[0].innerHTML = critic[0].innerHTML.replace(/([\d.]+)\/5/, function(m) { return 2*parseFloat(m)+ '/10'; });
}


})(); // end of anonymous function

into

// ==UserScript==
// @name          Rotten Tomatoes Decimal Rating
// @namespace     erosman
// @description   Change Base 5 Rating of Rotten Tomatoes to Base 10
// @updateURL     https://userscripts.org/scripts/source/407724.meta.js
// @downloadURL   https://userscripts.org/scripts/source/407724.user.js
// @include       http://www.rottentomatoes.com/*
// @grant         none
// @author        erosman
// @version       1.0
// ==/UserScript==
/* --------- Note ---------
  This script changes the Base 5 rating of Rotten Tomatoes to Base 10.
  (per request: http://userscripts.org/topics/205596)


  --------- History ---------


  1.0 Initial release

*/
(function () { // anonymous function wrapper, used for error checking & limiting scope
  'use strict';
  if (window.self !== window.top) {
    return;
  }
  // end execution if in a frame

  var elem = document.getElementsByClassName('audiencepanel');
  if (!elem[0]) { return; } // end execution if not found

var help = elem[0].getElementsByClassName('glyphicon /glyphicon-question-sign');
if (help[0]) {
    help[0].setAttribute('data-original-title', 
    help[0].getAttribute('data-original-title').replace(/([\d.]+) star/, function (m) { return 2 * parseFloat(m) + ' star';  }));
}

var critic = elem[0].getElementsByClassName('audience-info');
if (critic[0]) {
critic[0].innerHTML = critic[0].innerHTML.replace(/([\d.]+)\/5/, function (m) {
  return 2 * parseFloat(m) + '/10';
});
}
}) (); // end of anonymous function

and unfortunately it works only for the first part.
The problematic part is this, I think:

var help = elem[0].getElementsByClassName('glyphicon /glyphicon-question-sign');
if (help[0]) {
    help[0].setAttribute('data-original-title', 
    help[0].getAttribute('data-original-title').replace(/([\d.]+) star/, function (m) { return 2 * parseFloat(m) + ' star';  }));
}

Please help me with this.

§
投稿日: 2014/10/09
編集日: 2014/10/09

And, if it helps you, the following link (from archive.org)
is a snapshot from a page from rottentomatoes.org taken in March, i.e. about the time the script was written
http://web.archive.org/web/20140304102559/http://www.rottentomatoes.com/m/godfather/


Also, I've updated my version of the script in the first post.
It's better now, I think, but still it works for the first part only.

woxxomMod
§
投稿日: 2014/10/09
編集日: 2014/10/09

The site appears to add these rating blocks dynamically, so the simplest solution would be to execute after everything loads (you'll briefly see the original 5-based rating):

window.addEventListener('load', function(e) {
    if (r = document.querySelector('.audiencepanel h3 span'))
        r.setAttribute('data-original-title', 
        r.getAttribute('data-original-title').replace(/([\d.]+)( stars)/, 
            function(m, s1, s2) { return 2 * s1 + s2 }));

    if (r = document.querySelector('.audience-info dd:nth-child(2)'))
        r.innerHTML = r.innerHTML.replace(/[\d.]+/g,
            function(m) { return 2 * m });
});

(This code replaces everything after the last header line: // ==/UserScript==)

A better solution I guess would be to use a mutation observer, which is quite simple as well but I'm off to sleep right now.

§
投稿日: 2014/10/09

Thank you very much. It works!!

Just one minor thing, please:
could you make it so that, for the Average Rating,
the "/5" to also change into " /10" ?
For example:
4.3/5 --> 8.6/10
and not 8.6/5

§
投稿日: 2014/10/09

Thanks so much for your help.
Now it's complete.

§
投稿日: 2014/10/09
編集日: 2015/09/04

I made one addition, based on your code:
the popup of the '?' next to the word TOMATOMETER, to display:
instead of
"The percentage of Approved Tomatometer Critics who have given this movie a positive review", this
"The percentage of Approved Tomatometer Critics who have given this movie a positive review (=6 stars or higher)"

update 04/03/15: the selectors used in the 1st and 3rd if have changed today.
I've uploaded it here

window.addEventListener('load', function(e) {
    if (r = document.querySelector('h3.scoreTitle:nth-child(1) > span:nth-child(1)'))
        r.setAttribute('title', 
        r.getAttribute('title').replace(/([\d.]+)( stars)/, 
            function(m, s1, s2) { return 2 * s1 + s2 }));

    if (r = document.querySelector('.audience-info div:nth-child(1)'))
        r.innerHTML = r.innerHTML.replace(/[\d.]+/g,
            function(m) { return 2 * m });

    if (r = document.querySelector('h3.scoreTitle:nth-child(2) > span:nth-child(1)'))
        r.setAttribute('title', 
        r.getAttribute('title')+(' (=6 stars or higher)'));

});
§
投稿日: 2015/09/04
編集日: 2015/09/05

(please delete)

返信を投稿

返信を投稿するにはログインしてください。