Skip to content

Instantly share code, notes, and snippets.

@CannoHarito
Last active January 15, 2024 06:02
Show Gist options
  • Save CannoHarito/a4b61f812ace98a86e203605c1f5303c to your computer and use it in GitHub Desktop.
Save CannoHarito/a4b61f812ace98a86e203605c1f5303c to your computer and use it in GitHub Desktop.
ブラウザプロファイルをクラッシュしたので、以前使っていたものに近いのを探した。ちょっと古かったので作り直した。
// ==UserScript==
// @name COOKPAD - Show Report Count
// @version 2024-01-15
// @description Cookpadのレシピへの文字列リンクにつくれぽ数を表示する
// @namespace http://iwamot.com/
// @match https://cookpad.com/*
// @grant none
// @website http://d.hatena.ne.jp/samurai20000/20090715/1247668133
// @website https://github.com/iwamot/cookpad-show-report-count
// @downloadURL https://gist.githubusercontent.com/CannoHarito/a4b61f812ace98a86e203605c1f5303c/raw/
// @updateURL https://gist.githubusercontent.com/CannoHarito/a4b61f812ace98a86e203605c1f5303c/raw/
// ==/UserScript==
(() => {
"use strict";
const showReportCount = (node) => {
[...node.querySelectorAll("a")].filter((a) =>
a.href.match(/^(https:\/\/cookpad\.com)?\/recipe\/\d+$/) &&
!a.querySelector("img")
).forEach((a) => fetch(a.href)
.then((res) => res.text())
.then((text) => insertReportCount(text, a))
);
};
const insertReportCount = (responseText, anchor) => {
const matches = responseText.match(
/<span class='tsukurepo_count'>([\d,]+)<\/span>/,
);
anchor.insertAdjacentHTML("beforeend", `(${matches ? matches[1] : 0}件)`);
};
showReportCount(document.body);
document.body.addEventListener(
"AutoPagerize_DOMNodeInserted",
(event) => showReportCount(event.target),
false,
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment