Skip to content

Instantly share code, notes, and snippets.

@pacochi
Created July 9, 2018 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pacochi/1361c625dd9a01e39bbdc601586c73a6 to your computer and use it in GitHub Desktop.
Save pacochi/1361c625dd9a01e39bbdc601586c73a6 to your computer and use it in GitHub Desktop.
pixiv Sketch ライブのシェア機能を Pawoo 以外の Mastodon でも利用できるようにします。(書きかけ)
// ==UserScript==
// @name ぴくすけライブで web+mastodon
// @namespace hen.acho.co
// @include https://sketch.pixiv.net/*/lives/*
// @version 0.180709
// @description i18n の字が見えたのであえてここを日本語にした
// @run-at document-idle
// @grant none
// ==/UserScript==
(() => {
const stores = window.dehydrated.context.dispatcher.stores;
if (!stores) return;
const liveId = stores.RouteStore.currentNavigate.route.params.live_id;
const ownerId = stores.LiveStore.lives[liveId].owner.user_id;
const accountId = stores.UserStore.account.id;
const ownerName = stores.UserStore.users[ownerId].name;
const liveName = stores.LiveStore.lives[liveId].name;
const liveURL = location.origin + stores.RouteStore.currentNavigate.route.url;
console.log(liveId,ownerId,accountId,ownerName,liveName,liveURL);
new MutationObserver(
mutations => mutations.reduce(
(nodes, record) => nodes.concat([...record.addedNodes]), []
).some(node => {console.log('some');
if (node.nodeType != 1) return false;
const pawooButton = node.querySelector('.pawoo');
if (!pawooButton) return false;
console.log('pawooButton',pawooButton);
const reactEventHandlers = (Object.entries(pawooButton)
.find(p => p[0].startsWith('__reactEventHandlers')))[1];
if (!reactEventHandlers) return false;
console.log('reactEventHandlers',reactEventHandlers);
reactEventHandlers.onClick = () => {
window.open('web+mastodon://share?text=' + encodeURIComponent(`${ownerName}${ownerId === accountId ? '' : 'さん'}が「${liveName}」でライブ配信中! #pixivSketch ${liveURL}`),
'',
'toolbar=0, status=0, width=550, height=420');
};
// Pawoo 連携してない時の動作とハクゾウ君アイコンの差し替えがまだ
})
// まだちゃんとピンポイント指定やってない
).observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment