Greasy Fork

Greasy Fork is available in English.

Twitterの共有リンクをMisskeyの共有リンクに置換するスクリプト

Twitterの共有リンクを開いたときにMisskeyの共有リンクに置換するスクリプトです。

当前为 2023-05-10 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name            Twitterの共有リンクをMisskeyの共有リンクに置換するスクリプト
// @namespace       https://midra.me
// @version         1.0.6
// @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         http://greasyfork.icu/scripts/7212-gm-config-eight-s-version/code/GM_config%20(eight's%20version).js?version=156587
// ==/UserScript==

;(() => {
  'use strict'

  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')
  ) {
    const { text, url, hashtags, via } = Object.fromEntries(new URLSearchParams(window.location.search).entries())

    let shareText = ''
    if (text) {
      shareText = text.replace(/@([a-zA-Z0-9_]+)/g, '?[@$1](https://twitter.com/$1)')
    }
    if (url) {
      shareText += ` ${url}`
    }
    if (hashtags) {
      shareText += ` #${hashtags.split(',').join(' #')}`
    }
    if (via) {
      shareText += ` ?[@${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)}`
    }
  }
})()