Yahoo!番組表の映画にレビュー点数を表示する
最近、WOWWOWの映画を見てまして、だいたいYahoo!映画のレビュー点数4点以上(5点満点)を基準に見るものを選んでいます。
ひとつひとつレビュー点数を検索するのが面倒だったので、ChromeのUserScriptで番組表に表示できるようにしてみました。
Yahoo!番組表用UserScript
// ==UserScript==
// @name Yahoo!番組表 映画レビュー点数反映
// @namespace http://n.blueblack.net/
// @include http://tv.yahoo.co.jp/listings/bs2/*
// @include http://tv.yahoo.co.jp/listings/?*&t=BS2*
// @description Yahoo!番組表の映画にレビュー点数を表示する
// ==/UserScript==
//How can I use jQuery in Greasemonkey scripts in Google Chrome? - Stack Overflow
//http://stackoverflow.com/questions/2246901/how-can-i-use-jquery-in-greasemonkey-scripts-in-google-chrome
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function main() {
// jquery.xdomainajax.js
// https://github.com/padolsey/jquery.fn/blob/master/cross-domain-ajax/jquery.xdomainajax.js
jQ.ajax = (function(_ajax){
var protocol = location.protocol,
hostname = location.hostname,
exRegex = RegExp(protocol + '//' + hostname),
YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?',
query = 'select * from html where url="{URL}" and xpath="*"';
function isExternal(url) {
return !exRegex.test(url) && /:\/\//.test(url);
}
return function(o) {
var url = o.url;
if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) {
// Manipulate options so that JSONP-x request is made to YQL
o.url = YQL;
o.dataType = 'json';
o.data = {
q: query.replace(
'{URL}',
url + (o.data ?
(/\?/.test(url) ? '&' : '?') + jQ.param(o.data)
: '')
),
format: 'xml'
};
// Since it's a JSONP request
// complete === success
if (!o.success && o.complete) {
o.success = o.complete;
delete o.complete;
}
o.success = (function(_success){
return function(data) {
if (_success) {
// Fake XHR callback.
_success.call(this, {
responseText: (data.results[0] || '')
// YQL screws with <script>s
// Get rid of them
.replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi, '')
}, 'success');
}
};
})(o.success);
}
return _ajax.apply(this, arguments);
};
})(jQ.ajax);
var counter = 0;
jQ("#tvpgm img.programIcon[src='http://i.yimg.jp/i/tv/ntv/images/movie.gif']").each(function (index, domEle) {
var title_ele = $(domEle).parent().find("a");
if (title_ele.attr("data-ylk").match(/pos:\d+_\d+_3/)) {
setTimeout(function () {
var movie_title = title_ele.text();
var search_url = "http://movies.yahoo.co.jp/search/?query=" + encodeURIComponent(movie_title);
jQ.ajax({
url: search_url,
type: "GET",
cache: false,
success: function(res){
var movie_rating = "";
var review_count = "";
var result_title = "";
var rating_ele = $(res.responseText).find('#list-module span.rating-score:first');
var review_ele = $(res.responseText).find('#list-module ul li:nth-child(3) span.stat__number:first');
var title_ele = $(res.responseText).find('#list-module h3:first');
if (rating_ele.length) {
movie_rating = rating_ele.text().replace(/^([\d.]+)[\s\S]*/, "$1");
review_count = review_ele.text();
result_title = title_ele.text().replace(/\n/g, "").replace(/\s+\(/, "(");
} else {
movie_rating = "-";
}
var bg_color = "#ccc";
if (parseFloat(movie_rating) >= 4.0) {
bg_color = "hotpink";
} else if (parseFloat(movie_rating) >= 3.7) {
bg_color = "pink";
}
$(domEle).before("<a href='" + search_url + "' target='_blank' style='background: " + bg_color + "; margin: 0 3px 0 1px; padding: 1px 0 0 2px; text-decoration: none; color: #333' title='" + result_title + "'>" + movie_rating + "(" + review_count + ")</span>");
}
});
}, 5000*counter);
counter += 1;
}
});
}
addJQuery(main);
使い方ははてなブックマークのhotentryをUserScriptでキー拡張すると同じ。
「レビュー点数(レビュー数)」で順に表示されていきます。よく分かりませんが、ページを再読み込みしないと動かなかったりします。
おすすめ映画
ついでに、WOWWOWで見て面白かった映画を紹介します。
嘆きのピエタ
韓国映画です。すごく暗くて、救いがなくて、いい感じ。ラストが非常に印象的。【Y!映画 : 4.07点】
ヘッドハンター
ノルウェー・ドイツ合作映画です。シナリオが凝ってて伏線回収が気持ちいい。【Y!映画 : 3.96点】
あの頃、君を追いかけた
台湾映画です。恋愛映画。切ない。【Y!映画 : 4.23点】
ザ・ファイブ-選ばれた復讐者-
韓国映画です。かなり怖い。精神的なダメージを受ける。【Y!映画 : 3.67点】