Improve: nano

This commit is contained in:
cutls 2019-10-14 00:28:10 +09:00
parent 4cabeb2e99
commit 85468761d3
3 changed files with 282 additions and 275 deletions

View File

@ -1,7 +1,11 @@
//TL取得
var websocket;
function tl(data) {
var tlid = 0;
if(websocket){
websocket.close()
}
var acct_id = $("#post-acct-sel").val();
var type = $("#type-sel").val();
var domain = localStorage.getItem("domain_" + acct_id);
@ -28,9 +32,9 @@ function tl(data) {
var templete = parse([json[0]], '', acct_id, tlid);
$("#timeline_nano").html(templete);
jQuery("time.timeago").timeago();
$("#menu").addClass("hide");
});
//Streaming接続
var websocket = [];
var tlid = 0;
if (type == "home") {
var start = "wss://" + domain +
@ -45,29 +49,26 @@ function tl(data) {
var start = "wss://" + domain +
"/api/v1/streaming/?stream=hashtag&tag=" + data + "&access_token=" + at;
}
var wsid = websocket.length;
websocket[wsid] = new WebSocket(start);
websocket[wsid].onopen = function (mess) {
websocket = new WebSocket(start);
websocket.onopen = function (mess) {
$("#notice_icon_" + tlid).removeClass("red-text");
}
websocket[wsid].onmessage = function (mess) {
websocket.onmessage = function (mess) {
var typeA = JSON.parse(mess.data).event;
if (typeA == "delete") {
var obj = JSON.parse(mess.data).payload;
$("[toot-id=" + JSON.parse(mess.data).payload + "]").hide();
$("[toot-id=" + JSON.parse(mess.data).payload + "]").remove();
} else if (typeA == "update") {
if (typeA == "update") {
var obj = JSON.parse(JSON.parse(mess.data).payload);
var templete = parse([obj], '', acct_id, tlid);
jQuery("time.timeago").timeago();
$("#timeline_nano").html(templete);
}
websocket[wsid].onclose = function (mess) {
console.error("Close Streaming API:" + type);
}
}
websocket[wsid].onerror = function (error) {
websocket.onerror = function (error) {
console.error('WebSocket Error ' + error);
};
websocket.onclose = function (mess) {
console.error("Close Streaming API:" + type);
}
}
//TLのタイトル
function cap(type, data) {
@ -134,3 +135,122 @@ $(function ($) {
}
});
});
function set() {
$("#menu").toggleClass("hide");
if($("#menu").hasClass("hide")){
$("#setting").text("Setting")
}else{
$("#setting").text("Close")
}
}
var multi = localStorage.getItem("multi");
if (!multi) {
var obj = [
{
at: localStorage.getItem(localStorage.getItem("domain_" + acct_id) + "_at"),
name: localStorage.getItem("name_" + acct_id),
domain: localStorage.getItem("domain_" + acct_id),
user: localStorage.getItem("user_" + acct_id),
prof: localStorage.getItem("prof_" + acct_id)
}
];
var json = JSON.stringify(obj);
localStorage.setItem("multi", json);
} else {
var obj = JSON.parse(multi);
}
var templete;
var last = localStorage.getItem("last-use");
var sel;
Object.keys(obj).forEach(function(key) {
var acct = obj[key];
var list = key * 1 + 1;
if (key == last) {
sel = "selected";
} else {
sel = "";
}
templete = '<option value="' + key + '" ' + sel + ">" + acct.user + "@" + acct.domain + "</option>";
$("#post-acct-sel").append(templete);
});
function mov() {
return false;
}
function resetmv() {
return false;
}
function post() {
var acct_id = $("#post-acct-sel").val();
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_" + acct_id + "_at");
var start = "https://" + domain + "/api/v1/statuses";
var str = $("#textarea").val();
var toot = {
status: str
};
var vis = loadVis(acct_id);
toot.visibility = vis;
var httpreq = new XMLHttpRequest();
httpreq.open("POST", start, true);
httpreq.setRequestHeader("Content-Type", "application/json");
httpreq.setRequestHeader("Authorization", "Bearer " + at);
httpreq.responseType = "json";
httpreq.send(JSON.stringify(toot));
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
$("#textarea").val("");
}
};
}
function loadVis(acct_id) {
var vist = localStorage.getItem("vis");
if (!vist) {
return "public";
} else {
if (vist == "memory") {
var memory = localStorage.getItem("vis-memory-" + acct_id);
if (!memory) {
memory = "public";
}
return memory;
} else if (vist == "server" || vist == "useapi") {
var multi = localStorage.getItem("multi");
var obj = JSON.parse(multi);
var memory = obj[acct_id]["vis"];
if (!memory) {
memory = "public";
}
return memory;
} else {
return vist;
}
}
}
function loader(){
var acct_id = $("#post-acct-sel").val()
console.log(loadVis(acct_id))
$("#vis-sel").val(loadVis(acct_id));
}
loader()
$("textarea").height(15); //init
$("textarea").css("lineHeight", "1rem"); //init
$("textarea").on("input", function(evt) {
if (evt.target.scrollHeight > evt.target.offsetHeight) {
$(evt.target).height(evt.target.scrollHeight);
} else {
var lineHeight = Number(
$(evt.target)
.css("lineHeight")
.split("px")[0]
);
while (true) {
$(evt.target).height($(evt.target).height() - lineHeight);
if (evt.target.scrollHeight > evt.target.offsetHeight) {
$(evt.target).height(evt.target.scrollHeight);
break;
}
}
}
});

View File

@ -13,34 +13,6 @@ function system(mainWindow, dir, lang, dirname) {
const dialog = electron.dialog;
const os = require('os')
const language = require("../main/language.js");
ipc.on('native-notf', function (e, args) {
var platform = process.platform;
var bit = process.arch;
if (platform == "win32") {
const notifier = require('node-notifier')
var tmp_imge = tmp_img;
Jimp.read(args[2], function (err, lenna) {
if (!err && lenna) {
lenna.write(tmp_img);
var tmp_imge = tmp_img;
} else {
var tmp_imge = "";
}
notifier.notify({
appID: "top.thedesk",
message: args[1],
title: args[0],
icon: tmp_imge,
sound: false,
wait: true,
},
function (err, response) {
console.log(err, response)
});
});
}
});
//プラットフォーム
ipc.on('getPlatform', function (e, arg) {
try {
@ -162,14 +134,14 @@ function system(mainWindow, dir, lang, dirname) {
preload: join(dirname, "js", "platform", "preload.js")
},
width: 350,
height: 200,
height: 140,
"transparent": false, // ウィンドウの背景を透過
"frame": false, // 枠の無いウィンドウ
"resizable": false
});
nanowindow.loadURL(dir + '/nano.html');
nanowindow.setAlwaysOnTop(true);
//nanowindow.toggleDevTools()
nanowindow.setPosition(window_pos[0], window_pos[1]);
nanowindow.on('close', function () {
fs.writeFileSync(nano_info_path, JSON.stringify(nanowindow.getPosition()));

View File

@ -1,11 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="./css/themes.css" type="text/css" rel="stylesheet">
<link href="./css/tl.css" type="text/css" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<head>
<meta charset="utf-8" />
<link href="./css/themes.css" type="text/css" rel="stylesheet" />
<link href="./css/tl.css" type="text/css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<link href="./node_modules/@fortawesome/fontawesome-free/css/all.min.css" type="text/css" rel="stylesheet">
<title>TheDesk Nano</title>
<style>
html {
@ -15,6 +15,7 @@
height: 100vh;
overflow: hidden;
font-family: sans-serif;
color: var(--color) !important;
}
body {
@ -43,6 +44,7 @@
textarea {
-webkit-app-region: no-drag;
color: var(--color) !important;
}
::-webkit-scrollbar {
@ -56,10 +58,6 @@
border-radius: 5px;
}
.area-actions {
display: none !important;
}
.area-date_via {
display: none !important;
}
@ -75,68 +73,66 @@
background: rgba(0, 0, 0, 0.8);
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}
.blacktheme body {
color: white;
background-color: #212121;
.hide, .pin, .rep-btn, .tickers{
display: none;
}
.blacktheme button {
background-color: black;
color: white;
.fas {
font-size: 1rem !important;
}
.blacktheme textarea,
.blacktheme select {
color: white;
}
.blacktheme select,
.blacktheme option {
background-color: black;
.cvo {
grid-template-rows: auto 1rem 1fr auto 2rem;
}
</style>
</head>
</head>
<body>
<body>
<script type="text/javascript" src="./node_modules/jquery/dist/jquery.js"></script>
<script>
$.strip_tags = function (str, allowed) {
$.strip_tags = function(str, allowed) {
if (!str) {
return "";
}
allowed = (((allowed || '') + '').toLowerCase().match(/<[a-z][a-z0-9]*>/g) || [])
.join('');
allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join("");
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>?/gi,
commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
return str.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
return str.replace(commentsAndPhpTags, "").replace(tags, function($0, $1) {
return allowed.indexOf("<" + $1.toLowerCase() + ">") > -1 ? $0 : "";
});
};
function escapeHTML(str) {
if (!str) {
return "";
}
return str.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
return str
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
</script>
<script type="text/javascript" src="./js/platform/first-not-view.js"></script>
<select id="post-acct-sel" style="max-width:150px">
</select>
<select id="type-sel" style="max-width:60px">
<div id="menu" class="hide">
TL and posting account<br>
<select id="post-acct-sel" style="max-width:150px"> </select><br>
TL type<br>
<select id="type-sel" style="max-width:60px" onchange="loader()">
<option value="local">Local</option>
<option value="home">Home</option>
</select><button onclick="tl()">Show</button><button onclick="window.close()">x</button><br>
<div id="timeline_nano">
<option value="home">Home</option> </select
><button onclick="tl()">Show</button><br>
Visibility<br>
<select id="vis-sel" style="max-width:60px">
<option value="public">Public</option>
<option value="unlisted">Unlisted</option>
<option value="private">Private</option>
</select>
</div>
<br>
<textarea id="textarea" style="width:80%; background-color:transparent"></textarea>
<button onclick="set()" id="setting">Setting</button>
<textarea id="textarea" style="width:55%; background-color:transparent" placeholder="Post someyhing new"></textarea>
<button class="btn" onclick="post()">Post</button>
<button onclick="window.close()">x</button><br />
<div id="timeline_nano">Click "settings" to show TL</div>
<br />
<script>
if (localStorage.getItem("lang")) {
var lang = localStorage.getItem("lang");
@ -145,6 +141,8 @@
}
</script>
<script src="https://twemoji.maxcdn.com/2/twemoji.min.js?2.7"></script>
<script type="text/javascript" src="view/en/main.js"></script>
<script type="text/javascript" src="./js/post/status.js"></script>
<script type="text/javascript" src="./js/post/post.js"></script>
<script type="text/javascript" src="./js/post/use-txtbox.js"></script>
<script type="text/javascript" src="./js/tl/parse.js"></script>
@ -153,88 +151,5 @@
<script type="text/javascript" src="./js/common/time.js"></script>
<script type="text/javascript" src="./js/platform/nano.js"></script>
<script type="text/javascript" src="./js/platform/end.js"></script>
<script>
var multi = localStorage.getItem("multi");
if (!multi) {
var obj = [{
at: localStorage.getItem(localStorage.getItem("domain_" + acct_id) + "_at"),
name: localStorage.getItem("name_" + acct_id),
domain: localStorage.getItem("domain_" + acct_id),
user: localStorage.getItem("user_" + acct_id),
prof: localStorage.getItem("prof_" + acct_id)
}];
var json = JSON.stringify(obj);
localStorage.setItem("multi", json);
} else {
var obj = JSON.parse(multi);
}
var templete;
var last = localStorage.getItem("last-use");
var sel;
Object.keys(obj).forEach(function (key) {
var acct = obj[key];
var list = key * 1 + 1;
if (key == last) {
sel = "selected";
} else {
sel = "";
}
templete = '<option value="' + key + '" ' + sel + '>' + acct.user + '@' + acct.domain +
'</option>';
$("#post-acct-sel").append(templete);
});
function mov() {
return false;
}
function resetmv() {
return false;
}
function post() {
var acct_id = $("#post-acct-sel").val();
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem("acct_" + acct_id + "_at");
var start = "https://" + domain + "/api/v1/statuses";
var str = $("#textarea").val();
var toot = {
status: str
}
var vis = loadVis(acct_id)
toot.visibility = vis;
var httpreq = new XMLHttpRequest();
httpreq.open('POST', start, true);
httpreq.setRequestHeader('Content-Type', 'application/json');
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
httpreq.responseType = "json";
httpreq.send(JSON.stringify(toot));
httpreq.onreadystatechange = function () {
if (httpreq.readyState === 4) {
$("#textarea").val("");
}
}
}
function loadVis(acct_id) {
var vist = localStorage.getItem("vis");
console.log(vist);
if (!vist) {
return "public";
} else {
if (vist == "memory") {
var memory = localStorage.getItem("vis-memory-" + acct_id);
if (!memory) {
memory = "public";
}
return memory;
} else if (vist == "server") {
var multi = localStorage.getItem("multi");
var obj = JSON.parse(multi);
var memory = obj[acct_id]["vis"];
if (!memory) {
memory = "public";
}
return memory;
} else {
return vist;
}
}
}
</script>
</body>
</html>