TheDesk
This commit is contained in:
194
js/post/bb-md.js
Normal file
194
js/post/bb-md.js
Normal file
@@ -0,0 +1,194 @@
|
||||
//BBCodeとMarkdownの入力・パーサー
|
||||
//BOXのトグルボタン
|
||||
function mdToggle(){
|
||||
$(".markdown").toggleClass("hide");
|
||||
$(".anti-markdown").toggleClass("hide");
|
||||
if($(".markdown").hasClass("hide")){
|
||||
localStorage.setItem("md","hide");
|
||||
}else{
|
||||
localStorage.removeItem("md");
|
||||
}
|
||||
|
||||
}
|
||||
//最初に読み込みます(MD対応インスタンスかチェック)
|
||||
if(localStorage.getItem("md")=="hide"){
|
||||
$(".markdown").addClass("hide");
|
||||
$(".anti-markdown").removeClass("hide");
|
||||
}
|
||||
//タグを選んだ時に(BB版)
|
||||
function tagsel(tag){
|
||||
if(tag=="large" || tag=="size" || tag=="color" || tag=="colorhex"){
|
||||
var sub=$("#"+tag).val();
|
||||
var sub = sub.replace( /#/g , "" ) ;
|
||||
surroundHTML(tag+"="+sub,tag);
|
||||
}else if(tag=="flip=vertical" || tag=="flip=horizontal"){
|
||||
surroundHTML(tag,"flip");
|
||||
}else{
|
||||
surroundHTML(tag,tag);
|
||||
}
|
||||
$("#textarea").focus();
|
||||
}
|
||||
//HTMLをエスケープしてXSSを防ぐ
|
||||
function escape_html (string) {
|
||||
if(typeof string !== 'string') {
|
||||
return string;
|
||||
}
|
||||
return string.replace(/[&'`"<>]/g, function(match) {
|
||||
return {
|
||||
'&': '&',
|
||||
"'": ''',
|
||||
'`': '`',
|
||||
'"': '"',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
}[match]
|
||||
});
|
||||
}
|
||||
//PHPのnl2brと同様
|
||||
function nl2br(str) {
|
||||
str = str.replace(/\r\n/g, "<br />");
|
||||
str = str.replace(/(\n|\r)/g, "<br />");
|
||||
return str;
|
||||
}
|
||||
//テキストボックスで選択したやつをタグで囲む(BB版)
|
||||
function surroundHTML(tagS,tagE) {
|
||||
var target = document.getElementById("textarea");
|
||||
var pos = getAreaRange(target);
|
||||
|
||||
var val = target.value;
|
||||
var range = val.slice(pos.start, pos.end);
|
||||
var beforeNode = val.slice(0, pos.start);
|
||||
var afterNode = val.slice(pos.end);
|
||||
var insertNode;
|
||||
if (range || pos.start != pos.end) {
|
||||
insertNode = '[' + tagS + ']' + range + '[/' + tagE + ']';
|
||||
target.value = beforeNode + insertNode + afterNode;
|
||||
}
|
||||
|
||||
else if (pos.start == pos.end) {
|
||||
insertNode = '[' + tagS + ']' + '[/' + tagE + ']';
|
||||
target.value = beforeNode + insertNode + afterNode;
|
||||
}
|
||||
}
|
||||
function markdown(tag,ck,br){
|
||||
surroundMD(tag,tag,ck);
|
||||
$("#textarea").focus();
|
||||
}
|
||||
function surroundMD(tagS,tagE,ck,br) {
|
||||
var target = document.getElementById("textarea");
|
||||
var pos = getAreaRange(target);
|
||||
|
||||
var val = target.value;
|
||||
var range = val.slice(pos.start, pos.end);
|
||||
var beforeNode = val.slice(0, pos.start);
|
||||
var afterNode = val.slice(pos.end);
|
||||
var insertNode;
|
||||
if(br=="yes"){
|
||||
var br="\n";
|
||||
}else{
|
||||
var br="";
|
||||
}
|
||||
|
||||
if ((range || pos.start != pos.end )&& ck=="yes") {
|
||||
insertNode = tagS + range + tagE ;
|
||||
target.value = beforeNode + insertNode + br + afterNode;
|
||||
}
|
||||
|
||||
else if (pos.start == pos.end || ck=="no") {
|
||||
insertNode = tagS + range;
|
||||
target.value = beforeNode + insertNode + br + afterNode;
|
||||
}
|
||||
}
|
||||
|
||||
//テキストボックスの前後チェック
|
||||
function getAreaRange(obj) {
|
||||
var pos = new Object();
|
||||
if(window.getSelection()) {
|
||||
pos.start = obj.selectionStart;
|
||||
pos.end = obj.selectionEnd;
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
//Markdownのリンク挿入
|
||||
function markdownLink(){
|
||||
var linkIns="["+$("#linkt").val()+"]"+"("+$("#link2").val()+")";
|
||||
if(linkIns!="[]()"){
|
||||
$("#textarea").val($("#textarea").val()+linkIns);
|
||||
$("#linkt").val("");
|
||||
$("#link2").val("");
|
||||
$("#textarea").focus();
|
||||
}
|
||||
}
|
||||
//Markdownのimg挿入
|
||||
function markdownImage(){
|
||||
var imgIns="!["+$("#image").val()+"]"+"("+$("#image2").val()+")";
|
||||
if(imgIns!="![]()"){
|
||||
$("#textarea").val($("#textarea").val()+imgIns);
|
||||
$("#image").val("");
|
||||
$("#image2").val("");
|
||||
$("#textarea").focus();
|
||||
}
|
||||
}
|
||||
//文字数をチェック(hタグ用)
|
||||
function str_count(all, part) {
|
||||
return (all.match(new RegExp(part, "g")) || []).length;
|
||||
}
|
||||
|
||||
//プレビュー
|
||||
function preview(){
|
||||
$("#preview-field").show();
|
||||
$("#toot-field").hide();
|
||||
$("#preview-btn").hide();
|
||||
var bb=escape_html($("#textarea").val());
|
||||
//quote
|
||||
var bb=bb.replace(/>(.+)$/g,'<blockquote>$1<\/blockquote>');
|
||||
//spin
|
||||
var bb=bb.replace(/\[spin\](.+)\[\/spin\]/g,'<span class="fa fa-spin">$1<\/span>');
|
||||
//pulse
|
||||
var bb=bb.replace(/\[pulse\](.+)\[\/pulse\]/g,'<span class="bbcode-pulse-loading">$1<\/span>');
|
||||
//large
|
||||
var bb=bb.replace(/\[large=([0-9]{1,2})x\](.+)\[\/large\]/g,'<span class="fa fa-$1x">$2<\/span>');
|
||||
//vertical
|
||||
var bb=bb.replace(/\[flip=vertical\](.+)\[\/flip\]/g,'<span class="fa fa-flip-vertical">$1<\/span>');
|
||||
//horizontal
|
||||
var bb=bb.replace(/\[flip=horizontal\](.+)\[\/flip\]/g,'<span class="fa fa-flip-horizontal">$1<\/span>');
|
||||
//b
|
||||
var bb=bb.replace(/\[b\](.+)\[\/b\]/g,'<b>$1<\/b>');
|
||||
//i
|
||||
var bb=bb.replace(/\[i\](.+)\[\/i\]/g,'<i>$1<\/i>');
|
||||
//u
|
||||
var bb=bb.replace(/\[u\](.+)\[\/u\]/g,'<u>$1<\/u>');
|
||||
//s
|
||||
var bb=bb.replace(/\[s\](.+)\[\/s\]/g,'<s>$1<\/s>');
|
||||
//size
|
||||
var bb=bb.replace(/\[size=([0-9]{1,2})\](.+)\[\/size\]/g,'<span style="font-size:$1px">$2<\/span>');
|
||||
//colorhex
|
||||
var bb=bb.replace(/\[colorhex=([A-Fa-f0-9]+)\](.+)\[\/colorhex\]/g,'<span style="color:#$1">$2<\/span>');
|
||||
//code
|
||||
var bb=bb.replace(/`(.+)`/g,'<code>$1<\/code>');
|
||||
//index
|
||||
var m;
|
||||
m=bb.match(/^#{1,6}(.+)$/gm);
|
||||
if(m){
|
||||
for(let i = 0; i < m.length; i++) {
|
||||
var t=m[i].match(/^#{1,6}(.+)$/);
|
||||
var indexct='<h'+str_count(m[i],"#")+'>'+t[1]+'</h'+str_count(m[i],"#")+'>';
|
||||
var bb=bb.replace(new RegExp(m[i], ""),indexct);
|
||||
}
|
||||
}
|
||||
//img
|
||||
var bb=bb.replace(/!\[(.+)\]\((https:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)\)/g,'<img src="$2" text="$1" style="width:100%">');
|
||||
//link
|
||||
var bb=bb.replace(/\[(.+)\]\((https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)\)/g,'<a href="$2" target="_blank">$1<\/a>');
|
||||
|
||||
$("#md-preview").html(nl2br(bb));
|
||||
}
|
||||
//Editで戻る
|
||||
function previewEdit(){
|
||||
$("#preview-field").hide();
|
||||
$("#toot-field").show();
|
||||
$("#preview-btn").show();
|
||||
$("#md-preview").html("");
|
||||
}
|
114
js/post/emoji.js
Normal file
114
js/post/emoji.js
Normal file
@@ -0,0 +1,114 @@
|
||||
//絵文字ピッカー
|
||||
//最初に読み込む
|
||||
$("#emoji-before").addClass("disabled");
|
||||
$("#emoji-next").addClass("disabled");
|
||||
|
||||
//絵文字ボタンのトグル
|
||||
function emoji() {
|
||||
var acct_id = $("#post-acct-sel").val();
|
||||
if ($("#emoji").hasClass("hide")) {
|
||||
$("#emoji").removeClass("hide")
|
||||
if (!localStorage.getItem("emoji_" + acct_id)) {
|
||||
var html =
|
||||
'<button class="btn waves-effect green" style="width:100%; padding:0; margin-top:0;" onclick="emojiGet(\'true\');">絵文字リスト取得</button>';
|
||||
$("#emoji-list").html(html);
|
||||
} else {
|
||||
emojiList('home');
|
||||
}
|
||||
} else {
|
||||
$("#emoji").addClass("hide")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//絵文字リスト挿入
|
||||
function emojiGet(parse) {
|
||||
$('#emoji-list').html('Loading...');
|
||||
var acct_id = $("#post-acct-sel").val();
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var start = "https://" + domain + "/api/v1/custom_emojis";
|
||||
fetch(start, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
if (parse == "true") {
|
||||
$('#emoji-list').html('Parsing...');
|
||||
//絵文字をマストドン公式と同順にソート
|
||||
json.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));
|
||||
} else {
|
||||
localStorage.setItem("emoji_" + acct_id, JSON.stringify(json));
|
||||
}
|
||||
localStorage.setItem("emojiseek", 0);
|
||||
emojiList('home')
|
||||
});
|
||||
}
|
||||
|
||||
//リストの描画
|
||||
function emojiList(target) {
|
||||
var acct_id = $("#post-acct-sel").val();
|
||||
var start = localStorage.getItem("emojiseek");
|
||||
if (target == "next") {
|
||||
var start = start * 1 + 127;
|
||||
localStorage.setItem("emojiseek", start);
|
||||
} else if (target == "before") {
|
||||
var start = start - 127;
|
||||
localStorage.setItem("emojiseek", start);
|
||||
} else {
|
||||
var start = 0;
|
||||
localStorage.getItem("emojiseek", 0)
|
||||
}
|
||||
var html = '';
|
||||
var obj = JSON.parse(localStorage.getItem("emoji_" + acct_id));
|
||||
var num = obj.length;
|
||||
if (num < start) {
|
||||
var start = 0;
|
||||
localStorage.setItem("emojiseek", start);
|
||||
}
|
||||
var page = Math.ceil(num / 126);
|
||||
$("#emoji-sum").text(page);
|
||||
var ct = Math.ceil(start / 126);
|
||||
if (ct == 0) {
|
||||
var ct = 1;
|
||||
$("#emoji-before").addClass("disabled");
|
||||
} else {
|
||||
$("#emoji-before").removeClass("disabled");
|
||||
}
|
||||
$("#emoji-next").removeClass("disabled");
|
||||
$("#emoji-count").text(ct);
|
||||
for (i = start; i < start + 126; i++) {
|
||||
var emoji = obj[i];
|
||||
if (emoji) {
|
||||
html = html + '<a onclick="emojiInsert(\':' + emoji.shortcode +
|
||||
':\')" class="pointer"><img src="' + emoji.url + '" width="20"></a>';
|
||||
}
|
||||
}
|
||||
$("#emoji-list").html(html);
|
||||
}
|
||||
|
||||
//絵文字など様々なものをテキストボックスに挿入
|
||||
function emojiInsert(code, del) {
|
||||
var now = $("#textarea").val();
|
||||
|
||||
if (!del) {
|
||||
$("#textarea").val(now + " " + code);
|
||||
emoji();
|
||||
} else {
|
||||
var regExp = new RegExp(del, "g");
|
||||
var now = now.replace(now, "");
|
||||
$("#textarea").val(now + " " + code);
|
||||
}
|
||||
$("#textarea").focus();
|
||||
}
|
132
js/post/img.js
Normal file
132
js/post/img.js
Normal file
@@ -0,0 +1,132 @@
|
||||
//ドラッグ・アンド・ドロップからアップロードまで。uiのimg.jsとは異なります。
|
||||
var obj = $("body");
|
||||
var system;
|
||||
//ドラッグスタート
|
||||
obj.on('dragstart', function(e) {
|
||||
system = "locked"
|
||||
});
|
||||
//何もなくファイルが通過
|
||||
obj.on('dragend', function(e) {
|
||||
system = "";
|
||||
});
|
||||
//ドラッグファイルが画面上に
|
||||
obj.on('dragenter', function(e) {
|
||||
if (system != "locked") {
|
||||
$("#drag").css('display', 'flex');
|
||||
more();
|
||||
}
|
||||
|
||||
});
|
||||
$("body").on('dragover', function(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
});
|
||||
//ドロップした
|
||||
$("body").on('drop', function(e) {
|
||||
if (system != "locked") {
|
||||
$("#drag").css('display', 'none');
|
||||
e.preventDefault();
|
||||
var files = e.originalEvent.dataTransfer.files;
|
||||
pimg(files);
|
||||
}
|
||||
});
|
||||
//何もなくファイルが通過
|
||||
$("#drag").on('dragleave', function(e) {
|
||||
$("#drag").css('display', 'none');
|
||||
});
|
||||
|
||||
//複数アップ
|
||||
function pimg(files) {
|
||||
console.log(files);
|
||||
for (i = 0; i < files.length; i++) {
|
||||
handleFileUpload(files[i], obj);
|
||||
}
|
||||
}
|
||||
|
||||
//ドラッグ・アンド・ドロップを終了
|
||||
function closedrop() {
|
||||
$("#drag").css('display', 'none');
|
||||
}
|
||||
|
||||
//ファイルプレビュー
|
||||
function handleFileUpload(files, obj) {
|
||||
var fr = new FileReader();
|
||||
fr.onload = function(evt) {
|
||||
var b64 = evt.target.result;
|
||||
if (files["type"] == "image/png" || files["type"] == "image/jpeg" || files[
|
||||
"type"] == "image/gif") {
|
||||
var html = '<img src="' + b64 + '" style="width:50px; max-height:100px;">';
|
||||
$('#preview').append(html);
|
||||
} else {
|
||||
$('#preview').append(files["name"] + "はプレビューできません");
|
||||
}
|
||||
$('#b64-box').val(b64);
|
||||
var ret = media(b64, files["type"])
|
||||
}
|
||||
fr.readAsDataURL(files);
|
||||
$("#mec").append(files["name"] + "/");
|
||||
}
|
||||
|
||||
//ファイルアップロード
|
||||
function media(b64, type) {
|
||||
$("#toot-post-btn").prop("disabled", true);
|
||||
todo("Image Upload...");
|
||||
var media = toBlob(b64, type);
|
||||
console.log(media);
|
||||
var fd = new FormData();
|
||||
fd.append('file', media);
|
||||
var acct_id = $("#post-acct-sel").val();
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/media";
|
||||
fetch(start, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
body: fd
|
||||
}).then(function(response) {
|
||||
console.log(response)
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
console.log(json);
|
||||
var img = localStorage.getItem("img");
|
||||
if (!img) {
|
||||
var img = "no-act";
|
||||
}
|
||||
if (img != "inline") {
|
||||
if ($("#media").val()) {
|
||||
$("#media").val($("#media").val() + ',' + json["id"]);
|
||||
} else {
|
||||
$("#media").val(json["id"]);
|
||||
}
|
||||
}
|
||||
if (img == "url") {
|
||||
$("#textarea").val($("#textarea").val() + " " + json["text_url"])
|
||||
}
|
||||
todc();
|
||||
$("#toot-post-btn").prop("disabled", false);
|
||||
});
|
||||
}
|
||||
|
||||
//Base64からBlobへ
|
||||
function toBlob(base64, type) {
|
||||
var bin = atob(base64.replace(/^.*,/, ''));
|
||||
var buffer = new Uint8Array(bin.length);
|
||||
for (var i = 0; i < bin.length; i++) {
|
||||
buffer[i] = bin.charCodeAt(i);
|
||||
}
|
||||
// Blobを作成
|
||||
try {
|
||||
var blob = new Blob([new Uint8Array(buffer)], {
|
||||
type: type
|
||||
});
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return blob;
|
||||
}
|
97
js/post/post.js
Normal file
97
js/post/post.js
Normal file
@@ -0,0 +1,97 @@
|
||||
/*投稿系*/
|
||||
//投稿
|
||||
function post() {
|
||||
var str = $("#textarea").val();
|
||||
var acct_id = $("#post-acct-sel").val();
|
||||
localStorage.setItem("last-use", acct_id);
|
||||
todo("Posting");
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/statuses";
|
||||
var reply = $("#reply").val();
|
||||
var media = $("#media").val();
|
||||
if ($("#nsfw").hasClass("nsfw-avail")) {
|
||||
var nsfw = "true";
|
||||
} else {
|
||||
var nsfw = "false";
|
||||
}
|
||||
var vis = $("#vis").text();
|
||||
if ($("#cw").hasClass("cw-avail")) {
|
||||
var spo = $("#cw-text").val();
|
||||
} else {
|
||||
var spo = "";
|
||||
}
|
||||
fetch(start, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
body: JSON.stringify({
|
||||
status: str,
|
||||
in_reply_to_id: reply,
|
||||
media_ids: media.split(","),
|
||||
sensitive: nsfw,
|
||||
spoiler_text: spo,
|
||||
visibility: vis
|
||||
})
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
console.log(json);
|
||||
var box = localStorage.getItem("box");
|
||||
if (box == "yes") {
|
||||
hide();
|
||||
}
|
||||
todc();
|
||||
clear();
|
||||
});
|
||||
}
|
||||
|
||||
//クリア(Shift+C)
|
||||
function clear() {
|
||||
$("#textarea").val("");
|
||||
$("#textarea").attr("placeholder", "象");
|
||||
$("#reply").val("");
|
||||
$("#media").val("");
|
||||
var cwt = localStorage.getItem("cw-text");
|
||||
if (cwt) {
|
||||
$("#cw-text").val(cwt);
|
||||
} else {
|
||||
$("#cw-text").val("");
|
||||
}
|
||||
$("#cw").addClass("blue");
|
||||
$("#cw").removeClass("yellow");
|
||||
$("#cw").removeClass("cw-avail");
|
||||
$("#rec").text("いいえ");
|
||||
$("#mec").text("なし");
|
||||
var vis = localStorage.getItem("vis");
|
||||
if (!vis) {
|
||||
$("#vis").text("public");
|
||||
} else {
|
||||
if (vis == "memory") {
|
||||
localStorage.setItem("vis-memory", $("#vis").text());
|
||||
} else {
|
||||
$("#vis").text(vis);
|
||||
}
|
||||
}
|
||||
$("#nsfw").addClass("blue");
|
||||
$("#nsfw").removeClass("yellow");
|
||||
$("#nsi").html("lock_open");
|
||||
$("#nsfw").removeClass("nsfw-avail");
|
||||
$("#nsc").text("なし");
|
||||
$("#drag").css("background-color", "#e0e0e0");
|
||||
$("#preview").html("");
|
||||
if ($("#post-box").hasClass("post-more")) {
|
||||
$("#file-wrap").html(
|
||||
'<input class="more-show" style="display:inline-block;" type="file" name="pic" id="upfile" onchange="pimg(document.getElementById(\'upfile\').files);" multiple>'
|
||||
);
|
||||
} else {
|
||||
$("#file-wrap").html(
|
||||
'<input class="more-show" type="file" name="pic" id="upfile" onchange="pimg(document.getElementById(\'upfile\').files);" multiple>'
|
||||
);
|
||||
}
|
||||
}
|
9
js/post/reply.js
Normal file
9
js/post/reply.js
Normal file
@@ -0,0 +1,9 @@
|
||||
/*リプライ*/
|
||||
function re(id,at){
|
||||
show();
|
||||
$("#reply").val(id);
|
||||
var te=$("#textarea").val();
|
||||
$("#textarea").val("@"+at+" "+te);
|
||||
$("#rec").text("はい");
|
||||
$("#textarea").attr("placeholder","返信モードです。クリアするときはShift+Cを押してください。");
|
||||
}
|
50
js/post/secure.js
Normal file
50
js/post/secure.js
Normal file
@@ -0,0 +1,50 @@
|
||||
/*保護系*/
|
||||
//画像保護
|
||||
function nsfw(){
|
||||
if($("#nsfw").hasClass("nsfw-avail")){
|
||||
$("#nsfw").addClass("blue");
|
||||
$("#nsfw").removeClass("yellow");
|
||||
$("#nsi").html("lock_open");
|
||||
$("#nsfw").removeClass("nsfw-avail");
|
||||
$("#nsc").text("なし");
|
||||
}else{
|
||||
$("#nsfw").removeClass("blue");
|
||||
$("#nsfw").addClass("yellow");
|
||||
$("#nsi").html("lock_outline");
|
||||
$("#nsfw").addClass("nsfw-avail");
|
||||
$("#nsc").text("あり");
|
||||
}
|
||||
}
|
||||
|
||||
//投稿公開範囲
|
||||
function vis(set){
|
||||
$("#vis").text(set);
|
||||
var vis=localStorage.getItem("vis");
|
||||
if(vis=="memory"){
|
||||
localStorage.setItem("vis-memory",set);
|
||||
}
|
||||
}
|
||||
|
||||
//コンテンツワーニング
|
||||
function cw(){
|
||||
if($("#cw").hasClass("cw-avail")){
|
||||
$("#cw-text").val();
|
||||
$("#cw-text").hide();
|
||||
$("#cw").addClass("blue");
|
||||
$("#cw").removeClass("yellow");
|
||||
$("#cw").removeClass("cw-avail");
|
||||
}else{
|
||||
$("#cw-text").show();
|
||||
$("#cw").removeClass("blue");
|
||||
$("#cw").addClass("yellow");
|
||||
$("#cw").addClass("cw-avail");
|
||||
var cwt=localStorage.getItem("cw-text");
|
||||
if(cwt){
|
||||
$("#cw-text").val(cwt);
|
||||
}
|
||||
}
|
||||
}
|
||||
//TLでコンテンツワーニングを表示トグル
|
||||
function cw_show(id){
|
||||
$(".cw_hide_"+id).toggleClass("cw");
|
||||
}
|
268
js/post/status.js
Normal file
268
js/post/status.js
Normal file
@@ -0,0 +1,268 @@
|
||||
//お気に入り登録やブースト等、フォローやブロック等
|
||||
//お気に入り登録
|
||||
function fav(id, acct_id) {
|
||||
if ($("#pub_" + id).hasClass("faved")) {
|
||||
var flag = "unfavourite";
|
||||
} else {
|
||||
var flag = "favourite";
|
||||
}
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/statuses/" + id + "/" + flag;
|
||||
fetch(start, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
body: JSON.stringify({})
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
console.log(json);
|
||||
$("#pub_" + id + " .fav_ct").text(json.favourites_count);
|
||||
if (!json.reblog) {
|
||||
$("#pub_" + id + " .rt_ct").text(json.reblogs_count - 1);
|
||||
} else {
|
||||
$("#pub_" + id + " .rt_ct").text(json.reblog.reblogs_count);
|
||||
}
|
||||
if ($("#pub_" + id).hasClass("faved")) {
|
||||
$("#pub_" + id).removeClass("faved");
|
||||
$("#fav_" + id).removeClass("yellow-text");
|
||||
} else {
|
||||
$("#pub_" + id).addClass("faved");
|
||||
$("#fav_" + id).addClass("yellow-text");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//ブースト
|
||||
function rt(id, acct_id) {
|
||||
if ($("#pub_" + id).hasClass("rted")) {
|
||||
var flag = "unreblog";
|
||||
} else {
|
||||
var flag = "reblog";
|
||||
}
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/statuses/" + id + "/" + flag;
|
||||
fetch(start, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
body: JSON.stringify({})
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
console.log(json);
|
||||
$("#pub_" + id + " .fav_ct").text(json.favourites_count);
|
||||
if (!json.reblog) {
|
||||
$("#pub_" + id + " .rt_ct").text(json.reblogs_count - 1);
|
||||
} else {
|
||||
$("#pub_" + id + " .rt_ct").text(json.reblog.reblogs_count);
|
||||
}
|
||||
|
||||
if ($("#pub_" + id).hasClass("rted")) {
|
||||
$("#pub_" + id).removeClass("rted");
|
||||
$("#rt_" + id).removeClass("teal-text");
|
||||
} else {
|
||||
$("#pub_" + id).addClass("rted");
|
||||
$("#rt_" + id).addClass("teal-text");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//フォロー
|
||||
function follow(acct_id) {
|
||||
if (!acct_id) {
|
||||
var acct_id = $('#his-data').attr("use-acct");
|
||||
}
|
||||
var id = $("#his-data").attr("user-id");
|
||||
if ($("#his-data").hasClass("following")) {
|
||||
var flag = "unfollow";
|
||||
} else {
|
||||
var flag = "follow";
|
||||
}
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/accounts/" + id + "/" + flag;
|
||||
fetch(start, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
body: JSON.stringify({})
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
if ($("#his-data").hasClass("following")) {
|
||||
$("#his-data").removeClass("following");
|
||||
$("#his-follow-btn").text("フォロー");
|
||||
} else {
|
||||
$("#his-data").addClass("following");
|
||||
$("#his-follow-btn").text("フォロー解除");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//ブロック
|
||||
function block(acct_id) {
|
||||
if (!acct_id) {
|
||||
var acct_id = $('#his-data').attr("use-acct");
|
||||
}
|
||||
var id = $("#his-data").attr("user-id");
|
||||
if ($("#his-data").hasClass("blocking")) {
|
||||
var flag = "unblock";
|
||||
} else {
|
||||
var flag = "block";
|
||||
}
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/accounts/" + id + "/" + flag;
|
||||
fetch(start, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
body: JSON.stringify({})
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
if ($("#his-data").hasClass("blocking")) {
|
||||
$("#his-data").removeClass("blocking");
|
||||
$("#his-block-btn").text("ブロック");
|
||||
} else {
|
||||
$("#his-data").addClass("blocking");
|
||||
$("#his-block-btn").text("ブロック解除");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//ミュート
|
||||
function mute(acct_id) {
|
||||
if (!acct_id) {
|
||||
var acct_id = $('#his-data').attr("use-acct");
|
||||
}
|
||||
var id = $("#his-data").attr("user-id");
|
||||
if ($("#his-data").hasClass("muting")) {
|
||||
var flag = "unmute";
|
||||
} else {
|
||||
var flag = "mute";
|
||||
}
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/accounts/" + id + "/" + flag;
|
||||
fetch(start, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
body: JSON.stringify({})
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
if ($("#his-data").hasClass("muting")) {
|
||||
$("#his-data").removeClass("muting");
|
||||
$("#his-mute-btn").text("ミュート");
|
||||
} else {
|
||||
$("#his-data").addClass("muting");
|
||||
$("#his-mute-btn").text("ミュート解除");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//投稿削除
|
||||
function del(id, acct_id) {
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/statuses/" + id;
|
||||
fetch(start, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
//ここで消さなくてもStreamingが消す
|
||||
//$("#pub_"+id).hide();
|
||||
});
|
||||
}
|
||||
|
||||
//フォロリク
|
||||
function request(id, flag, acct_id) {
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/follow_requests/" + id + "/" + flag;
|
||||
fetch(start, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
body: JSON.stringify({})
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
showReq();
|
||||
});
|
||||
}
|
||||
|
||||
//ドメインブロック(未実装)
|
||||
function domainblock(add, flag, acct_id) {
|
||||
if (!acct_id) {
|
||||
var acct_id = $('#his-data').attr("use-acct");
|
||||
}
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
var start = "https://" + domain + "/api/v1/domain_blocks"
|
||||
fetch(start, {
|
||||
method: flag,
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
body: JSON.stringify({
|
||||
domain: add
|
||||
})
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
showDom();
|
||||
});
|
||||
}
|
||||
|
||||
function addDomainblock() {
|
||||
var domain = $("#domainblock").val();
|
||||
domainblock(domain, 'POST');
|
||||
}
|
70
js/post/suggest.js
Normal file
70
js/post/suggest.js
Normal file
@@ -0,0 +1,70 @@
|
||||
//入力時にハッシュタグと@をサジェスト
|
||||
var timer = null;
|
||||
|
||||
var input = document.getElementById("textarea");
|
||||
|
||||
var prev_val = input.value;
|
||||
var oldSuggest;
|
||||
var suggest;
|
||||
input.addEventListener("focus", function() {
|
||||
$("#suggest").html("");
|
||||
window.clearInterval(timer);
|
||||
timer = window.setInterval(function() {
|
||||
var new_val = input.value;
|
||||
if (prev_val != new_val) {
|
||||
var tag = new_val.match(/#(\S{3,})/);
|
||||
var acct = new_val.match(/@(\S{3,})/);
|
||||
if (tag && tag[1]) {
|
||||
var q = tag[1];
|
||||
} else if (acct[1]) {
|
||||
var q = acct[1];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
var domain = localStorage.getItem("domain_" + acct_id);
|
||||
var at = localStorage.getItem(domain + "_at");
|
||||
suggest = "https://" + domain + "/api/v1/search?q=" + q
|
||||
if (suggest != oldSuggest) {
|
||||
console.log(suggest)
|
||||
fetch(suggest, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer ' + at
|
||||
},
|
||||
}).then(function(response) {
|
||||
return response.json();
|
||||
}).catch(function(error) {
|
||||
todo(error);
|
||||
console.error(error);
|
||||
}).then(function(json) {
|
||||
if (json.hashtags[0] && tag[1]) {
|
||||
var tags = "";
|
||||
Object.keys(json.hashtags).forEach(function(key4) {
|
||||
var tag = json.hashtags[key4];
|
||||
tags = tags + '<a onclick="emojiInsert(\'#' + tag + '\',\'#' + q +
|
||||
'\')" class="pointer">#' + tag + '</a> ';
|
||||
});
|
||||
$("#suggest").html("Tags:" + tags);
|
||||
} else if (json.accounts[0] && acct[1]) {
|
||||
var accts = "";
|
||||
Object.keys(json.accounts).forEach(function(key3) {
|
||||
var acct = json.accounts[key3];
|
||||
accts = accts + '<a onclick="emojiInsert(\'@' + acct.acct +
|
||||
'\',\'@' + q + '\')" class="pointer">@' + acct.acct + '</a> ';
|
||||
});
|
||||
$("#suggest").html("@:" + accts);
|
||||
} else {
|
||||
$("#suggest").html("Not Found");
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
oldSuggest = suggest;
|
||||
prev_value = new_val;
|
||||
}, 1000);
|
||||
}, false);
|
||||
|
||||
input.addEventListener("blur", function() {
|
||||
window.clearInterval(timer);
|
||||
}, false);
|
Reference in New Issue
Block a user