// ==UserScript== // @name Twitterの共有リンクをMisskeyの共有リンクに置換するスクリプト // @namespace https://midra.me // @version 1.0.3 // @description Twitterの共有リンクを開いたときにMisskeyの共有リンクに置換するスクリプトです。 // @author Midra // @license MIT // @match https://twitter.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com // @run-at document-start // @noframes // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @require https://greasyfork.org/scripts/7212-gm-config-eight-s-version/code/GM_config%20(eight's%20version).js?version=156587 // @downloadURL none // ==/UserScript== (() => { const configInitData = { instance: { label: 'インスタンス (httpsは省略)', type: 'text', default: 'misskey.io', }, replace: { label: 'オプション', type: 'select', default: 'afterConfirm', options: { auto: '自動で置換する', afterConfirm: '置換する前に確認する', }, }, } GM_config.init('Twitterで共有をMisskeyで共有に置換するスクリプト 設定', configInitData) GM_config.onload = () => { setTimeout(() => { alert('設定を反映させるにはページを再読み込みしてください。') }, 200) } GM_registerMenuCommand('設定', GM_config.open) // 設定取得 const config = {} Object.keys(configInitData).forEach(v => { config[v] = GM_config.get(v) }) if ( !window.location.href.startsWith('https://twitter.com/intent/tweet?') && !window.location.href.startsWith('https://twitter.com/share?') ) return const { text, url, hashtags, via } = Object.fromEntries(new URLSearchParams(window.location.search).entries()) let shareText = '' if (text !== undefined && text !== '') { shareText = text } if (url !== undefined && url !== '') { shareText += ` ${url}` } if (hashtags !== undefined && hashtags !== '') { shareText += ` #${hashtags.split(',').join(' #')}` } if (via !== undefined && via !== '') { shareText += ` via ?[@${via}](https://twitter.com/${via})` } if ( config['replace'] === 'auto' || window.confirm(`指定したMisskeyのインスタンス(${config['instance']})で共有しますか?`) ) { window.location.href = `https://${config['instance']}/share?text=${window.encodeURIComponent(shareText)}` } })()