Skip to content

Instantly share code, notes, and snippets.

@windymelt
Last active August 19, 2020 03:42
Show Gist options
  • Save windymelt/80c71722d2c0aff3108c4aa17a7277bd to your computer and use it in GitHub Desktop.
Save windymelt/80c71722d2c0aff3108c4aa17a7277bd to your computer and use it in GitHub Desktop.
はてブエントリページでユーザミュートをサポートする君
// ==UserScript==
// @name Mute user はてブ
// @namespace http://tampermonkey.net/
// @version 0.1
// @description mute user
// @author Windymelt
// @match https://b.hatena.ne.jp/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Your code here...
const rks = "*********************************";
const button = document.createElement("button");
document.querySelector("div.entry-comments").appendChild(button);
button.innerText = "Show mute buttons";
const placeButtons = () => {
Array.from(document.querySelectorAll(".entry-comment-username")).map((span) => {
const b = document.createElement("button");
span.parentNode.appendChild(b);
b.innerText="mute";
const form = new FormData();
form.append("username", span.innerText);
form.append("rks", rks);
b.addEventListener("click", () => {
b.disabled = true;
const res = fetch("https://b.hatena.ne.jp/__________YOUR_____USERNAME__________/api.ignore.json", {
method: "POST",
body: form
});
res.then((res) => {
if (res.ok) {
b.disabled = true;
} else {
alert("failed to mute");
b.disabled = false;
}
});
});
return span.innerText
});
};
button.addEventListener("click", placeButtons);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment