Skip to content

Instantly share code, notes, and snippets.

@noromanba
Last active August 29, 2015 14:14
Show Gist options
  • Save noromanba/cd313dd2b15fbc6b4949 to your computer and use it in GitHub Desktop.
Save noromanba/cd313dd2b15fbc6b4949 to your computer and use it in GitHub Desktop.
Make Tabelog Stars more honest w/ Pager Extension for UserScript
// ==UserScript==
// @name Tabelog-HonestStars
// @namespace http://noromanba.flavors.me
// @description Make Tabelog Stars more honest w/ Pager Extension for UserScript
// @include http://tabelog.com/*
// @grant none
// @run-at document-end
// @noframes
// @version 2015.1.31.2
// @homepage https://gist.github.com/noromanba/cd313dd2b15fbc6b4949
// @downloadURL https://gist.github.com/noromanba/cd313dd2b15fbc6b4949/raw/tabelog-honeststars.user.js
// @contributor miyagawa https://github.com/miyagawa/Tabelog-HonestStars
// @orig-license Unknown (as-is)
// @license as-is
// @author noromanba http://noromanba.flavors.me
// @icon http://upload.wikimedia.org/wikipedia/commons/thumb/7/75/%D0%A7%D1%91%D1%80%D0%BD%D1%8B%D0%B9_%D0%BA%D0%B0%D0%BE%D0%B4%D0%B0%D0%B8%D1%81%D1%82%D1%81%D0%BA%D0%B8%D0%B9_%D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB.svg/32px-%D0%A7%D1%91%D1%80%D0%BD%D1%8B%D0%B9_%D0%BA%D0%B0%D0%BE%D0%B4%D0%B0%D0%B8%D1%81%D1%82%D1%81%D0%BA%D0%B8%D0%B9_%D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB.svg.png
// @icon64 http://upload.wikimedia.org/wikipedia/commons/thumb/7/75/%D0%A7%D1%91%D1%80%D0%BD%D1%8B%D0%B9_%D0%BA%D0%B0%D0%BE%D0%B4%D0%B0%D0%B8%D1%81%D1%82%D1%81%D0%BA%D0%B8%D0%B9_%D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB.svg/64px-%D0%A7%D1%91%D1%80%D0%BD%D1%8B%D0%B9_%D0%BA%D0%B0%D0%BE%D0%B4%D0%B0%D0%B8%D1%81%D1%82%D1%81%D0%BA%D0%B8%D0%B9_%D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB.svg.png
// ==/UserScript==
// Icon (PD by Insuranze)
// http://commons.wikimedia.org/wiki/File:%D0%A7%D1%91%D1%80%D0%BD%D1%8B%D0%B9_%D0%BA%D0%B0%D0%BE%D0%B4%D0%B0%D0%B8%D1%81%D1%82%D1%81%D0%BA%D0%B8%D0%B9_%D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB.svg
// Devel
// https://gist.github.com/noromanba/cd313dd2b15fbc6b4949
// TODO
// - indepandent from jQuery
// - @require myscript.js
// - apply to conext node
// - justify quote style
// e.g. http://tabelog.com/rstLst/yakitori/?SrtT=rt&Srt=D&sk=%E7%84%BC%E3%81%8D%E9%B3%A5&sa=%E6%9D%B1%E4%BA%AC%E9%83%BD%E6%B8%8B%E8%B0%B7%E5%8C%BA
// c.f.
// http://ptech.g.hatena.ne.jp/noromanba/20150131/1422663288
// http://weblog.bulknews.net/post/108212614849/chrome-extension
// http://weblog.bulknews.net/post/108519100924
(function () {
console.log = function() {};
// https://github.com/miyagawa/Tabelog-HonestStars/blob/master/myscript.js
function patch(){
var honestify = function(score) {
var honest;
if (score >= 4.0) {
honest = 5.0;
} else if (score >= 3.5) {
honest = 4.5;
} else if (score >= 3.4) {
honest = 4.0;
} else if (score >= 3.3) {
honest = 3.5;
} else if (score >= 3.1) {
honest = 3.0;
} else if (score >= 3.0) {
honest = 2.0;
} else {
honest = 1.0;
}
console.log("Original score: " + score.toFixed(2) + ", Honest score: " + honest);
return honest;
};
$('.rate .score').each(function(index, element) {
var score = parseFloat($(element).text());
if (isNaN(score)) return;
var honest = honestify(score);
$(element).html(honest.toFixed(1) + ' <span class="tabelog-score">(' + score.toFixed(2) + ")</span>");
$(element).parent().find("img")
.attr("src", "http://image1-3.tabelog.k-img.com/images/restaurant/star/star_ll" + (honest * 10) + ".gif");
});
$(".info .score-overall").each(function(index, element) {
var score = parseFloat($(element).find(".score").text());
if (isNaN(score)) return;
var honest = honestify(score);
$(element).find(".score").html(honest.toFixed(1) + ' <span class="tabelog-score">(' + score.toFixed(2) + ")</span>");
$(element).find(".star").removeClass().addClass("star star" + honest * 10);
});
// for Autopaging
/*/ FIXME 100% CPU usage
new MutationObserver(function (records) {
records.forEach(function (record) {
patch(record.target);
});
}).observe(document.body, { childList: true, subtree: true });
/*/
[
'AutoPatchWork.DOMNodeInserted',
'AutoPagerize_DOMNodeInserted',
'AutoPagerAfterInsert'
].forEach(function(insert) {
// TODO debounce / MutationObserver
document.body.addEventListener(insert, function(evt) {
patch(evt.target);
}, false);
});
//*/
// /for Autopaging
}
var style = document.createElement('style');
style.appendChild(document.createTextNode('.tabelog-score { font-weight: normal; font-size: 60%; color: #bbb }'));
document.body.appendChild(style);
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+patch+')();'));
document.body.appendChild(script);
// /myscript.js
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment