// DarkPlasma_TweetScreenshot 2.1.0 // Copyright (c) 2023 DarkPlasma // This software is released under the MIT license. // http://opensource.org/licenses/mit-license.php /** * 2024/12/21 2.1.0 ChangeScreenshotSettingに対応 * 2024/12/21 2.0.2 ツイートの画像リンクから.jpeg拡張子を除去 * 2024/01/15 2.0.1 ビルド方式を変更 (configをTypeScript化) * 2023/03/12 2.0.0 ツイート用インターフェース変更 * 2023/03/05 1.0.0 公開 */ /*: @target MZ @url https://github.com/elleonard/DarkPlasma-MZ-Plugins/tree/release @plugindesc Tweet a screenshot of the game @author DarkPlasma @license MIT @help English Help Translator: munokura This is an unofficial English translation of the plugin help, created to support global RPG Maker users. Feedback is welcome to improve translation quality (see: https://github.com/munokura/DarkPlasma-MZ-Plugins ). Original plugin by DarkPlasma. Please check the latest official version at: https://github.com/elleonard/DarkPlasma-MZ-Plugins/tree/release ----- Version: 2.1.0 Anonymously upload a screenshot of your game to imgur, and open a tweet with the URL. To use this app, you must register with imgur and obtain a client ID. This app does not support browser play. @param clientId @text imgur client ID @desc Please set the client ID to use the imgur upload API. @type string @param tweetText @text Tweet @type multiline_string @default I'm playing this RPG today! \n#RPG Maker MZ @command tweetScreenshot @text Tweet a screenshot */ /*:ja @plugindesc ゲーム画面のキャプチャをツイートする @author DarkPlasma @license MIT @target MZ @url https://github.com/elleonard/DarkPlasma-MZ-Plugins/tree/release @param clientId @desc imgurのアップロードAPIを利用するためのクライアントIDを設定してください。 @text imgurクライアントID @type string @param tweetText @text ツイート @type multiline_string @default 今日はこのRPGをやってるよ!\n#RPGツクールMZ @command tweetScreenshot @text スクリーンショットをツイートする @help version: 2.1.0 ゲーム画面のキャプチャをimgurに匿名でアップロードし、 そのURLを付与したツイート画面を開きます。 利用にはimgurの登録、及びクライアントIDの発行が必要です。 ブラウザプレイには対応していません。 */ (() => { 'use strict'; const pluginName = document.currentScript.src.replace(/^.*\/(.*).js$/, function () { return arguments[1]; }); const pluginParametersOf = (pluginName) => PluginManager.parameters(pluginName); const pluginParameters = pluginParametersOf(pluginName); const settings = { clientId: String(pluginParameters.clientId || ``), tweetText: String(pluginParameters.tweetText || `今日はこのRPGをやってるよ!\n#RPGツクールMZ`), }; const IMAGE_UPLOAD_API_URL = 'https://api.imgur.com/3/image'; function SceneManager_TweetScreenshotMixIn(sceneManager) { sceneManager.tweetScreenshot = function () { const snap = this.snapForScreenshot(); this.tweetImage(snap); }; sceneManager.tweetImage = function (image) { const base64Image = image.canvas.toDataURL('image/jpeg', 1).replace(/^.*,/, ''); const formData = new FormData(); formData.append('image', base64Image); formData.append('type', 'base64'); fetch(IMAGE_UPLOAD_API_URL, { method: 'POST', headers: { Authorization: `Client-ID ${settings.clientId}`, }, body: formData, }) .then((response) => { response .json() .then((json) => { if (json.status === 200) { const imageUrl = json.data.link.replace(/.(jpg|jpeg)$/, ''); const tweetUrl = `https://twitter.com/intent/tweet?text=${tweetText(imageUrl)}`; const exec = require('child_process').exec; if (process.platform === 'win32') { exec(`rundll32.exe url.dll,FileProtocolHandler "${tweetUrl}"`); } else { exec(`open "${tweetUrl}"`); } } else { throw new Error(`画像アップロードに失敗しました。 status: ${json.status} error: ${json.data.error}`); } }) .catch((e) => { this.notifyTweetScreenshotError(e); }); }) .catch((e) => { this.notifyTweetScreenshotError(e); }); }; sceneManager.notifyTweetScreenshotError = function (error) { console.log(error); }; sceneManager.snapForScreenshot = function () { return this.snap(); }; } SceneManager_TweetScreenshotMixIn(SceneManager); PluginManager.registerCommand(pluginName, 'tweetScreenshot', function () { SceneManager.tweetScreenshot(); }); function tweetText(imageUrl) { return encodeURIComponent(`${settings.tweetText} ${imageUrl}`); } })();