cleanup code

This commit is contained in:
pypy
2020-01-12 19:13:42 +09:00
parent fa62bbdc20
commit b7cd2d8fee
3 changed files with 6791 additions and 6885 deletions
+644 -726
View File
File diff suppressed because it is too large Load Diff
+35 -35
View File
@@ -310,7 +310,7 @@
<!-- favorite --> <!-- favorite -->
<div v-show="$refs.menu && $refs.menu.activeIndex === 'favorite'" class="x-container"> <div v-show="$refs.menu && $refs.menu.activeIndex === 'favorite'" class="x-container">
<el-button type="default" :loading="API.isFavoriteLoading" @click="API.refreshFavorite()" size="small" icon="el-icon-refresh" circle style="position:relative;float:right;z-index:1"></el-button> <el-button type="default" :loading="API.isFavoriteLoading" @click="API.refreshFavorites()" size="small" icon="el-icon-refresh" circle style="position:relative;float:right;z-index:1"></el-button>
<el-tabs type="card" v-loading="API.isFavoriteLoading"> <el-tabs type="card" v-loading="API.isFavoriteLoading">
<el-tab-pane label="Friend"> <el-tab-pane label="Friend">
<el-collapse style="border:0"> <el-collapse style="border:0">
@@ -445,14 +445,14 @@
<!-- moderation --> <!-- moderation -->
<div v-show="$refs.menu && $refs.menu.activeIndex === 'moderation'" class="x-container"> <div v-show="$refs.menu && $refs.menu.activeIndex === 'moderation'" class="x-container">
<data-tables v-bind="playerModerationTable" v-loading="API.isPlayerModerationLoading"> <data-tables v-bind="playerModerationTable" v-loading="API.isPlayerModerationsLoading">
<template #tool> <template #tool>
<div style="margin:0 0 10px;display:flex;align-items:center"> <div style="margin:0 0 10px;display:flex;align-items:center">
<el-select v-model="playerModerationTable.filters[0].value" multiple clearable collapse-tags style="flex:1" placeholder="Filter"> <el-select v-model="playerModerationTable.filters[0].value" multiple clearable collapse-tags style="flex:1" placeholder="Filter">
<el-option v-once v-for="type in ['block', 'mute', 'unmute', 'hideAvatar', 'showAvatar']" :key="type" :label="type" :value="type"></el-option> <el-option v-once v-for="type in ['block', 'mute', 'unmute', 'hideAvatar', 'showAvatar']" :key="type" :label="type" :value="type"></el-option>
</el-select> </el-select>
<el-input v-model="playerModerationTable.filters[1].value" placeholder="Search" style="flex:none;width:150px;margin:0 10px"></el-input> <el-input v-model="playerModerationTable.filters[1].value" placeholder="Search" style="flex:none;width:150px;margin:0 10px"></el-input>
<el-button type="default" :loading="API.isPlayerModerationLoading" @click="API.refreshPlayerModeration()" icon="el-icon-refresh" circle style="flex:none"></el-button> <el-button type="default" :loading="API.isPlayerModerationsLoading" @click="API.refreshPlayerModerations()" icon="el-icon-refresh" circle style="flex:none"></el-button>
</div> </div>
</template> </template>
<el-table-column label="Date" prop="created" sortable="custom" width="120"> <el-table-column label="Date" prop="created" sortable="custom" width="120">
@@ -485,7 +485,7 @@
</div> </div>
<!-- notification --> <!-- notification -->
<div v-show="$refs.menu && $refs.menu.activeIndex === 'notification'" v-loading="API.isNotificationLoading" class="x-container"> <div v-show="$refs.menu && $refs.menu.activeIndex === 'notification'" v-loading="API.isNotificationsLoading" class="x-container">
<data-tables v-bind="notificationTable"> <data-tables v-bind="notificationTable">
<template #tool> <template #tool>
<div style="margin:0 0 10px;display:flex;align-items:center"> <div style="margin:0 0 10px;display:flex;align-items:center">
@@ -493,7 +493,7 @@
<el-option v-once v-for="type in ['requestInvite', 'invite', 'friendRequest', 'message']" :key="type" :label="type" :value="type"></el-option> <el-option v-once v-for="type in ['requestInvite', 'invite', 'friendRequest', 'message']" :key="type" :label="type" :value="type"></el-option>
</el-select> </el-select>
<el-input v-model="notificationTable.filters[1].value" placeholder="Search" style="flex:none;width:150px;margin:0 10px"></el-input> <el-input v-model="notificationTable.filters[1].value" placeholder="Search" style="flex:none;width:150px;margin:0 10px"></el-input>
<el-button type="default" :loading="API.isNotificationLoading" @click="API.refreshNotification()" icon="el-icon-refresh" circle style="flex:none"></el-button> <el-button type="default" :loading="API.isNotificationsLoading" @click="API.refreshNotifications()" icon="el-icon-refresh" circle style="flex:none"></el-button>
</div> </div>
</template> </template>
<el-table-column label="Date" prop="created_at" sortable="custom" width="120"> <el-table-column label="Date" prop="created_at" sortable="custom" width="120">
@@ -697,19 +697,19 @@
<span style="font-weight:bold">Friends Sort Option</span> <span style="font-weight:bold">Friends Sort Option</span>
<div style="font-size:12px;margin-top:5px"> <div style="font-size:12px;margin-top:5px">
<span style="display:inline-block;min-width:150px">VIP</span> <span style="display:inline-block;min-width:150px">VIP</span>
<el-switch v-model="orderFriendGroup0" inactive-text="by name" active-text="by state"></el-switch> <el-switch v-model="orderFriendsGroup0" inactive-text="by name" active-text="by state"></el-switch>
</div> </div>
<div style="font-size:12px;margin-top:5px"> <div style="font-size:12px;margin-top:5px">
<span style="display:inline-block;min-width:150px">ONLINE</span> <span style="display:inline-block;min-width:150px">ONLINE</span>
<el-switch v-model="orderFriendGroup1" inactive-text="by name" active-text="by state"></el-switch> <el-switch v-model="orderFriendsGroup1" inactive-text="by name" active-text="by state"></el-switch>
</div> </div>
<div style="font-size:12px;margin-top:5px"> <div style="font-size:12px;margin-top:5px">
<span style="display:inline-block;min-width:150px">ACTIVE</span> <span style="display:inline-block;min-width:150px">ACTIVE</span>
<el-switch v-model="orderFriendGroup2" inactive-text="by name" active-text="by state"></el-switch> <el-switch v-model="orderFriendsGroup2" inactive-text="by name" active-text="by state"></el-switch>
</div> </div>
<div style="font-size:12px;margin-top:5px"> <div style="font-size:12px;margin-top:5px">
<span style="display:inline-block;min-width:150px">OFFLINE</span> <span style="display:inline-block;min-width:150px">OFFLINE</span>
<el-switch v-model="orderFriendGroup3" inactive-text="by name" active-text="by state"></el-switch> <el-switch v-model="orderFriendsGroup3" inactive-text="by name" active-text="by state"></el-switch>
</div> </div>
</div> </div>
<div style="margin-top:30px"> <div style="margin-top:30px">
@@ -780,12 +780,12 @@
</el-option> </el-option>
</el-select> </el-select>
<div class="x-friend-list" style="padding-bottom:10px"> <div class="x-friend-list" style="padding-bottom:10px">
<div v-show="friendGroup0.length" class="x-friend-group"> <div v-show="friendsGroup0.length" class="x-friend-group">
<i class="el-icon-arrow-right" :class="{ rotate: isFriendGroup0 }"></i> <i class="el-icon-arrow-right" :class="{ rotate: isFriendsGroup0 }"></i>
<span @click="isFriendGroup0 = !isFriendGroup0" class="x-link" style="margin-left:5px">VIP&horbar;{{ friendGroup0.length }}</span> <span @click="isFriendsGroup0 = !isFriendsGroup0" class="x-link" style="margin-left:5px">VIP&horbar;{{ friendsGroup0.length }}</span>
</div> </div>
<div v-show="isFriendGroup0"> <div v-show="isFriendsGroup0">
<div v-for="friend in friendGroup0" :key="friend.id" @click="showUserDialog(friend.id)" class="x-friend-item"> <div v-for="friend in friendsGroup0" :key="friend.id" @click="showUserDialog(friend.id)" class="x-friend-item">
<template v-if="friend.ref"> <template v-if="friend.ref">
<div class="avatar" :class="userStatusClass(friend.ref)"> <div class="avatar" :class="userStatusClass(friend.ref)">
<img v-lazy="friend.ref.currentAvatarThumbnailImageUrl"> <img v-lazy="friend.ref.currentAvatarThumbnailImageUrl">
@@ -802,12 +802,12 @@
</template> </template>
</div> </div>
</div> </div>
<div v-show="friendGroup1.length" class="x-friend-group"> <div v-show="friendsGroup1.length" class="x-friend-group">
<i class="el-icon-arrow-right" :class="{ rotate: isFriendGroup1 }"></i> <i class="el-icon-arrow-right" :class="{ rotate: isFriendsGroup1 }"></i>
<span @click="isFriendGroup1 = !isFriendGroup1" class="x-link" style="margin-left:5px">ONLINE&horbar;{{ friendGroup1.length }}</span> <span @click="isFriendsGroup1 = !isFriendsGroup1" class="x-link" style="margin-left:5px">ONLINE&horbar;{{ friendsGroup1.length }}</span>
</div> </div>
<div v-show="isFriendGroup1"> <div v-show="isFriendsGroup1">
<div v-for="friend in friendGroup1" :key="friend.id" @click="showUserDialog(friend.id)" class="x-friend-item"> <div v-for="friend in friendsGroup1" :key="friend.id" @click="showUserDialog(friend.id)" class="x-friend-item">
<template v-if="friend.ref"> <template v-if="friend.ref">
<div class="avatar" :class="userStatusClass(friend.ref)"> <div class="avatar" :class="userStatusClass(friend.ref)">
<img v-lazy="friend.ref.currentAvatarThumbnailImageUrl"> <img v-lazy="friend.ref.currentAvatarThumbnailImageUrl">
@@ -824,12 +824,12 @@
</template> </template>
</div> </div>
</div> </div>
<div v-show="friendGroup2.length" class="x-friend-group"> <div v-show="friendsGroup2.length" class="x-friend-group">
<i class="el-icon-arrow-right" :class="{ rotate: isFriendGroup2 }"></i> <i class="el-icon-arrow-right" :class="{ rotate: isFriendsGroup2 }"></i>
<span @click="isFriendGroup2 = !isFriendGroup2" class="x-link" style="margin-left:5px">ACTIVE&horbar;{{ friendGroup2.length }}</span> <span @click="isFriendsGroup2 = !isFriendsGroup2" class="x-link" style="margin-left:5px">ACTIVE&horbar;{{ friendsGroup2.length }}</span>
</div> </div>
<div v-show="isFriendGroup2"> <div v-show="isFriendsGroup2">
<div v-for="friend in friendGroup2" :key="friend.id" @click="showUserDialog(friend.id)" class="x-friend-item"> <div v-for="friend in friendsGroup2" :key="friend.id" @click="showUserDialog(friend.id)" class="x-friend-item">
<template v-if="friend.ref"> <template v-if="friend.ref">
<div class="avatar"> <div class="avatar">
<img v-lazy="friend.ref.currentAvatarThumbnailImageUrl"> <img v-lazy="friend.ref.currentAvatarThumbnailImageUrl">
@@ -846,12 +846,12 @@
</template> </template>
</div> </div>
</div> </div>
<div v-show="friendGroup3.length" class="x-friend-group"> <div v-show="friendsGroup3.length" class="x-friend-group">
<i class="el-icon-arrow-right" :class="{ rotate: isFriendGroup3 }"></i> <i class="el-icon-arrow-right" :class="{ rotate: isFriendsGroup3 }"></i>
<span @click="isFriendGroup3 = !isFriendGroup3" class="x-link" style="margin-left:5px">OFFLINE&horbar;{{ friendGroup3.length }}</span> <span @click="isFriendsGroup3 = !isFriendsGroup3" class="x-link" style="margin-left:5px">OFFLINE&horbar;{{ friendsGroup3.length }}</span>
</div> </div>
<div v-show="isFriendGroup3"> <div v-show="isFriendsGroup3">
<div v-for="friend in friendGroup3" :key="friend.id" @click="showUserDialog(friend.id)" class="x-friend-item"> <div v-for="friend in friendsGroup3" :key="friend.id" @click="showUserDialog(friend.id)" class="x-friend-item">
<template v-if="friend.ref"> <template v-if="friend.ref">
<div class="avatar"> <div class="avatar">
<img v-lazy="friend.ref.currentAvatarThumbnailImageUrl"> <img v-lazy="friend.ref.currentAvatarThumbnailImageUrl">
@@ -1303,8 +1303,8 @@
</div> </div>
</el-option> </el-option>
</el-option-group> </el-option-group>
<el-option-group v-if="friendGroup0.length" label="VIP"> <el-option-group v-if="friendsGroup0.length" label="VIP">
<el-option v-for="friend in friendGroup0" :key="friend.id" :label="friend.name" :value="friend.id" class="x-friend-item" style="height:auto"> <el-option v-for="friend in friendsGroup0" :key="friend.id" :label="friend.name" :value="friend.id" class="x-friend-item" style="height:auto">
<template v-if="friend.ref"> <template v-if="friend.ref">
<div class="avatar" :class="userStatusClass(friend.ref)"> <div class="avatar" :class="userStatusClass(friend.ref)">
<img v-lazy="friend.ref.currentAvatarThumbnailImageUrl"> <img v-lazy="friend.ref.currentAvatarThumbnailImageUrl">
@@ -1316,8 +1316,8 @@
<span v-else v-text="friend.id"></span> <span v-else v-text="friend.id"></span>
</el-option> </el-option>
</el-option-group> </el-option-group>
<el-option-group v-if="friendGroup1.length" label="ONLINE"> <el-option-group v-if="friendsGroup1.length" label="ONLINE">
<el-option v-for="friend in friendGroup1" :key="friend.id" :label="friend.name" :value="friend.id" class="x-friend-item" style="height:auto"> <el-option v-for="friend in friendsGroup1" :key="friend.id" :label="friend.name" :value="friend.id" class="x-friend-item" style="height:auto">
<template v-if="friend.ref"> <template v-if="friend.ref">
<div class="avatar" :class="userStatusClass(friend.ref)"> <div class="avatar" :class="userStatusClass(friend.ref)">
<img v-lazy="friend.ref.currentAvatarThumbnailImageUrl"> <img v-lazy="friend.ref.currentAvatarThumbnailImageUrl">
@@ -1329,8 +1329,8 @@
<span v-else v-text="friend.id"></span> <span v-else v-text="friend.id"></span>
</el-option> </el-option>
</el-option-group> </el-option-group>
<el-option-group v-if="friendGroup2.length" label="ACTIVE"> <el-option-group v-if="friendsGroup2.length" label="ACTIVE">
<el-option v-for="friend in friendGroup2" :key="friend.id" :label="friend.name" :value="friend.id" class="x-friend-item" style="height:auto"> <el-option v-for="friend in friendsGroup2" :key="friend.id" :label="friend.name" :value="friend.id" class="x-friend-item" style="height:auto">
<template v-if="friend.ref"> <template v-if="friend.ref">
<div class="avatar"> <div class="avatar">
<img v-lazy="friend.ref.currentAvatarThumbnailImageUrl"> <img v-lazy="friend.ref.currentAvatarThumbnailImageUrl">
+49 -61
View File
@@ -1,16 +1,15 @@
// Copyright(c) 2019 pypy. All rights reserved. // Copyright(c) 2019-2020 pypy and individual contributors.
// All rights reserved.
// //
// This work is licensed under the terms of the MIT license. // This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>. // For a copy, see <https://opensource.org/licenses/MIT>.
if (window.CefSharp) { CefSharp.BindObjectAsync(
Promise.all([ 'VRCX',
CefSharp.BindObjectAsync('VRCX'), 'VRCXStorage',
CefSharp.BindObjectAsync('VRCXStorage'), 'SQLite'
CefSharp.BindObjectAsync('SQLite') ).then(function () {
]).catch(function () { var isObject = (arg) => arg === Object(arg);
location = 'https://github.com/pypy-vrc/vrcx';
}).then(function () {
VRCXStorage.GetBool = function (key) { VRCXStorage.GetBool = function (key) {
return this.Get(key) === 'true'; return this.Get(key) === 'true';
@@ -40,13 +39,10 @@ if (window.CefSharp) {
VRCXStorage.GetArray = function (key) { VRCXStorage.GetArray = function (key) {
try { try {
var json = this.Get(key); var array = JSON.parse(this.Get(key));
if (json) {
var array = JSON.parse(json);
if (Array.isArray(array)) { if (Array.isArray(array)) {
return array; return array;
} }
}
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
@@ -59,9 +55,9 @@ if (window.CefSharp) {
VRCXStorage.GetObject = function (key) { VRCXStorage.GetObject = function (key) {
try { try {
var json = this.Get(key); var object = JSON.parse(this.Get(key));
if (json) { if (isObject(object)) {
return JSON.parse(json); return object;
} }
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@@ -83,8 +79,6 @@ if (window.CefSharp) {
timeout: 6000 timeout: 6000
}); });
var isObject = (arg) => arg === Object(arg);
var escapeTag = (s) => String(s).replace(/["&'<>]/gu, (c) => `&#${c.charCodeAt(0)};`); var escapeTag = (s) => String(s).replace(/["&'<>]/gu, (c) => `&#${c.charCodeAt(0)};`);
Vue.filter('escapeTag', escapeTag); Vue.filter('escapeTag', escapeTag);
@@ -173,23 +167,23 @@ if (window.CefSharp) {
} }
}; };
API.$on = function (name, fn) { API.$on = function (name, handler) {
var handlers = this.eventHandlers.get(name); var handlers = this.eventHandlers.get(name);
if (handlers === undefined) { if (handlers === undefined) {
handlers = []; handlers = [];
this.eventHandlers.set(name, handlers); this.eventHandlers.set(name, handlers);
} }
handlers.push(fn); handlers.push(handler);
}; };
API.$off = function (name, fn) { API.$off = function (name, handler) {
var handlers = this.eventHandlers.get(name); var handlers = this.eventHandlers.get(name);
if (handlers === undefined) { if (handlers === undefined) {
return; return;
} }
var { length } = handlers; var { length } = handlers;
for (var i = 0; i < length; ++i) { for (var i = 0; i < length; ++i) {
if (handlers[i] === fn) { if (handlers[i] === handler) {
if (length > 1) { if (length > 1) {
handlers.splice(i, 1); handlers.splice(i, 1);
} else { } else {
@@ -249,8 +243,7 @@ if (window.CefSharp) {
}).then((json) => { }).then((json) => {
if (isObject(json) === false) { if (isObject(json) === false) {
this.$throw(0, 'Invalid JSON response'); this.$throw(0, 'Invalid JSON response');
} } else if (res.ok) {
if (res.ok) {
if (isObject(json.success)) { if (isObject(json.success)) {
new Noty({ new Noty({
type: 'success', type: 'success',
@@ -361,10 +354,10 @@ if (window.CefSharp) {
var text = []; var text = [];
if (code > 0) { if (code > 0) {
var status = this.statusCodes[code]; var status = this.statusCodes[code];
if (status) { if (status === undefined) {
text.push(`${code} ${status}`);
} else {
text.push(`${code}`); text.push(`${code}`);
} else {
text.push(`${code} ${status}`);
} }
} }
if (error !== undefined) { if (error !== undefined) {
@@ -388,6 +381,15 @@ if (window.CefSharp) {
args.ref = this.applyConfig(args.json); args.ref = this.applyConfig(args.json);
}); });
API.applyConfig = function (json) {
var ref = {
clientApiKey: '',
...json
};
this.cachedConfig = ref;
return ref;
};
API.getConfig = function () { API.getConfig = function () {
return this.call('config', { return this.call('config', {
method: 'GET' method: 'GET'
@@ -401,15 +403,6 @@ if (window.CefSharp) {
}); });
}; };
API.applyConfig = function (json) {
var ref = {
clientApiKey: '',
...json
};
this.cachedConfig = ref;
return ref;
};
// API: Location // API: Location
API.parseLocation = function (tag) { API.parseLocation = function (tag) {
@@ -546,25 +539,6 @@ if (window.CefSharp) {
args.ref = this.applyWorld(args.json); args.ref = this.applyWorld(args.json);
}); });
/*
params: {
worldId: string
}
*/
API.getWorld = function (params) {
return this.call(`worlds/${params.worldId}`, {
method: 'GET'
}).then((json) => {
var args = {
ref: null,
json,
params
};
this.$emit('WORLD', args);
return args;
});
};
API.applyWorld = function (json) { API.applyWorld = function (json) {
var ref = this.cachedWorlds.get(json.id); var ref = this.cachedWorlds.get(json.id);
if (ref === undefined) { if (ref === undefined) {
@@ -608,12 +582,29 @@ if (window.CefSharp) {
} else { } else {
Object.assign(ref, json); Object.assign(ref, json);
} }
if (Array.isArray(ref.tags)) {
ref.$isLabs = ref.tags.includes('system_labs'); ref.$isLabs = ref.tags.includes('system_labs');
}
return ref; return ref;
}; };
/*
params: {
worldId: string
}
*/
API.getWorld = function (params) {
return this.call(`worlds/${params.worldId}`, {
method: 'GET'
}).then((json) => {
var args = {
ref: null,
json,
params
};
this.$emit('WORLD', args);
return args;
});
};
var $app = { var $app = {
data: { data: {
API, API,
@@ -765,7 +756,4 @@ if (window.CefSharp) {
$app = new Vue($app); $app = new Vue($app);
window.$app = $app; window.$app = $app;
}); });
} else {
location = 'https://github.com/pypy-vrc/vrcx';
}