Skip to content

Instantly share code, notes, and snippets.

@mirka
Last active February 4, 2018 17:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirka/3552ee03ae782415e806 to your computer and use it in GitHub Desktop.
Save mirka/3552ee03ae782415e806 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Tabelog Smoking Alert
// @description 食べログの禁煙・喫煙情報を目立たせる
// @author mirka
// @include https://tabelog.com/*
// @namespace http://jaguchi.com
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js
// @grant GM_addStyle
// @version 1.3.1
// ==/UserScript==
(function () {
// Site-dependent settings
var $smokingTh = $("th:contains('禁煙・喫煙')");
var smokingStr = $smokingTh.find(" ~ td").text().trim();
var $insertionTarget = $(".rdheader-rstname-wrap");
var $linkTarget = $(".rstinfo-table__title:eq(1)");
// User-defined settings
var config = {
types: {
known: [
{
regex: /^全面喫煙可/,
shortStr: "喫煙",
alertColor: "#e10a17",
},
{
regex: /^分煙/,
shortStr: "分煙",
alertColor: "#fd9f28",
},
{
regex: /^完全禁煙/,
shortStr: "禁煙",
alertColor: "#93c526",
},
],
unknown: {
shortStr: "不明",
alertColor: "#e10a17",
},
},
thHighlightColor: "#ffecd0",
myAlertId: "smoking-alert",
};
insertSmokingData(smokingStr);
function insertSmokingData(str) {
var $alert;
var shortStr;
var alertColor;
config.types.known.forEach(function(type) {
if (type.regex.test(str)) {
shortStr = type.shortStr;
alertColor = type.alertColor;
}
});
if (!shortStr) {
shortStr = config.types.unknown.shortStr;
alertColor = config.types.unknown.alertColor;
}
// Create and insert alert element
$alert = $("<a/>", {
id: config.myAlertId,
href: "#",
text: shortStr,
css: {
position: "absolute",
left: "-4em",
padding: "3px",
color: "#fff",
backgroundColor: alertColor,
},
}).prependTo($insertionTarget);
// Suppress underline on alert element hover
GM_addStyle("a#" + config.myAlertId + ":hover { text-decoration: none }");
// Make alert link scroll to related table
$alert.click(function(e) {
e.preventDefault();
$smokingTh.css("background-color", config.thHighlightColor);
$("html,body").animate({
scrollTop: $linkTarget.offset().top - 60,
}, 250);
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment