Skip to content

Commit

Permalink
Merge pull request #96 from AN0NCER/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
AN0NCER authored Apr 16, 2024
2 parents 40f744f + 4a0bca7 commit b73908f
Show file tree
Hide file tree
Showing 23 changed files with 1,165 additions and 491 deletions.
124 changes: 124 additions & 0 deletions javascript/modules/ActionVerify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { WindowManagement } from "./Windows.js";

const WindowVerify = {
init: function () {

},
anim: {
hided: () => {
$(`.window-verify-action`).remove();

}
},
show: () => {
$('body').css('overflow', 'hidden');
},
hide: () => {
$('body').css('overflow', '');
},
verif: () => { return true; }
}



export function CreateVerify() {
return new Promise((resolve) => {
const id = Math.random().toString(19).slice(2);
$('body').append(GenVerify(id));
const wm = new WindowManagement(WindowVerify, '.window-verify-action');

const pin = $(`#pin-${id}`);
const swipeText = $(`#swipeText-${id}`);
let isDragging = false;
let callbackCalled = false;

pin.on('mousedown touchstart', function (event) {
isDragging = true;
callbackCalled = false;
});

$(document).on('mousemove touchmove', function (event) {
if (isDragging && !callbackCalled) {
const pinWidth = pin.width();
const swipeWidth = pin.parent().width() - pinWidth;
let touchX = event.clientX;
if (event.originalEvent.touches)
touchX = event.originalEvent.touches[0].clientX;
const containerLeft = pin.parent().offset().left;

if (touchX - containerLeft >= swipeWidth) {
pin.css('transform', `translateX(${swipeWidth}px)`);
swipeText.text('Подтверждено!');
callbackCalled = true;
} else {
const translateX = touchX - containerLeft - pinWidth / 2;
pin.css('transform', `translateX(${translateX}px)`);
swipeText.text('Проведите вправо');
callbackCalled = false;
}
}
});

$(document).on('mouseup touchend', function () {
if (isDragging) {
isDragging = false;
pin.css('transform', '');

// Проверяем, было ли подтверждение действия
if (callbackCalled) {
wm.hide();
WindowVerify.hide();
resolve(true);
}

swipeText.text('Проведите вправо');
}
});

$(`#cancel-${id}`).on('click', function () {
wm.hide();
WindowVerify.hide();
throw new Error(`Отмена действия`);
});

wm.click();
});
}

function GenVerify(id, warning = 'Внимание! Проподут выборы озвучек, история просмотра, история поиска, параметры и т.д.') {
return `<!--Окно подтверждения действия-->
<span class="windowed window-verify-action hide" id="verify-${id}">
<span class="hide-window"></span>
<span class="window-content hide">
<span class="content-wraper">
<div class="window-access-icon">
<svg width="180" height="180" viewBox="0 0 180 180" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M94.711 1.01953C93.2344 0.351563 91.6172 0 90.0001 0C88.3829 0 86.7657 0.351563 85.3243 1.01953L19.0899 29.1094C11.3555 32.3789 5.5899 40.0078 5.62505 49.2188C5.80083 84.0938 20.1446 147.902 80.7188 176.906C86.5899 179.719 93.4102 179.719 99.2813 176.906C159.856 147.902 174.199 84.0938 174.375 49.2188C174.41 40.0078 168.645 32.3789 160.91 29.1094L94.711 1.01953ZM77.7338 78.9127H69.919C69.2266 78.9127 68.4352 77.9883 68.4352 77.4491V65.3548C68.4352 64.8156 69.2266 63.8142 70.0179 63.8142H109.982C110.773 63.8142 111.565 64.7386 111.565 65.2778V77.5261C111.565 78.0654 110.872 78.9127 110.081 78.9127H102.167C101.376 78.9127 100.683 78.1424 100.585 77.6031L99.991 75.2922H96.7266V104.796C96.7266 104.796 98.5072 105.335 99.1997 105.489C99.8921 105.643 100.486 106.26 100.486 106.876V114.502C100.486 115.118 99.7932 115.966 98.9029 115.966H81.0971C80.1079 115.966 79.5144 115.118 79.5144 114.425V106.953C79.5144 106.175 79.9463 105.717 81.0971 105.412C82.2479 105.108 83.2734 104.796 83.2734 104.796V75.2922H80.009C80.009 75.2922 79.9463 76.5058 79.6876 77.6031C79.4289 78.7005 78.8843 78.9127 77.7338 78.9127Z" />
</svg>
</div>
<div class="window-access-footer">
<span class="detail-access">
${warning}
</span>
<div class="access-swiper">
<div class="pin" id="pin-${id}">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path
d="M18.3828 9.11719C18.8711 9.60547 18.8711 10.3984 18.3828 10.8867L12.1328 17.1367C11.6445 17.625 10.8516 17.625 10.3633 17.1367C9.875 16.6484 9.875 15.8555 10.3633 15.3672L15.7305 10L10.3672 4.63281C9.87891 4.14453 9.87891 3.35156 10.3672 2.86328C10.8555 2.375 11.6484 2.375 12.1367 2.86328L18.3867 9.11328L18.3828 9.11719ZM4.63281 2.86719L10.8828 9.11719C11.3711 9.60547 11.3711 10.3984 10.8828 10.8867L4.63281 17.1367C4.14453 17.625 3.35156 17.625 2.86328 17.1367C2.375 16.6484 2.375 15.8555 2.86328 15.3672L8.23047 10L2.86719 4.63281C2.37891 4.14453 2.37891 3.35156 2.86719 2.86328C3.35547 2.375 4.14844 2.375 4.63672 2.86328L4.63281 2.86719Z"
fill="white" />
</svg>
</div>
<span id="swipeText-${id}">Проведите</span>
</div>
<div id="cancel-${id}" class="button-access-cancel">
Отмена
</div>
</div>
</span>
</span>
</span>`;
}

