Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
七森中☆Mastodon部 - うにーボタン
// ==UserScript==
// @name 七森中☆Mastodon部 - うにーボタン
// @namespace https://github.com/unarist/
// @version 0.1
// @description 何も入力せずにうにー!を押すとうにー!ってうにー!します。
// @author unarist
// @match https://yuruyuri.family/
// @match https://yuruyuri.family/web/*
// @downloadURL https://gist.github.com/unarist/bf89a5f054fb1d58a39067f61626b9c2/raw/mastodon-default-toot.user.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
document.addEventListener('click', e => {
const btn = $(e.target).closest('button')[0];
if (btn && btn.textContent.match(/うにー/)) {
const textarea = document.querySelector('textarea[placeholder="今なにしてる?"]');
if (textarea.value.length === 0) {
textarea.value = 'うにー!';
// Simulate React's "change" event
// https://github.com/vitalyq/react-trigger-change/blob/v1.0.2/lib/change.js#L135-L140
const event = document.createEvent('HTMLEvents');
event.initEvent('input', true, false);
textarea.dispatchEvent(event);
}
}
}, true);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment