Skip to content

Commit

Permalink
Merge pull request #100 from AN0NCER/develop
Browse files Browse the repository at this point in the history
New way to update
  • Loading branch information
AN0NCER authored Apr 27, 2024
2 parents 09e1ec9 + ab35ab5 commit 742c47b
Show file tree
Hide file tree
Showing 27 changed files with 818 additions and 119 deletions.
23 changes: 18 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@
</div>
</div>

<div class="app-update">
<div class="update-content-version">
<span class="text-update">Обновление</span>
<div class="to-version">
<span class="cur version">4fg5d</span>
<span class="version">></span>
<span class="next">37eeg</span>
</div>
</div>
<div class="update-progress">
<div class="progress"></div>
</div>
</div>

<!-- Slider main container -->
<div class="swiper-treilers mbs">
<!-- Additional required wrapper -->
Expand Down Expand Up @@ -157,12 +171,11 @@
</div>

<div class="github unselectable">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512">
<path
d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z" />
</svg>
<div class="title">Tunime</div>
<div class="version">v <span>0.0.0</span></div>
<div class="version-hash">
<div class="version">v <span>0.0.0</span></div>
<div class="hash"></div>
</div>
<div class="date">2022.12.28</div>
</div>

Expand Down
10 changes: 7 additions & 3 deletions javascript/modules/ActionVerify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const WindowVerify = {
anim: {
hided: () => {
$(`.window-verify-action`).remove();

}
},
show: () => {
Expand All @@ -21,10 +21,14 @@ const WindowVerify = {



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

const pin = $(`#pin-${id}`);
Expand Down
66 changes: 55 additions & 11 deletions javascript/modules/TunimeApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const Tunime = {
server: new Server(),
Online: function (access = this.storage.access) {
return new Promise((resolve) => {
const cods = [666, 403]
const cods = [666, 403, 400];
if (!this.storage.Live(access)) {
access = undefined;
}
Expand All @@ -150,6 +150,10 @@ export const Tunime = {
let responseCode = 503;
Fetch('/online', { method: 'POST', headers: headers, body: body }).then((response) => {
responseCode = response.status;
if (responseCode == 401) {
Tunime.storage.access = undefined;
return resolve(this.Online(Tunime.storage.access));
}
if (cods.includes(responseCode)) {
Tunime.storage.access = undefined;
return resolve(false);
Expand Down Expand Up @@ -195,15 +199,20 @@ export const Tunime = {
let responseCode = 503;
Fetch('/video/source', { method: 'POST', body, headers }).then((response) => {
responseCode = response.status;
if (responseCode == 401) {
Tunime.storage.access = undefined;
return this.Online(Tunime.storage.access).then((val) => {
if (val)
resolve(this.Source(kodik, Tunime.storage.access));
});
}
response.json().then((value) => {
return resolve(value.data);
});
}).catch(async (reason) => {
console.log(`[api] - Error: ${Tunime.server.url} Code: ${responseCode}\n${reason}`);
if (responseCode == 503) {
return;
// URL = `onrender.com`;
return resolve(this.Source(kodik, access));
}
await Sleep(1000);
return resolve(this.Source(kodik, access));
Expand All @@ -220,15 +229,20 @@ export const Tunime = {
let responseCode = 503;
Fetch(`/anime/${aid}`, { method: 'POST', body, headers }).then((response) => {
responseCode = response.status;
if (responseCode == 401) {
Tunime.storage.access = undefined;
return this.Online(Tunime.storage.access).then((val) => {
if (val)
resolve(this.Anime(aid, Tunime.storage.access));
});
}
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.Anime(aid, access));
}
await Sleep(1000);
return resolve(this.Anime(aid, access));
Expand All @@ -245,15 +259,20 @@ export const Tunime = {
let responseCode = 503;
Fetch(`/voices/${aid}`, { method: 'GET', headers }).then((response) => {
responseCode = response.status;
if (responseCode == 401) {
Tunime.storage.access = undefined;
return this.Online(Tunime.storage.access).then((val) => {
if (val)
resolve(this.Voices(aid, Tunime.storage.access).GET());
});
}
response.json().then((value) => {
return resolve(value.data);
});
}).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).GET());
}
await Sleep(1000);
return resolve(this.Voices(aid, access).GET());
Expand All @@ -266,15 +285,20 @@ export const Tunime = {
const body = { key: access.key, id: access.id, tid };
Fetch(`/voices/${aid}`, { method: 'POST', headers, body }).then((response) => {
responseCode = response.status;
if (responseCode == 401) {
Tunime.storage.access = undefined;
return this.Online(Tunime.storage.access).then((val) => {
if (val)
resolve(this.Voices(aid, Tunime.storage.access).SET(tid));
});
}
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));
Expand Down Expand Up @@ -313,25 +337,45 @@ export const Tunime = {
(async () => {
const exception = ['/player.html'];
let minute = 60000;
let interval = undefined;
if (exception.includes(window.location.pathname))
return;

if (Tunime.storage.access === undefined || !Tunime.storage.Live()) {
const access = await Tunime.Online();
if (access) {
const interval = setInterval(async () => {
interval = setInterval(async () => {
const access = await Tunime.Online();
if (!access)
clearInterval(interval);
}, (LIFETIME - minute) - (Date.now() - Tunime.storage.access.date));
}
} else {
const interval = setInterval(async () => {
interval = setInterval(async () => {
const access = await Tunime.Online();
if (!access)
clearInterval(interval);
}, (LIFETIME - minute) - (Date.now() - Tunime.storage.access.date));
}

//Доработать этот код

// document.addEventListener('visibilitychange', async function () {
// if (document.visibilityState === "visible") {
// if (!Tunime.storage.Live())
// await Tunime.Online();
// interval = setInterval(async () => {
// const access = await Tunime.Online();
// if (!access)
// clearInterval(interval);
// }, (LIFETIME - minute) - (Date.now() - Tunime.storage.access.date));
// console.log(`[api] - Continue Interval: Next ${((LIFETIME - minute) - (Date.now() - Tunime.storage.access?.date))} ms`);
// } else {
// console.log(`[api] - Stop Interval`);
// clearInterval(interval);
// }
// });

console.log(`[api] - Interval Started: Next ${((LIFETIME - minute) - (Date.now() - Tunime.storage.access?.date))} ms`);
})();

Expand Down
13 changes: 13 additions & 0 deletions javascript/modules/Windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class WindowManagement {
await Sleep(300);
el.addClass('hide');
$(`${this.element} > .hide-window`).css('opacity', '');
$(window).off(`resize.${this.element}`);
if (this.target.anim?.hided) {
this.target.anim.hided();
}
Expand All @@ -64,8 +65,20 @@ export class WindowManagement {
$(`${this.element} > .window-content`).removeClass('hide');
await Sleep(10);
$(`${this.element} > .window-content`).css('transform', 'translateY(0%)')
$(window).on(`resize.${this.element}`, this.#resize.bind(this));
$(window).resize();
if (this.target.anim?.showed) {
this.target.anim.showed();
}
}

#resize() {
const wHeight = $(window).height(),
eHeight = $(`${this.element}>.window-content`).height();
if (wHeight <= eHeight) {
$(`${this.element}>.window-content`).addClass('border-hide');
} else {
$(`${this.element}>.window-content`).removeClass('border-hide');
}
}
}
2 changes: 1 addition & 1 deletion javascript/pages/index/mod_animes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function LoadAnimeShikimori({ status = 'ongoing', limit = _limitAnime, ge
Animes.list(q, async (response) => {
if (response.failed && response.status == 429) {
await Sleep(1000);
return GetAnimeShikimori();
return LoadAnimeShikimori({status, limit, genre, take, reflex, order, exclude_ids});
}

const element = $('.section-anime');
Expand Down
53 changes: 15 additions & 38 deletions javascript/pages/index/mod_github.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,21 @@ import { SetUpdateData, ShowUpdateWindow, UpdateKey } from "./mod_window.js";
const url = "https://api.github.com/repos/AN0NCER/an0ncer.github.io/releases/latest";

export function GitHubRel() {
fetch(url).then(async (response) => {
if (!response.ok) {
OfflineData();
return;
try {
const data = JSON.parse(localStorage.getItem(UpdateKey()));
if (data.show) {
fetch(url).then(async (response) => {
if (!response.ok) {
return;
}
const jsonData = await response.json();
if (jsonData.tag_name === data.ver) {
SetUpdateData(jsonData);
ShowUpdateWindow();
}
});
}

const jsonData = await response.json();
const dateLastRelease = new Date(jsonData.published_at);

$('.github > .version > span').text(jsonData.tag_name); // <- Отображение текущей версии с гита
$('.github > .date').text(`${dateLastRelease.getFullYear()}.${dateLastRelease.getMonth() + 1}.${dateLastRelease.getDate()}`); // <- Отображение даты последнего релиза
UpdatetGithub(jsonData);
});
}


function UpdatetGithub(data) {
let saved_git_version = JSON.parse(localStorage.getItem('github-version'));

if (saved_git_version == null || saved_git_version.tag != data.tag_name) {
//Пользователь находиться без ключа об обновлениях
if (localStorage.getItem(UpdateKey()) == null) {
localStorage.setItem(UpdateKey(), false);
}
//Если было обновление показываем диалоговое окно
if (localStorage.getItem(UpdateKey()) == "true") {
SetUpdateData(data);
ShowUpdateWindow();
}
}
}

function OfflineData() {
let saved_git_version = JSON.parse(localStorage.getItem('github-version'));
if (saved_git_version == null) {
return;
} catch (err) {
console.log('Ошибка отображения обновления', err);
}
let date = new Date(saved_git_version.published_at);
$('.github > .version > span').text(saved_git_version.tag);
$('.github > .date').text(`${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`);
}
1 change: 0 additions & 1 deletion javascript/pages/index/mod_notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ function GENERATE() {
return GENERATE().html(e.read, e.id, episode, e.linked.id, e.created_at, body, e.linked.episodes_aired, e.linked.episodes, issetVoice, "Новый эпизод");
},
release: (e) => {
console.log(e);
const body = `Завершён показ аниме <b>"${e.linked.russian}"</b>`;
const issetVoice = localStorage.getItem(e.linked.id) ? true : false;
if (issetVoice) {
Expand Down
8 changes: 7 additions & 1 deletion javascript/pages/index/mod_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ const WindowUpdate = {
},

hide: function () {
localStorage.setItem(_updateKey, false);
try {
let data = JSON.parse(localStorage.getItem(_updateKey));
data.show = false;
localStorage.setItem(_updateKey, JSON.stringify(data));
} catch {

}
localStorage.setItem('github-version', JSON.stringify({ tag: this.data.tag_name, published_at: this.data.published_at }));
},

Expand Down
7 changes: 5 additions & 2 deletions javascript/pages/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ Main((e) => {
ShowVoice();
ShowHistory();
Events();
Recomendation();
// Recomendation();
$('.recomendation-none > span').text('Рекомендации отключены разработчиком');
localStorage.removeItem('recomendation-database');
localStorage.removeItem('tunime-recomendation');
});

InitMenu();
Expand Down Expand Up @@ -541,7 +544,7 @@ function ShowHistory() {

for (let i = 0; i < response.length; i++) {
const element = response[i];
$(`main.history > .content > a[data-id="${element.id}"]`).append(ACard.Gen({response: element, link: false}));
$(`main.history > .content > a[data-id="${element.id}"]`).append(ACard.Gen({ response: element, link: false }));
}
}).GET();
}
Expand Down
Loading

0 comments on commit 742c47b

Please sign in to comment.