$('head').append(`<link rel="stylesheet" href="/style/css/verifyaction.css">`);
34 changes: 18 additions & 16 deletions javascript/modules/TunimeApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Server {
}
this.#id = id;
this.#url = url;
sessionStorage.setItem(this.#key, JSON.stringify({id: this.#id, url: this.#url}));
sessionStorage.setItem(this.#key, JSON.stringify({ id: this.#id, url: this.#url }));
}
}

Expand Down Expand Up @@ -261,22 +261,24 @@ export const Tunime = {
},

SET: (tid) => {
let responseCode = 503;
const body = { key: access.key, id: access.id, tid };
Fetch(`/voices/${aid}`, { method: 'POST', headers, body }).then((response) => {
responseCode = response.status;
response.json().then((value) => {
return resolve(value);
return new Promise((resolve) => {
let responseCode = 503;
const body = { key: access.key, id: access.id, tid };
Fetch(`/voices/${aid}`, { method: 'POST', headers, body }).then((response) => {
responseCode = response.status;
response.json().then((value) => {
return resolve(value);
});
}).catch(async (reason) => {
console.log(`[api] - Error: ${Tunime.server.url} Code: ${responseCode}\n${reason}`);
if (responseCode == 503) {
return;
// URL = `onrender.com`;
// return resolve(this.Voices(aid, access).SET(tid));
}
await Sleep(1000);
return resolve(this.Voices(aid, access).SET(tid));
});
}).catch(async (reason) => {
console.log(`[api] - Error: ${Tunime.server.url} Code: ${responseCode}\n${reason}`);
if (responseCode == 503) {
return;
// URL = `onrender.com`;
// return resolve(this.Voices(aid, access).SET(tid));
}
await Sleep(1000);
return resolve(this.Voices(aid, access).SET(tid));
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions javascript/modules/Windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export class WindowManagement {
this.authorized = authorized;
}

click() {
click(title = "Вы должны авторизоваться!") {
if (!this.target.verif()) {
ShowInfo("Вы должны авторизоваться!", "auth");
ShowInfo(title, "auth");
return;
}
this.show();
Expand Down
23 changes: 23 additions & 0 deletions javascript/pages/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { InitMenu, Menu } from "../menu.js";
import { Users } from "../modules/ShikiAPI.js";
import { Main, User } from "../modules/ShikiUSR.js";
import { ShowMoreSelect, ShowSelect } from "./settings/mod_select.js";
import { ShowStorage, Storage } from "./settings/mod_storage.js";

const Parameters = [
{
Expand All @@ -18,6 +19,10 @@ const Parameters = [
param: 'autologin',
name: 'Автоматический вход',
description: 'Моментальная авторизация пользователей.'
},
{
type: 'app-size',
name: 'Хранилище'
}
]
},
Expand Down Expand Up @@ -296,6 +301,7 @@ function _ShowParametrs() {
eventBoolean();
eventSelectOne();
eventSelectMore();
eventAppStorage();

function __loadParametrs(parametrs) {
let html = "";
Expand Down Expand Up @@ -325,6 +331,17 @@ function _ShowParametrs() {
<div class="select">${element.variation.length}</div>
</label>`
break;
case "app-size":
let s = Storage.size(), d = 'KB';
if (s > 1000) {
d = 'MB';
s = (s / 1000).toFixed(2);
}
html += `<label class="${i == 0 ? 'border-top' : ''} ${i + 1 == parametrs.length ? 'border-bottom' : ''}" data-type="app-size" data-tooltip="${element.description}">
<div class="title">${element.name}</div>
<div class="select">${s > 1000 ? (s / 1000).toFixed(2) : s} ${d}</div>
</label>`
break;
default:
break;
}
Expand Down Expand Up @@ -374,6 +391,12 @@ function eventSelectMore() {
});
}

function eventAppStorage() {
$('label[data-type="app-size"]').click(function () {
ShowStorage();
});
}

/**
* Рекурсивно выводит в консоль все ключи и значения объекта, кроме вложенных объектов.
*
Expand Down
146 changes: 146 additions & 0 deletions javascript/pages/settings/mod_storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { CreateVerify } from "../../modules/ActionVerify.js";
import { WindowManagement } from "../../modules/Windows.js";

const exception = ['tunime-id', 'application_installed'];

const WindowStorage = {
init: function () {
$('.window-bar > .window-close').on('click', () => {
_windowStorage.hide();
});
$('.button-clear-app').on('click', () => {
CreateVerify().then((val) => {
for (const key in localStorage) {
if (exception.includes(key)) {
continue;
}
localStorage.removeItem(key);
}
for (const key in sessionStorage) {
if (exception.includes(key)) {
continue;
}
sessionStorage.removeItem(key);
}
if (localStorage.getItem('application_installed')) {
const data = JSON.parse(localStorage.getItem('application_installed'));
if (data.installed) {
document.location.replace('/?mode=standalone');
}
}
document.location.replace('/');
}).catch((reason) => {

});
});
},
show: () => {
},
anim: {
showed: () => {

},
hided: () => {
$('.list-local-storage').empty();
$('.list-session-storage').empty();
}
},
hide: () => { },
verif: () => { return true; }
}

const _windowStorage = new WindowManagement(WindowStorage, '.window-app-size');

export function ShowStorage(title = "Хранилище") {
$('.select-bar > .window-title').text(title);
let d = 'KB', s = Storage.Local.size();
if (s > 1000) {
d = 'MB';
s = (s / 1000).toFixed(2);
}
$("#locdata > span").text(`${s} ${d}`);
d = 'KB', s = Storage.Session.size();
if (s > 1000) {
d = 'MB';
s = (s / 1000).toFixed(2);
}
$("#sesdata > span").text(`${Storage.Session.size()} KB`);

let _xLen, _x;
for (_x in localStorage) {
if (!localStorage.hasOwnProperty(_x)) {
continue;
}
let d = 'KB';
_xLen = (((localStorage[_x].length + _x.length) * 2) / 1024).toFixed(2);
if (_xLen > 1000) {
d = 'MB';
_xLen = (_xLen / 1000).toFixed(2);
}
$('.list-local-storage').append(`<div class="storage-element"><div>${_x}</div><span>${_xLen} ${d}</span></div>`);
}
for (_x in sessionStorage) {
if (!sessionStorage.hasOwnProperty(_x)) {
continue;
}
let d = 'KB';
_xLen = (((sessionStorage[_x].length + _x.length) * 2) / 1024).toFixed(2);
if (_xLen > 1000) {
d = 'MB';
_xLen = (_xLen / 1000).toFixed(2);
}
$('.list-session-storage').append(`<div class="storage-element"><div>${_x}</div><span>${_xLen} ${d}</span></div>`);
}
_windowStorage.click();
}

export const Storage = {
Local: {
size: function () {
var _lsTotal = 0,
_xLen, _x;
for (_x in localStorage) {
if (!localStorage.hasOwnProperty(_x)) {
continue;
}
_xLen = ((localStorage[_x].length + _x.length) * 2);
_lsTotal += _xLen;
};
return (_lsTotal / 1024).toFixed(2);
}
},
Session: {
size: function () {
var _lsTotal = 0,
_xLen, _x;
for (_x in sessionStorage) {
if (!sessionStorage.hasOwnProperty(_x)) {
continue;
}
_xLen = ((sessionStorage[_x].length + _x.length) * 2);
_lsTotal += _xLen;
};
return (_lsTotal / 1024).toFixed(2);
}
},

size: function () {
var _lsTotal = 0,
_xLen, _x;
for (_x in localStorage) {
if (!localStorage.hasOwnProperty(_x)) {
continue;
}
_xLen = ((localStorage[_x].length + _x.length) * 2);
_lsTotal += _xLen;
};
for (_x in sessionStorage) {
if (!sessionStorage.hasOwnProperty(_x)) {
continue;
}
_xLen = ((sessionStorage[_x].length + _x.length) * 2);
_lsTotal += _xLen;
};
return (_lsTotal / 1024).toFixed(2);
}
}
Loading

0 comments on commit b73908f

Please sign in to comment.