Last active
January 15, 2024 06:02
-
-
Save CannoHarito/a4b61f812ace98a86e203605c1f5303c to your computer and use it in GitHub Desktop.
ブラウザプロファイルをクラッシュしたので、以前使っていたものに近いのを探した。ちょっと古かったので作り直した。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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