Skip to content

Instantly share code, notes, and snippets.

@hcmiya
Last active September 26, 2018 22:51
Show Gist options
  • Save hcmiya/453ba90d849d5b4ff0d25ccee94df6c8 to your computer and use it in GitHub Desktop.
Save hcmiya/453ba90d849d5b4ff0d25ccee94df6c8 to your computer and use it in GitHub Desktop.
Mastodonステータスのふぁぼとかを見るやつ
// ==UserScript==
// @name Mastodonステータスのふぁぼとかを見るやつ
// @namespace https://js4.in/ns/
// @version 1.0.7
// @description
// @author Miyagi Hikaru
// @include /^https?:\/\/[^\/]+\/(?:@\w+|users\/\w+\/statuses)\/\d+/
// @grant none
// @website https://gist.github.com/hcmiya/453ba90d849d5b4ff0d25ccee94df6c8
// @updateURL https://gist.github.com/hcmiya/453ba90d849d5b4ff0d25ccee94df6c8/raw/mastodon-no-fav-toka-miru-yatu.user.js
// ==/UserScript==
// Copyright: 2018 Miyagi Hikaru
// License: CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
const ce = n => document.createElement(n);
const cec = (n, c) => { const e = ce(n); e.className = c; return e; };
const style = document.head.appendChild(ce('style'));
style.textContent = `
.toot-notes {
display: table;
}
.toot-notes img {
height: 24px;
width: 24px;
}
.toot-notes_cat {
display: table-row;
}
.toot-notes_cat:empty {
display: none;
}
.toot-notes_cat > span {
display: table-cell;
}
.toot-notes_title {
width: 4.2em;
}
`;
const page_v250 = id => {
return document.body.querySelector('.detailed-status__meta');
};
const page_v243 = page_v250;
const create_notes = id => {
const notecont = cec('div', 'toot-notes');
notecont.appendChild(create_stat(id, "ブースト", 'reblogged_by'));
notecont.appendChild(create_stat(id, "ふぁぼ", 'favourited_by'));
return notecont;
};
const create_icon = e => {
const a = ce('a');
a.href = e.url;
a.target = '_blank';
const img = a.appendChild(ce('img'));
img.src = e.avatar_static;
img.title = `${e.acct} - ${e.display_name}`;
return a;
};
const create_stat = (id, title, act) => {
const catcont = cec('div', 'toot-notes_cat');
fetch(`/api/v1/statuses/${id}/${act}?limit=80`)
.then(res => res.json())
.then(json => {
if (json.length) {
const titlecell = catcont.appendChild(cec('span', 'toot-notes_title'));
titlecell.textContent = title;
const iconlist = catcont.appendChild(cec('span', 'toot-notes_list'));
json.reverse().forEach(e => {
iconlist.appendChild(create_icon(e));
});
}
});
return catcont;
}
const main = () => {
const test_status_page = [
{ test: 'div.column-2 > h4 > a[href="https://joinmastodon.org/"]', selector: page_v250 },
{ test: 'div.footer > span.powered-by > a[href="https://joinmastodon.org"]', selector: page_v243 },
];
const e = test_status_page.find(e => document.body.querySelector(e.test));
if (e) {
const id = /^\/(?:@\w+|users\/\w+\/statuses)\/(\d+)/.exec(location.pathname)[1];
e.selector(id).appendChild(create_notes(id));
} else {
document.head.removeChild(style);
}
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment