There are 1 previous version of this script.
// ==UserScript==
// @name Wiki Tomatoes
// @namespace http://www.chocolatey.com/code/js
// @description Adds a Rotten Tomatoes link to Wikipedia film articles that contain an IMDb link
// @version 0.02
// @author chocolateboy
// @license GPL: http://www.gnu.org/copyleft/gpl.html
// @include *.wikipedia.org/wiki/*
// ==/UserScript==
const $attrs = 'href="$href" class="external text" title="$href" rel="nofollow"';
const $rt = '<a href="/wiki/Rotten_Tomatoes" title="Rotten Tomatoes">Rotten Tomatoes</a>';
const $locales = {
de: '<a $attrs>Kritiken zu <i>$title</i></a> auf $rt (englisch)',
en: '<a $attrs><i>$title</i></a> at $rt',
es: '<a $attrs><i>$title</i></a> en $rt (en inglés)',
fr: '<span style="cursor:help;font-family:monospace;font-weight:bold;font-size:small" title="Langue : anglais">' +
'(en)' +
'</span> ' +
'<a $attrs><i>$title</i></a> sur $rt',
it: '(<span style="font-weight: bolder; font-size: 80%">' +
'<a href="/wiki/Lingua_inglese" title="Lingua inglese">EN</a>' +
'</span>) <a $attrs><i>$title</i></a> su $rt'
};
/*
* Find a ul/li/a @class="external" link to an IMDb title that doesn't have a Rotten Tomatoes sibling
*/
const $xpath = '//ul[count(li//a[contains(@class, "external") and contains(@href, "rottentomatoes.com/")])=0]' +
'/li//a[contains(@class, "external") and contains(@href, "imdb.com/title/tt")]';
function localize($title, $href) {
var $locale = location.hostname.split('.')[0];
var $template = $locales[$locale] || $locales['en'];
var $html = $template.
replace(/\$attrs/, $attrs).
replace(/\$href/g, $href).
replace(/\$title/, $title).
replace(/\$rt/, $rt);
return $html;
}
var $imdb_link = document.evaluate($xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if ($imdb_link) {
var $imdb_id = $imdb_link.getAttribute('href').match(/\/title\/tt(\w+)/)[1];
var $rt_uri = 'http://www.rottentomatoes.com/alias?type=imdbid&s=' + $imdb_id;
var $imdb_li = $imdb_link.parentNode;
while ($imdb_li.tagName.toLowerCase() != 'li') {
$imdb_li = $imdb_li.parentNode;
}
var $title = $imdb_link.textContent;
var $rt_li = document.createElement('li');
$rt_li.innerHTML = localize($title, $rt_uri);
$imdb_li.appendChild($rt_li);
}
