From 47c6454c00bec1d79ec0cd2fbd84cc97988f5c2b Mon Sep 17 00:00:00 2001 From: Cutls Date: Thu, 3 Oct 2019 01:38:55 +0900 Subject: [PATCH] Add: categorize of custom emojis --- app/js/lang/lang.bg.js | 1 + app/js/lang/lang.cs.js | 1 + app/js/lang/lang.de.js | 1 + app/js/lang/lang.en.js | 1 + app/js/lang/lang.ja.js | 1 + app/js/post/emoji.js | 102 ++++++++++++++++++++++++++++++++++------- app/js/tl/parse.js | 14 +++--- app/js/ui/layout.js | 2 + 8 files changed, 99 insertions(+), 24 deletions(-) diff --git a/app/js/lang/lang.bg.js b/app/js/lang/lang.bg.js index a5a5a240..616fbd10 100644 --- a/app/js/lang/lang.bg.js +++ b/app/js/lang/lang.bg.js @@ -52,6 +52,7 @@ var lang={ "lang_emoji_get": "Вземи емотикони", "lang_emoji_custom": "Персонализирани емотикони", "lang_defaultemojis_text": "Още емотикони {{cat}}", + "lang_emoji_uncat": "Uncategorized", "lang_postimg_previewdis": "не може да се визуализира", "lang_postimg_aftupload": "Не можете да променяте профилите след качването.", "lang_postimg_delete": "Изтрийте това изображение.", diff --git a/app/js/lang/lang.cs.js b/app/js/lang/lang.cs.js index 80c1a727..f6247533 100644 --- a/app/js/lang/lang.cs.js +++ b/app/js/lang/lang.cs.js @@ -52,6 +52,7 @@ var lang={ "lang_emoji_get": "Získat emoji", "lang_emoji_custom": "Vlastní emoji", "lang_defaultemojis_text": "Emojis about {{cat}}", + "lang_emoji_uncat": "Uncategorized", "lang_postimg_previewdis": "nelze vytvořit náhled", "lang_postimg_aftupload": "Po nahrání nemůžete změnit účty.", "lang_postimg_delete": "Delete this image.", diff --git a/app/js/lang/lang.de.js b/app/js/lang/lang.de.js index 5972c984..07a01a95 100644 --- a/app/js/lang/lang.de.js +++ b/app/js/lang/lang.de.js @@ -52,6 +52,7 @@ var lang={ "lang_emoji_get": "Hole Emojis", "lang_emoji_custom": "Eigene Emojis", "lang_defaultemojis_text": "Emojis über {{cat}}", + "lang_emoji_uncat": "Uncategorized", "lang_postimg_previewdis": "keine Vorschau", "lang_postimg_aftupload": "Sie können die Konten nach dem Hochladen nicht mehr ändern.", "lang_postimg_delete": "Dieses Bild löschen.", diff --git a/app/js/lang/lang.en.js b/app/js/lang/lang.en.js index 27157ad0..cd580d75 100644 --- a/app/js/lang/lang.en.js +++ b/app/js/lang/lang.en.js @@ -61,6 +61,7 @@ var lang = { "lang_emoji_get": "Get emojis", "lang_emoji_custom": "Custom emojis", "lang_defaultemojis_text": "Emojis about {{cat}}", + "lang_emoji_uncat": "Uncategorized", //post/img.js "lang_postimg_previewdis": "cannot preview", "lang_postimg_aftupload": "You cannot change accounts after uploading.", diff --git a/app/js/lang/lang.ja.js b/app/js/lang/lang.ja.js index e307ead7..1dc843f7 100644 --- a/app/js/lang/lang.ja.js +++ b/app/js/lang/lang.ja.js @@ -61,6 +61,7 @@ var lang = { "lang_emoji_get": "絵文字リストを取得", "lang_emoji_custom": "カスタム絵文字", "lang_defaultemojis_text": "{{cat}}の絵文字", + "lang_emoji_uncat": "未分類", //post/img.js "lang_postimg_previewdis": "プレビューできません。", "lang_postimg_aftupload": "アップロード後はアカウントを切り替えられません。", diff --git a/app/js/post/emoji.js b/app/js/post/emoji.js index 3f9ecd58..19d6c4d3 100644 --- a/app/js/post/emoji.js +++ b/app/js/post/emoji.js @@ -23,7 +23,7 @@ function emojiToggle(reaction) { } $("#post-box").css("width", width + "px") $("#suggest").html(""); - if (!localStorage.getItem("emoji_" + acct_id)) { + if (!localStorage.getItem("emojis_" + acct_id)) { var html = ''; $("#emoji-list").html(html); @@ -69,15 +69,48 @@ function emojiGet(parse, started) { }).then(function (json) { if (parse == "true") { $('#emoji-list').text('Parsing...'); + var md = { + "categorized": {}, + "uncategorized": [] + }; + var if_categorized = false + Object.keys(json).forEach(function (key) { + var emoji = json[key]; + if (emoji.visible_in_picker) { + var listed = true + } else { + var listed = false + } + if (emoji.category) { + var cat = emoji.category + if (!md["categorized"][cat]) { + md["categorized"][cat] = [] + } + md["categorized"][cat].push({ + "shortcode": emoji.shortcode, + "url": emoji.url, + "listed": listed + }) + if_categorized = true + } else { + md["uncategorized"].push({ + "shortcode": emoji.shortcode, + "url": emoji.url, + "listed": listed + }) + } + }); + console.log(md) //絵文字をマストドン公式と同順にソート - json.sort(function (a, b) { + md["uncategorized"].sort(function (a, b) { if (a.shortcode < b.shortcode) return -1; if (a.shortcode > b.shortcode) return 1; return 0; }); - localStorage.setItem("emoji_" + acct_id, JSON.stringify(json)); + md["if_categorized"] = if_categorized + localStorage.setItem("emojis_" + acct_id, JSON.stringify(md)); } else { - localStorage.setItem("emoji_" + acct_id, JSON.stringify(json)); + localStorage.setItem("emojis_" + acct_id, JSON.stringify(md)); } localStorage.setItem("emojiseek", 0); if (!started) { @@ -103,25 +136,27 @@ function emojiGet(parse, started) { localStorage.setItem("emojiReaction_" + acct_id, "disabled"); } var emojis = json.emojis; - var md = []; + var md = {"uncategorized": []} Object.keys(emojis).forEach(function (key) { var emoji = emojis[key]; - md.push({ + md["uncategorized"].push({ "shortcode": emoji.name, - "url": emoji.url + "url": emoji.url, + "listed": true }) }); + md["if_categorized"] = false if (parse == "true") { $('#emoji-list').text('Parsing...'); //絵文字をマストドン公式と同順にソート - md.sort(function (a, b) { + md["uncategorized"].sort(function (a, b) { if (a.shortcode < b.shortcode) return -1; if (a.shortcode > b.shortcode) return 1; return 0; }); - localStorage.setItem("emoji_" + acct_id, JSON.stringify(md)); + localStorage.setItem("emojis_" + acct_id, JSON.stringify(md)); } else { - localStorage.setItem("emoji_" + acct_id, JSON.stringify(md)); + localStorage.setItem("emojis_" + acct_id, JSON.stringify(md)); } localStorage.setItem("emojiseek", 0); if (!started) { @@ -153,7 +188,28 @@ function emojiList(target, reaction) { localStorage.getItem("emojiseek", 0) } var html = ''; - var obj = JSON.parse(localStorage.getItem("emoji_" + acct_id)); + var raw = JSON.parse(localStorage.getItem("emojis_" + acct_id)); + console.log(raw) + if (raw.if_categorized) { + var obj = [{ + "divider": true, + "cat": lang.lang_emoji_uncat + }] + var cats = raw["uncategorized"] + obj = obj.concat(cats); + Object.keys(raw["categorized"]).forEach(function (key) { + var cats = raw["categorized"][key]; + obj = obj.concat([{ + "divider": true, + "cat": key + }]); + obj = obj.concat(cats); + }); + } else { + var obj = raw["uncategorized"] + } + console.log(obj) + var num = obj.length; if (num < start) { var start = 0; @@ -163,24 +219,36 @@ function emojiList(target, reaction) { $("#emoji-sum").text(page); var ct = Math.ceil(start / 126); if (ct === 0) { - var ct = 1; + if(num > 0){ + var ct = 1; + } $("#emoji-before").addClass("disabled"); } else { $("#emoji-before").removeClass("disabled"); } - $("#emoji-next").removeClass("disabled"); + if (page != 1) { + $("#emoji-next").removeClass("disabled"); + } else { + $("#emoji-next").addClass("disabled"); + } $("#emoji-count").text(ct); for (i = start; i < start + 126; i++) { var emoji = obj[i]; if (emoji) { if (reaction) { html = html + ''; + ':\')" class="pointer">'; } else { - html = html + ''; + if(emoji.divider){ + html = html + '

'+ emoji.cat +'

' + }else{ + if (emoji.listed) { + html = html + ''; + } + } + } - } } $("#emoji-list").html(html); diff --git a/app/js/tl/parse.js b/app/js/tl/parse.js index 647308b1..2c16b5cf 100644 --- a/app/js/tl/parse.js +++ b/app/js/tl/parse.js @@ -208,7 +208,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) { var emoji = toot.account.emojis[key5]; var shortcode = emoji.shortcode; var emoji_url = ' :' + shortcode + ': '; + '" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': " title="' + shortcode + '" onclick="this.classList.toggle(\'bigemoji\');">'; var regExp = new RegExp(":" + shortcode + ":", "g"); dis_name = dis_name.replace(regExp, emoji_url); @@ -353,8 +353,8 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) { Object.keys(toot.account.emojis).forEach(function (key5) { var emoji = toot.account.emojis[key5]; var shortcode = emoji.shortcode; - var emoji_url = ' :' + shortcode + ': '; + var emoji_url = ' :' + shortcode + ': '; var regExp = new RegExp(":" + shortcode + ":", "g"); dis_name = dis_name.replace(regExp, emoji_url); }); @@ -400,7 +400,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) { var emoji = toot.account.emojis[key5]; var shortcode = emoji.shortcode; var emoji_url = ' :' + shortcode + ': '; + '" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': " title="' + shortcode + '" onclick="this.classList.toggle(\'bigemoji\');">'; var regExp = new RegExp(":" + shortcode + ":", "g"); dis_name = dis_name.replace(regExp, emoji_url); }); @@ -735,7 +735,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) { var emoji = toot.emojis[key5]; var shortcode = emoji.shortcode; var emoji_url = ' :' + shortcode + ': '; + '" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': " title="' + shortcode + '" onclick="this.classList.toggle(\'bigemoji\');">'; var regExp = new RegExp(":" + shortcode + ":", "g"); content = content.replace(regExp, emoji_url); spoil = spoil.replace(regExp, emoji_url); @@ -754,7 +754,7 @@ function parse(obj, mix, acct_id, tlid, popup, mutefilter, type) { var emoji = toot.profile_emojis[keynico]; var shortcode = emoji.shortcode; var emoji_url = ' :' + shortcode + ': '; + '" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': " title="' + shortcode + '" onclick="this.classList.toggle(\'bigemoji\');">'; var regExp = new RegExp(":" + shortcode + ":", "g"); content = content.replace(regExp, emoji_url); spoil = spoil.replace(regExp, emoji_url); @@ -1003,7 +1003,7 @@ function userparse(obj, auth, acct_id, tlid, popup) { var emoji = toot.emojis[key5]; var shortcode = emoji.shortcode; var emoji_url = ' :' + shortcode + ': '; + '" class="emoji-img" data-emoji="' + shortcode + '" alt=" :' + shortcode + ': " title="' + shortcode + '" onclick="this.classList.toggle(\'bigemoji\');">'; var regExp = new RegExp(":" + shortcode + ":", "g"); dis_name = dis_name.replace(regExp, emoji_url); }); diff --git a/app/js/ui/layout.js b/app/js/ui/layout.js index d92efa1b..eddf71fb 100644 --- a/app/js/ui/layout.js +++ b/app/js/ui/layout.js @@ -46,6 +46,7 @@ function parseColumn(target, dontclose) { var templete; Object.keys(obj).forEach(function (key) { var acct = obj[key]; + localStorage.setItem("name_" + key, acct.name); localStorage.setItem("user_" + key, acct.user); localStorage.setItem("user-id_" + key, acct.id); @@ -61,6 +62,7 @@ function parseColumn(target, dontclose) { localStorage.removeItem("misskey_wss_" + key) connectMisskey(key, false) } + localStorage.removeItem("emoji_" + key) //カスタム絵文字カテゴリ分け用旧データ削除 }); } var acctlist = obj;