Skip to content

Instantly share code, notes, and snippets.

@cutls
Last active February 8, 2023 09:13
Show Gist options
  • Save cutls/48f9f0a71c37023815b84298d16e74ce to your computer and use it in GitHub Desktop.
Save cutls/48f9f0a71c37023815b84298d16e74ce to your computer and use it in GitHub Desktop.

Mastodonの投票結果を投票しなくてもalertで表示するやつ

外部鯖のアンケートに投票した後で正確な票数を知りたいときにも使える
alertで出ます。

「投票するまで票数を隠す」オプションがオンなら多分出ないと思います。
トゥート個別ページ「https://${domain}/@${acct}/${id}」に対応。いわゆる「元のページを表示」を押す必要があります。 @${acct}の代わりにnoticeでもOKです。Pleroma用に用意されています。

bookmarklet.jsの中身をブックマークに登録してください。

javascript: (function(){async function d(){const t=location.href.match(/https:\/\/([^\/]+)\/(@[a-zA-Z0-9_]+|notice)\/([^\/]+)/);if(t){const o=t[1],e=t[3],l=await fetch(`https://${o}/api/v1/statuses/${e}`,{method:"GET",headers:{"content-type":"application/json"}});l.ok||alert("Error");const n=await l.json();if(n.poll){const t=n.poll.options;let o="Results: ";if(null==t[0].votes_count)return alert("This is a result-hidden poll"),!1;for(let e=0;e<t.length;e++)o+=`\n${t[e].title}:${t[e].votes_count}`;alert(o)}else alert("not poll")}}d();}());
async function d() {
const m = location.href.match(/https:\/\/([^/]+)\/(@[a-zA-Z0-9_]+|notice)\/([^/]+)/)
if (m) {
const d = m[1]
const i = m[3]
const u = `https://${d}/api/v1/statuses/${i}`
const p = await fetch(u, {
method: 'GET',
headers: {
'content-type': 'application/json'
}
})
if (!p.ok) {
alert('Error')
}
const j = await p.json()
if (j.poll) {
const v = j.poll.options
let s = 'Results: '
if (v[0].votes_count == null) {
alert('This is a result-hidden poll')
return false
}
for (let a = 0; a < v.length; a++) {
s+= `\n${v[a].title}:${v[a].votes_count}`
}
alert(s)
} else {
alert('not poll')
}
}
}
d()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment