thedesk/app/js/platform/end.js

168 lines
3.9 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
//プラットフォーム別 最後に読むやつ
//リンクを外部で開くか内部で出すか
$(document).on('click', 'a', e => {
var $a = $(e.target);
var url = $a.attr('href');
if (!url) {
var url = $a.parent().attr('href');
2018-02-18 05:44:20 +11:00
}
var urls=[];
if(url){
2018-07-05 11:26:07 +10:00
urls = url.match(/https?:\/\/(.+)/);
2018-04-07 14:31:09 +10:00
//トゥートのURLぽかったら
toot = url.match(/https:\/\/([a-zA-Z0-9.-]+)\/@([a-zA-Z0-9_]+)\/([0-9]+)/);
2018-05-12 04:12:25 +10:00
//タグのURLぽかったら
var tags=[];
tags = url.match(
/https:\/\/([-a-zA-Z0-9@.]+)\/tags\/([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/
);
//メンションっぽかったら
var ats=[];
ats = url.match(
/https:\/\/([-a-zA-Z0-9@.]+)\/@([-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/
);
2018-06-12 01:44:28 +10:00
console.log(toot);
2018-04-07 14:31:09 +10:00
if(toot){
2018-06-12 01:44:28 +10:00
ques = url.match(/https:\/\/quesdon\.rinsuki\.net\//);
console.log(ques);
if(ques){
if(ques[1]){
console.log("quesdon");
toot=[];
}
}
2018-04-07 14:31:09 +10:00
if(toot[1]){
2018-04-09 00:17:33 +10:00
var acct_id=$a.parent().attr("data-acct");
if(!acct_id){
acct_id=0;
}
$a.parent().addClass("loadp")
$a.parent().text("Loading...")
detEx(url,acct_id);
2018-04-07 14:31:09 +10:00
}
2018-05-12 04:12:25 +10:00
}else if(tags){
if(tags[2]){
tagShow(tags[2]);
}
}else if(ats){
2018-07-05 11:26:07 +10:00
console.log(ats);
2018-05-12 04:12:25 +10:00
if(ats[2]){
2018-06-12 01:44:28 +10:00
if(ats[1]!="quesdon.rinsuki.net"){
2018-07-05 11:26:07 +10:00
udgEx(ats[2]+"@"+ats[1],"main");
2018-06-12 01:44:28 +10:00
return false
}else{
const {
shell
} = require('electron');
shell.openExternal(url);
}
2018-05-12 04:12:25 +10:00
}
2018-04-07 14:31:09 +10:00
}else{
2018-02-18 05:44:20 +11:00
//hrefがhttp/httpsならブラウザで
2018-02-26 00:37:04 +11:00
if(urls){
2018-02-18 05:44:20 +11:00
if (urls[0]) {
const {
shell
} = require('electron');
shell.openExternal(url);
} else {
location.href = url;
}
2018-02-26 02:32:10 +11:00
}else{
location.href = url;
2018-02-26 00:37:04 +11:00
}
2018-02-18 05:44:20 +11:00
}
2018-04-07 14:31:09 +10:00
}
2018-01-28 23:22:43 +11:00
return false;
});
//よく使うライブラリ
/*マルチバイト用切り出し*/
$.isSurrogatePear = function(upper, lower) {
return 0xD800 <= upper && upper <= 0xDBFF && 0xDC00 <= lower && lower <=
0xDFFF;
};
$.mb_strlen = function(str) {
var ret = 0;
for (var i = 0; i < str.length; i++, ret++) {
var upper = str.charCodeAt(i);
var lower = str.length > (i + 1) ? str.charCodeAt(i + 1) : 0;
if ($.isSurrogatePear(upper, lower)) {
i++;
}
}
return ret;
};
$.mb_substr = function(str, begin, end) {
var ret = '';
for (var i = 0, len = 0; i < str.length; i++, len++) {
var upper = str.charCodeAt(i);
var lower = str.length > (i + 1) ? str.charCodeAt(i + 1) : 0;
var s = '';
if ($.isSurrogatePear(upper, lower)) {
i++;
s = String.fromCharCode(upper, lower);
} else {
s = String.fromCharCode(upper);
}
if (begin <= len && len < end) {
ret += s;
}
}
return ret;
};
$.strip_tags = function(str, allowed) {
allowed = (((allowed || '') + '').toLowerCase().match(/<[a-z][a-z0-9]*>/g) || [])
.join('');
2018-02-13 06:16:46 +11:00
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>?/gi,
2018-01-28 23:22:43 +11:00
commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
return str.replace(commentsAndPhpTags, '').replace(tags, function($0, $1) {
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
});
};
2018-03-11 01:22:59 +11:00
function escapeHTML(str) {
return str.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
2018-02-18 03:44:03 +11:00
//コピー
function execCopy(string){
2018-02-25 19:41:34 +11:00
var temp = $("#copy");
temp.val(string);
temp.select();
2018-02-18 03:44:03 +11:00
var result = document.execCommand('copy');
return result;
2018-03-11 01:22:59 +11:00
}
//Nano
function nano(){
var electron = require("electron");
var ipc = electron.ipcRenderer;
ipc.send('nano', "");
2018-04-17 03:10:35 +10:00
}
function progshow(e) {
if (e.lengthComputable) {
var percent = e.loaded / e.total;
console.log(percent * 100);
$("#imgsel").hide();
if(percent<1){
$("#imgup").text(Math.floor(percent*100)+"%");
}else{
$("#imgup").text("処理中");
}
}
2018-06-18 00:48:33 +10:00
}
var electron = require("electron");
var ipc = electron.ipcRenderer;
ipc.on('reload', function (event, arg) {
location.reload();
})