Fix: emoji parette

This commit is contained in:
cutls 2019-11-04 01:09:43 +09:00
parent 25d24ddef0
commit 5dfb28f2de

View File

@ -7,7 +7,9 @@ var prev_val = input.value;
var oldSuggest; var oldSuggest;
var suggest; var suggest;
input.addEventListener("focus", function () { input.addEventListener(
"focus",
function() {
localStorage.removeItem("cursor"); localStorage.removeItem("cursor");
var acct_id = $("#post-acct-sel").val(); var acct_id = $("#post-acct-sel").val();
$("#suggest").html(""); $("#suggest").html("");
@ -17,68 +19,20 @@ input.addEventListener("focus", function () {
if (new_val == "") { if (new_val == "") {
$("#suggest").html(""); $("#suggest").html("");
if ($("#poll").hasClass("hide") && $("#emoji").hasClass("hide")) { if ($("#poll").hasClass("hide") && $("#emoji").hasClass("hide")) {
$("#right-side").hide() $("#right-side").hide();
$("#right-side").css("width", "300px") $("#right-side").css("width", "300px");
$("#left-side").css("width", "100%") $("#left-side").css("width", "100%");
var width = localStorage.getItem("postbox-width"); var width = localStorage.getItem("postbox-width");
if (width) { if (width) {
width = width.replace("px", "") * 1 width = width.replace("px", "") * 1;
} else { } else {
width = 300 width = 300;
} }
$("#post-box").css("width", width + "px") $("#post-box").css("width", width + "px");
} }
return; return;
} }
if (prev_val != new_val) { if (prev_val != new_val) {
var semoji = new_val.match(/:(\S{3,})/);
if (semoji) {
var obj = JSON.parse(localStorage.getItem("emoji_" + acct_id));
if (!obj) {
var ehtml = lang.lang_suggest_nodata;
} else {
var num = obj.length;
var ehtml = "";
for (i = 0; i < num; i++) {
var emoji = obj[i];
if (~emoji.shortcode.indexOf(semoji[1])) {
if (emoji) {
ehtml = ehtml + '<a onclick="emojiInsert(\':' + emoji.shortcode +
': \',\':' + semoji[1] + '\')" class="pointer"><img src="' + emoji.url + '" width="20"></a>';
}
}
}
}
if (ehtml != "") {
$("#right-side").show()
$("#right-side").css("width", "200px")
$("#left-side").css("width", "calc(100% - 200px)")
var width = localStorage.getItem("postbox-width");
if (width) {
width = width.replace("px", "") * 1 + 200
} else {
width = 500
}
$("#post-box").css("width", width + "px")
$("#poll").addClass("hide")
$("#emoji").addClass("hide")
} else {
if ($("#poll").hasClass("hide") && $("#emoji").hasClass("hide")) {
$("#right-side").hide()
$("#right-side").css("width", "300px")
$("#left-side").css("width", "100%")
var width = localStorage.getItem("postbox-width");
if (width) {
width = width.replace("px", "") * 1
} else {
width = 300
}
$("#post-box").css("width", width + "px")
}
}
$("#suggest").html(ehtml);
}
var tag = new_val.match(/#(\S{3,})/); var tag = new_val.match(/#(\S{3,})/);
var acct = new_val.match(/@(\S{3,})/); var acct = new_val.match(/@(\S{3,})/);
if (tag && tag[1]) { if (tag && tag[1]) {
@ -88,41 +42,45 @@ input.addEventListener("focus", function () {
} else { } else {
$("#suggest").html(""); $("#suggest").html("");
if ($("#poll").hasClass("hide") && $("#emoji").hasClass("hide")) { if ($("#poll").hasClass("hide") && $("#emoji").hasClass("hide")) {
$("#right-side").hide() $("#right-side").hide();
$("#right-side").css("width", "300px") $("#right-side").css("width", "300px");
$("#left-side").css("width", "100%") $("#left-side").css("width", "100%");
var width = localStorage.getItem("postbox-width"); var width = localStorage.getItem("postbox-width");
if (width) { if (width) {
width = width.replace("px", "") * 1 width = width.replace("px", "") * 1;
} else { } else {
width = 300 width = 300;
} }
$("#post-box").css("width", width + "px") $("#post-box").css("width", width + "px");
} }
return; return;
} }
var domain = localStorage.getItem("domain_" + acct_id); var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_" + acct_id + "_at"); var at = localStorage.getItem("acct_" + acct_id + "_at");
suggest = "https://" + domain + "/api/v2/search?q=" + q suggest = "https://" + domain + "/api/v2/search?q=" + q;
if (suggest != oldSuggest) { if (suggest != oldSuggest) {
console.log("Try to get suggest at " + suggest) console.log("Try to get suggest at " + suggest);
fetch(suggest, { fetch(suggest, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json', "content-type": "application/json",
'Authorization': 'Bearer ' + at Authorization: "Bearer " + at
}, }
}).then(function (response) { })
.then(function(response) {
if (!response.ok) { if (!response.ok) {
response.text().then(function(text) { response.text().then(function(text) {
setLog(response.url, response.status, text); setLog(response.url, response.status, text);
}); });
} }
return response.json(); return response.json();
}).catch(function (error) { })
.catch(function(error) {
todo(error); todo(error);
setLog(start, "JSON", error);
console.error(error); console.error(error);
}).then(function (json) { })
.then(function(json) {
console.log(["Search", json]); console.log(["Search", json]);
//ハッシュタグ //ハッシュタグ
if (json.hashtags[0] && tag) { if (json.hashtags[0] && tag) {
@ -132,13 +90,12 @@ input.addEventListener("focus", function () {
var tag = json.hashtags[key4]; var tag = json.hashtags[key4];
var his = tag.history; var his = tag.history;
var uses = his[0].uses * 1 + his[1].uses * 1 + his[2].uses * 1 + his[3].uses * 1 + his[4].uses * 1 + his[5].uses * 1 + his[6].uses * 1; var uses = his[0].uses * 1 + his[1].uses * 1 + his[2].uses * 1 + his[3].uses * 1 + his[4].uses * 1 + his[5].uses * 1 + his[6].uses * 1;
tagHTML = '<br><a onclick="tagInsert(\'#' + escapeHTML(tag.name) + '\',\'#' + q + '\')" class="pointer">#' + tagHTML = "<br><a onclick=\"tagInsert('#" + escapeHTML(tag.name) + "','#" + q + '\')" class="pointer">#' + escapeHTML(tag.name) + "</a>&nbsp;" + uses + "toot(s)";
escapeHTML(tag.name) + '</a>&nbsp;' + uses + 'toot(s)'
var item = { var item = {
"uses": uses, uses: uses,
"html": tagHTML html: tagHTML
} };
tags.push(item) tags.push(item);
}); });
var num_a = -1; var num_a = -1;
var num_b = 1; var num_b = 1;
@ -149,28 +106,28 @@ input.addEventListener("focus", function () {
if (x < y) return num_b; if (x < y) return num_b;
return 0; return 0;
}); });
var ins = "" var ins = "";
var nev = false var nev = false;
Object.keys(tags).forEach(function(key7) { Object.keys(tags).forEach(function(key7) {
ins = ins + tags[key7].html ins = ins + tags[key7].html;
if (key7 <= 0 && !nev) { if (key7 <= 0 && !nev) {
ins = ins + '<br>' ins = ins + "<br>";
nev = true nev = true;
} }
}); });
$("#suggest").html(ins); $("#suggest").html(ins);
$("#right-side").show() $("#right-side").show();
$("#right-side").css("width", "200px") $("#right-side").css("width", "200px");
$("#left-side").css("width", "calc(100% - 200px)") $("#left-side").css("width", "calc(100% - 200px)");
var width = localStorage.getItem("postbox-width"); var width = localStorage.getItem("postbox-width");
if (width) { if (width) {
width = width.replace("px", "") * 1 + 200 width = width.replace("px", "") * 1 + 200;
} else { } else {
width = 500 width = 500;
} }
$("#post-box").css("width", width + "px") $("#post-box").css("width", width + "px");
$("#poll").addClass("hide") $("#poll").addClass("hide");
$("#emoji").addClass("hide") $("#emoji").addClass("hide");
} }
} else if (json.accounts[0] && acct[1]) { } else if (json.accounts[0] && acct[1]) {
var accts = ""; var accts = "";
@ -179,53 +136,58 @@ input.addEventListener("focus", function () {
if (acct.acct != q) { if (acct.acct != q) {
//Instance Actorって… //Instance Actorって…
if (acct.username.indexOf(".") < 0) { if (acct.username.indexOf(".") < 0) {
accts = accts + '<a onclick="tagInsert(\'@' + acct.acct + accts = accts + "<a onclick=\"tagInsert('@" + acct.acct + "','@" + q + '\')" class="pointer">@' + acct.acct + "</a><br>";
'\',\'@' + q + '\')" class="pointer">@' + acct.acct + '</a><br>';
} }
} }
}); });
$("#right-side").show() $("#right-side").show();
$("#right-side").css("width", "200px") $("#right-side").css("width", "200px");
$("#left-side").css("width", "calc(100% - 200px)") $("#left-side").css("width", "calc(100% - 200px)");
var width = localStorage.getItem("postbox-width"); var width = localStorage.getItem("postbox-width");
if (width) { if (width) {
width = width.replace("px", "") * 1 + 200 width = width.replace("px", "") * 1 + 200;
} else { } else {
width = 500 width = 500;
} }
$("#post-box").css("width", width + "px") $("#post-box").css("width", width + "px");
$("#suggest").html(accts); $("#suggest").html(accts);
$("#poll").addClass("hide") $("#poll").addClass("hide");
$("#emoji").addClass("hide") $("#emoji").addClass("hide");
} else { } else {
if ($("#poll").hasClass("hide") && $("#emoji").hasClass("hide")) { if ($("#poll").hasClass("hide") && $("#emoji").hasClass("hide")) {
$("#right-side").hide() $("#right-side").hide();
$("#right-side").css("width", "300px") $("#right-side").css("width", "300px");
$("#left-side").css("width", "100%") $("#left-side").css("width", "100%");
var width = localStorage.getItem("postbox-width"); var width = localStorage.getItem("postbox-width");
if (width) { if (width) {
width = width.replace("px", "") * 1 width = width.replace("px", "") * 1;
} else { } else {
width = 300 width = 300;
} }
$("#post-box").css("width", width + "px") $("#post-box").css("width", width + "px");
} }
} }
}); });
} }
}; }
oldSuggest = suggest; oldSuggest = suggest;
prev_value = new_val; prev_value = new_val;
}, 1000); }, 1000);
}, false); },
false
);
input.addEventListener("blur", function () { input.addEventListener(
"blur",
function() {
window.clearInterval(timer); window.clearInterval(timer);
favTag(); favTag();
}, false); },
false
);
function tagInsert(code, del) { function tagInsert(code, del) {
var now = $("#textarea").val(); var now = $("#textarea").val();
var selin = $("#textarea").prop('selectionStart'); var selin = $("#textarea").prop("selectionStart");
if (!del) { if (!del) {
} else { } else {
var regExp = new RegExp(del.replace(/[.*+?^=!:${}()|[\]\/\\]/g, "\\$&"), "g"); var regExp = new RegExp(del.replace(/[.*+?^=!:${}()|[\]\/\\]/g, "\\$&"), "g");
@ -242,42 +204,46 @@ function tagInsert(code, del) {
$("#textarea").val(newt); $("#textarea").val(newt);
$("#textarea").focus(); $("#textarea").focus();
if ($("#poll").hasClass("hide") && $("#emoji").hasClass("hide")) { if ($("#poll").hasClass("hide") && $("#emoji").hasClass("hide")) {
$("#right-side").hide() $("#right-side").hide();
$("#right-side").css("width", "300px") $("#right-side").css("width", "300px");
$("#left-side").css("width", "50%") $("#left-side").css("width", "50%");
var width = localStorage.getItem("postbox-width").replace("px", "") * 1; var width = localStorage.getItem("postbox-width").replace("px", "") * 1;
if (!width) { if (!width) {
width = 300 width = 300;
} }
$("#post-box").css("width", width + "px") $("#post-box").css("width", width + "px");
} }
$("#suggest").html(""); $("#suggest").html("");
} }
function cgNPs(q) { function cgNPs(q) {
suggest = "https://cg.toot.app/api/v1/search/light?q=" + q suggest = "https://cg.toot.app/api/v1/search/light?q=" + q;
if (suggest != oldSuggest) { if (suggest != oldSuggest) {
console.log("Try to get suggest at " + suggest) console.log("Try to get suggest at " + suggest);
fetch(suggest, { fetch(suggest, {
method: 'GET', method: "GET",
headers: { headers: {
'content-type': 'application/json' "content-type": "application/json"
}, }
}).then(function (response) { })
.then(function(response) {
if (!response.ok) { if (!response.ok) {
response.text().then(function(text) { response.text().then(function(text) {
setLog(response.url, response.status, text); setLog(response.url, response.status, text);
}); });
} }
return response.json(); return response.json();
}).catch(function (error) { })
.catch(function(error) {
todo(error); todo(error);
setLog(start, "JSON", error);
console.error(error); console.error(error);
}).then(function (json) { })
.then(function(json) {
if (json[0]) { if (json[0]) {
var tags = ""; var tags = "";
Object.keys(json).forEach(function(key4) { Object.keys(json).forEach(function(key4) {
var tag = json[key4]; var tag = json[key4];
tags = tags + '<a onclick="cgNP(\'' + json[key4] + '\')" class="pointer">' + escapeHTML(json[key4]) + '</a> '; tags = tags + "<a onclick=\"cgNP('" + json[key4] + '\')" class="pointer">' + escapeHTML(json[key4]) + "</a> ";
}); });
$("#suggest").html("Cinderella NowPlaying:" + tags); $("#suggest").html("Cinderella NowPlaying:" + tags);
} else { } else {