From c0a6ecec4d650213f6d094a6d9ea88e5d5f845aa Mon Sep 17 00:00:00 2001 From: cutls Date: Sat, 28 Nov 2020 07:07:16 +0900 Subject: [PATCH] Add: AiScript TheDesk Plugin --- app/img/aiscript.svg | 50 ++++++++++ app/js/platform/plugin.js | 16 +-- app/js/ui/settings.js | 114 ++++++++++++++++++++-- app/view/make/language/en/setting.json | 3 + app/view/make/language/ja-KS/setting.json | 3 + app/view/make/language/ja/setting.json | 3 + app/view/make/setting.sample.html | 16 ++- plugin.md | 37 ++++++- 8 files changed, 219 insertions(+), 23 deletions(-) create mode 100644 app/img/aiscript.svg diff --git a/app/img/aiscript.svg b/app/img/aiscript.svg new file mode 100644 index 00000000..fd015c45 --- /dev/null +++ b/app/img/aiscript.svg @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/js/platform/plugin.js b/app/js/platform/plugin.js index 8c2280af..8b75afa9 100644 --- a/app/js/platform/plugin.js +++ b/app/js/platform/plugin.js @@ -6,20 +6,8 @@ function getPlugin() { buttonOnPostbox: [], buttonOnToot: [] } - //if(!json) return ret - //const plugins = JSON.parse(json) - const plugins = [ - { - id: randomStr(20), - content: `### { - name: "マイ・ファースト・プラグイン" - version: 1 - event: "buttonOnPostbox" - author: "Cutls P" - } - ` - } - ] + if(!json) return ret + const plugins = JSON.parse(json) for (let plugin of plugins) { const meta = getMeta(plugin.content) if (!meta) continue diff --git a/app/js/ui/settings.js b/app/js/ui/settings.js index ea99af3c..71591eb0 100644 --- a/app/js/ui/settings.js +++ b/app/js/ui/settings.js @@ -502,9 +502,9 @@ function copyColor(from, to) { let i = 0 let color for (tag of props) { - if(tag == from) { + if (tag == from) { let used = $(`#use-color_${i}`).prop('checked') - if(!used) { + if (!used) { Swal.fire({ type: 'error', title: 'Not checked', @@ -516,9 +516,9 @@ function copyColor(from, to) { } i++ } - if(!color) return false + if (!color) return false for (tag of props) { - if(tag == to) { + if (tag == to) { $(`#color-picker${i}_value`).val(color) $(`#use-color_${i}`).prop('checked', true) break @@ -555,7 +555,7 @@ function customComp() { var my = JSON.parse(multi)[0].name var id = $('#custom-edit-sel').val() const defaults = [ - 'black','blue','brown','green','indigo','polar','snow','white' + 'black', 'blue', 'brown', 'green', 'indigo', 'polar', 'snow', 'white' ] if (id == 'add_new' || defaults.includes(id)) { id = makeCID() @@ -690,7 +690,7 @@ function customConnect(raw) { i++ } $('#custom_json').val(raw[1]) - if(args.default) { + if (args.default) { $('#delTheme').addClass('disabled') } } @@ -728,6 +728,107 @@ function customSoundSave(key, file) { localStorage.setItem('custom' + key, file) $(`#c${key}-file`).text(file) } +function pluginLoad() { + $('#plugin-edit-sel').val('add_new') + $(".plugin_delete").addClass('disabled') + var template = '' + var pgns = localStorage.getItem('plugins') + var args = JSON.parse(pgns ? pgns : '[]') + Object.keys(args).forEach(function (key) { + var theme = args[key] + var themeid = theme.id + template = template + `` + }) + template = '' + template + $('#plugin-edit-sel').html(template) + $('select').formSelect() +} +function pluginEdit() { + var id = $('#plugin-edit-sel').val() + $('#plugin').attr('data-id', id) + if (id == 'add_new') { + $('#plugin').val('') + $(".plugin_delete").addClass('disabled') + } else { + $(".plugin_delete").removeClass('disabled') + var pgns = localStorage.getItem('plugins') + var args = JSON.parse(pgns ? pgns : '[]') + Object.keys(args).forEach(function (key) { + var plugin = args[key] + var targetId = plugin.id + if (targetId == id) $('#plugin').val(plugin.content) + }) + } +} +function completePlugin(comp) { + var pgns = localStorage.getItem('plugins') + var args = JSON.parse(pgns ? pgns : '[]') + var id = $('#plugin').attr('data-id') + + var inputPlugin = $('#plugin').val() + var meta = getMeta(inputPlugin) + if (!meta) { + Swal.fire({ + icon: 'error', + title: 'error', + }) + return false + } + if (!meta.name || !meta.version || !meta.event || !meta.author) { + Swal.fire({ + icon: 'error', + title: 'error', + }) + return false + } + if (id == 'add_new') { + id = makeCID() + args.push({ + id: id, + content: inputPlugin + }) + } else { + Object.keys(args).forEach(function (key) { + var plugin = args[key] + var targetId = plugin.id + if (targetId == id) args[key].content = inputPlugin + }) + } + var ss = args + localStorage.setItem('plugins', JSON.stringify(ss)) + if(comp) return false + $('#plugin').attr('data-id', 'add_new') + $('#plugin').val('') + pluginLoad() +} +async function deletePlugin() { + const alert = await Swal.fire({ + title: 'delete', + icon: 'warning', + showCancelButton: true + }) + if (!alert) return false + $('#plugin').val('') + var pgns = localStorage.getItem('plugins') + var args = JSON.parse(pgns ? pgns : '[]') + var id = $('#plugin').attr('data-id') + $('#plugin').attr('data-id', 'add_new') + var ss = [] + Object.keys(args).forEach(function (key) { + var plugin = args[key] + var targetId = plugin.id + if (targetId != id) ss.push(plugin) + }) + localStorage.setItem('plugins', JSON.stringify(ss)) + pluginLoad() +} +function execEditPlugin() { + completePlugin(true) + var id = $('#plugin').attr('data-id') + var inputPlugin = $('#plugin').val() + var meta = getMeta(inputPlugin) + execPlugin(id, meta.event, { acct_id: 0, id: null }) +} window.onload = function () { //最初に読む load() @@ -738,6 +839,7 @@ window.onload = function () { voiceSettingLoad() oksload() ctLoad() + pluginLoad() $('body').addClass(localStorage.getItem('platform')) } //設定画面で未読マーカーは要らない diff --git a/app/view/make/language/en/setting.json b/app/view/make/language/en/setting.json index 33c63163..c6932c60 100644 --- a/app/view/make/language/en/setting.json +++ b/app/view/make/language/en/setting.json @@ -158,6 +158,9 @@ "keysc": "Keyboard shortcut Preferences", "iks": "Easy inserter", "okswarn": "You can insert any letters and emojis with only 3 keys", + "plugin": "Plugins", + "howToWritePlugin": "Japanese docs of AiScript TheDesk plugins", + "pluginList": "Plugin list", "muteemp": "Mute & Emphasis Preferences", "climute": "Client Mute", "cliemp": "Client Emphasis", diff --git a/app/view/make/language/ja-KS/setting.json b/app/view/make/language/ja-KS/setting.json index 333266d6..0478a551 100644 --- a/app/view/make/language/ja-KS/setting.json +++ b/app/view/make/language/ja-KS/setting.json @@ -156,6 +156,9 @@ "keysc": "キーボードショートカットの設定", "iks": "簡単文字入力", "okswarn": "絵文字やタグ、>BTなどを登録しておくとすぐに使えてええ感じや。", + "plugin": "プラグイン", + "howToWritePlugin": "AiScriptでTheDeskプラグイン書いたろ!", + "pluginList": "プラグイン一覧", "muteemp": "ミュート・強調の設定", "climute": "クライアントミュート", "cliemp": "クライアント強調", diff --git a/app/view/make/language/ja/setting.json b/app/view/make/language/ja/setting.json index 02fa9c0d..2f04bf09 100644 --- a/app/view/make/language/ja/setting.json +++ b/app/view/make/language/ja/setting.json @@ -155,6 +155,9 @@ "zeroWidthEmoji": "絵文字にゼロ幅スペースを使う", "uploadCrop": "添付画像の自動リサイズ", "uploadCropWarn": "最大の長辺ピクセル指定。JPEG以外は自動でPNGイメージに変換されます。大きなGIFアニメは静止画になります。0に設定するとリサイズしません。", + "plugin": "プラグイン", + "howToWritePlugin": "AiScriptによるTheDeskプラグインの書き方", + "pluginList": "プラグイン一覧", "keysc": "キーボードショートカットの設定", "iks": "簡単文字入力", "okswarn": "絵文字やタグ、>BTなどを登録しておくとすぐに入力できます。", diff --git a/app/view/make/setting.sample.html b/app/view/make/setting.sample.html index e06d4ae7..1f9b6f88 100644 --- a/app/view/make/setting.sample.html +++ b/app/view/make/setting.sample.html @@ -398,10 +398,19 @@
  • - power@@plugin@@ + @@plugin@@
    - + @@howToWritePlugin@@
    + + + +
    @@pluginList@@
    +
    + +
  • @@ -599,6 +608,9 @@
    TheDeskおよびCutls Pは被災地支援のためのマストドン研究会をログイン機能提供等の形で応援しています。
    タグタイムラインを開く:#被災地支援のためのマストドン研究会
    + + + diff --git a/plugin.md b/plugin.md index 16c41078..89b0923f 100644 --- a/plugin.md +++ b/plugin.md @@ -11,6 +11,7 @@ version: 1 event: "buttonOnPostbox" author: "Cutls P" + apiGet: false(例) } ``` これを冒頭に入れます。 @@ -114,4 +115,38 @@ NSFWを切り替えます。forceはデフォルトでfalseで、trueにする `buttonOnPostbox`で使用可能 `apiPost`をtrueにしてください。 -トゥートボタンを押したのと同じ挙動をします。 \ No newline at end of file +トゥートボタンを押したのと同じ挙動をします。 + + +## 実例 + +https://misskey.io/@syuilo/pages/bebeyo をTheDeskで使用できるようにするためには…(勝手に改造) +``` +### { + name: "ベベヨ" + version: 1 + event: "buttonOnPostbox" + author: "syuilo" + } + +#chars = +Str:split("ア,イ,ウ,エ,オ,カ,キ,ク,ケ,コ,サ,シ,ス,セ,ソ,タ,チ,ツ,テ,ト,ナ,ニ,ヌ,ネ,ノ,ハ,ヒ,フ,ヘ,ホ,マ,ミ,ム,メ,モ,ヤ,ユ,ヨ,ガ,ギ,グ,ゲ,ゴ,ザ,ジ,ズ,ゼ,ゾ,ダ,ヂ,ヅ,デ,ド,バ,ビ,ブ,ベ,ボ,パ,ピ,プ,ペ,ポ", ",") +#yos = ["オ", "ニョ"] +#suffixes = ["オオオオオオオ", "ナーラ", "ンチーノ"] +$text <- _ + +@do() { + #char1 = chars[Math:rnd(1, Arr:len(chars))] + #char2 = chars[Math:rnd(1, Arr:len(chars))] + #yo = ? (Math:rnd(0, 2) = 0) { yos[Math:rnd(1, Arr:len(yos))] } ... { "ヨ" } + #n = ? (Math:rnd(0, 2) = 0) { "ン" } ... { "" } + #suffix = ? (Math:rnd(0, 2) = 0) { suffixes[Math:rnd(1, Arr:len(suffixes))] } ... { "" } + text <- `{char1}{char2}{n}{yo}{suffix}` + TheDesk:postText(text) +} + +do() +``` + +最初のメタデータを追加します。 +また、do関数の最下部の`TheDesk:postText(text)`で、TheDeskの投稿ボックスに結果を挿入しています。 \ No newline at end of file