thedesk/app/js/platform/first.js

305 lines
7.8 KiB
JavaScript
Raw Normal View History

2021-06-19 20:16:08 +10:00
window.onload = function() {
console.log('loaded')
initPostbox()
connection()
initPlugin(plugins)
if (localStorage.getItem('control-center-np')) $('#ccnp').removeClass('hide')
2020-11-28 07:57:11 +11:00
}
2021-06-19 20:16:08 +10:00
$.strip_tags = function(str, allowed) {
if (!str) {
return ''
}
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 : ''
})
2019-11-09 00:52:54 +11:00
}
2021-06-19 20:16:08 +10:00
2019-05-19 17:39:30 +10:00
function escapeHTML(str) {
2021-06-19 20:16:08 +10:00
if (!str) {
return ''
}
return str
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
2019-05-19 17:39:30 +10:00
}
//PHPのnl2brと同様
2018-12-09 05:46:01 +11:00
function nl2br(str) {
2021-06-19 20:16:08 +10:00
if (!str) {
return ''
}
str = str.replace(/\r\n/g, '<br />')
str = str.replace(/(\n|\r)/g, '<br />')
return str
2019-01-22 03:25:40 +11:00
}
2021-06-19 20:16:08 +10:00
2019-04-14 02:42:18 +10:00
function br2nl(str) {
2021-06-19 20:16:08 +10:00
if (!str) {
return ''
}
str = str.replace(/<br \/>/g, '\r\n')
return str
2019-04-14 02:42:18 +10:00
}
2021-06-19 20:16:08 +10:00
2019-05-19 17:39:30 +10:00
function formattime(date) {
2021-06-19 20:16:08 +10:00
var str = date.getFullYear() + '-'
if (date.getMonth() + 1 < 10) {
str = str + '0' + (date.getMonth() + 1) + '-'
} else {
str = str + (date.getMonth() + 1) + '-'
}
if (date.getDate() < 10) {
str = str + '0' + date.getDate()
} else {
str = str + date.getDate()
}
str = str + 'T'
if (date.getHours() < 10) {
str = str + '0' + date.getHours() + ':'
} else {
str = str + date.getHours() + ':'
}
if (date.getMinutes() < 10) {
str = str + '0' + date.getMinutes()
} else {
str = str + date.getMinutes()
}
return escapeHTML(str)
2019-01-22 03:25:40 +11:00
}
2021-06-19 20:16:08 +10:00
2019-05-19 17:39:30 +10:00
function formattimeutc(date) {
2021-06-19 20:16:08 +10:00
var str = date.getUTCFullYear() + '-'
if (date.getUTCMonth() + 1 < 10) {
str = str + '0' + (date.getUTCMonth() + 1) + '-'
} else {
str = str + (date.getUTCMonth() + 1) + '-'
}
if (date.getUTCDate() < 10) {
str = str + '0' + date.getUTCDate()
} else {
str = str + date.getUTCDate()
}
str = str + 'T'
if (date.getUTCHours() < 10) {
str = str + '0' + date.getUTCHours() + ':'
} else {
str = str + date.getUTCHours() + ':'
}
if (date.getUTCMinutes() < 10) {
str = str + '0' + date.getUTCMinutes()
} else {
str = str + date.getUTCMinutes()
}
return escapeHTML(str)
2019-03-08 05:19:26 +11:00
}
2019-11-09 00:52:54 +11:00
postMessage(['sendSinmpleIpc', 'custom-css-request'], '*')
2021-06-19 20:16:08 +10:00
incrementid=0
function makeCID()
{
return incrementid++
2019-03-08 05:19:26 +11:00
}
2021-06-19 20:16:08 +10:00
2019-05-19 17:39:30 +10:00
function rgbToHex(color) {
2021-06-19 20:16:08 +10:00
// HEXに変換したものを代入する変数
var hex = ''
2019-05-19 17:39:30 +10:00
2021-06-19 20:16:08 +10:00
// 第1引数がHEXのとき変換処理は必要ないのでそのままreturn
// IE8の場合はjQueryのcss()関数でHEXを返すので除外
if (color.match(/^#[a-f\d]{3}$|^#[a-f\d]{6}$/i)) {
return color
}
2019-05-19 17:39:30 +10:00
2021-06-19 20:16:08 +10:00
// 正規表現
var regex = color.match(/^rgb\(([0-9.]+),\s*([0-9.]+),\s*([0-9.]+)\)$/)
2019-05-19 17:39:30 +10:00
2021-06-19 20:16:08 +10:00
// 正規表現でマッチしたとき
if (regex) {
var rgb = [
// RGBからHEXへ変換
parseInt(regex[1]).toString(16),
parseInt(regex[2]).toString(16),
parseInt(regex[3]).toString(16)
]
2019-05-19 17:39:30 +10:00
2021-06-19 20:16:08 +10:00
for (var i = 0; i < rgb.length; ++i) {
// rgb(1,1,1)のようなときHEXに変換すると1桁になる
// 1桁のときは前に0を足す
if (rgb[i].length == 1) {
rgb[i] = '0' + rgb[i]
}
hex += rgb[i]
}
2019-05-19 17:39:30 +10:00
2021-06-19 20:16:08 +10:00
return hex
}
2019-05-19 17:39:30 +10:00
2021-06-19 20:16:08 +10:00
console.error(color + ':第1引数はRGB形式で入力')
2019-05-19 16:17:05 +10:00
}
2019-05-19 17:39:30 +10:00
/*マルチバイト用切り出し*/
2021-06-19 20:16:08 +10:00
$.isSurrogatePear = function(upper, lower) {
return 0xd800 <= upper && upper <= 0xdbff && 0xdc00 <= lower && lower <= 0xdfff
2019-11-09 00:52:54 +11:00
}
2021-06-19 20:16:08 +10:00
$.mb_strlen = function(str) {
var splitter = new GraphemeSplitter()
var arr = splitter.splitGraphemes(str)
return arr.length
2019-11-09 00:52:54 +11:00
}
2021-06-19 20:16:08 +10:00
$.mb_substr = function(str, begin, end) {
//配列にする
var splitter = new GraphemeSplitter()
var arr = splitter.splitGraphemes(str)
var newarr = []
for (var i = 0; i < arr.length; i++) {
if (i >= begin && i <= end) {
newarr.push(arr[i])
}
}
return newarr.join('')
}
//ソートするやつ
2019-07-29 01:42:17 +10:00
function object_array_sort(data, key, order, fn) {
2021-06-19 20:16:08 +10:00
var num_a = -1
var num_b = 1
if (order === 'asc') {
num_a = 1
num_b = -1
}
data = data.sort(function(a, b) {
var x = a[key]
var y = b[key]
if (x > y) return num_a
if (x < y) return num_b
return 0
})
var arrObj = {}
for (var i = 0; i < data.length; i++) {
arrObj[data[i]['family']] = data[i]
}
data = []
for (var key in arrObj) {
data.push(arrObj[key])
}
fn(data)
2019-07-29 01:42:17 +10:00
}
2021-06-19 20:16:08 +10:00
2019-11-09 00:52:54 +11:00
function setLog(txt1, txt2, txt3) {
2021-06-19 20:16:08 +10:00
//url,statuscode,responsetext
var text = new Date().toUTCString()
text = text + ',' + txt1 + ',' + txt2 + ',' + escapeCsv(txt3)
console.error(text)
postMessage(['log', text], '*')
2019-10-31 02:30:26 +11:00
}
2021-06-19 20:16:08 +10:00
2019-10-31 02:30:26 +11:00
function escapeCsv(str) {
2021-06-19 20:16:08 +10:00
if (!str) {
return str
}
var result
result = str.toString().replace(/\"/g, '""')
if (result.indexOf(',') >= 0) {
result = '"' + result + '"'
}
return result
2019-11-09 00:52:54 +11:00
}
2021-06-19 20:16:08 +10:00
2019-12-12 02:06:40 +11:00
function evalAttr(json, attr, lenCk) {
2021-06-19 20:16:08 +10:00
if (json[attr]) {
if (lenCk) {
if (json[attr][0]) {
return true
} else {
return false
}
} else {
return true
}
} else {
return false
}
2019-12-12 02:06:40 +11:00
}
2021-06-19 20:16:08 +10:00
2019-12-01 22:28:20 +11:00
function statusModel(now) {
2021-06-19 20:16:08 +10:00
if (!now) {
var now = new Date().toString()
}
return {
id: '',
created_at: now,
in_reply_to_id: null,
in_reply_to_account_id: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
language: 'en',
uri: '',
url: '',
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
favourited: false,
reblogged: false,
muted: false,
bookmarked: false,
pinned: false,
content: '<p><i>No status here</i></p>',
reblog: null,
application: {
name: null,
website: null
},
account: {
id: '',
username: '',
acct: '',
display_name: '',
locked: false,
bot: false,
created_at: now,
note: '',
url: '',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
followers_count: 0,
following_count: 0,
statuses_count: 0,
last_status_at: now,
emojis: [],
fields: []
},
media_attachments: [],
mentions: [],
tags: [],
card: null,
poll: null
}
2019-12-01 22:28:20 +11:00
}
2021-06-19 20:16:08 +10:00
2021-04-09 17:35:40 +10:00
function webviewFinder() {
2021-06-19 20:16:08 +10:00
const webview = document.querySelector('webview')
webview.addEventListener('did-navigate', (e) => {
const url = webview.getURL()
if (url.match('https://mobile.twitter.com/login')) {
postMessage(['twitterLogin', null], '*')
} else if (url.match('https://mobile.twitter.com/logout')) {
postMessage(['twitterLogin', true], '*')
}
})
2021-04-09 17:35:40 +10:00
}
2021-06-19 20:16:08 +10:00
2021-04-09 17:35:40 +10:00
function initWebviewEvent() {
2021-06-19 20:16:08 +10:00
if (document.querySelector('webview')) { webviewFinder() } else {
const timerWV = setInterval(function() {
document.querySelector('webview') ?
(webviewFinder(), clearInterval(timerWV)) :
console.log('まだロード中')
}, 500)
}
2021-04-09 17:35:40 +10:00
}