Skip to content

Commit

Permalink
Fix error (Not found function GetAnimeShikimori)
Browse files Browse the repository at this point in the history
  • Loading branch information
AN0NCER committed Apr 25, 2024
1 parent 38da17a commit 24c27cd
Show file tree
Hide file tree
Showing 14 changed files with 467 additions and 226 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
2 changes: 2 additions & 0 deletions javascript/modules/TunimeApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export const Tunime = {
};

(async () => {
return;
const exception = ['/player.html'];
let minute = 60000;
if (exception.includes(window.location.pathname))
Expand All @@ -336,6 +337,7 @@ export const Tunime = {
})();

function Fetch(path, { method = 'GET', body = undefined, headers = undefined } = {}) {
return;
const request = {
method
};
Expand Down
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
6 changes: 5 additions & 1 deletion javascript/pages/index/mod_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ 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
4 changes: 4 additions & 0 deletions javascript/pages/watch/mod_download.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ function LoadingEpisodes() {
$('.window-body-fs > .download-episode > .down-value').append(`<span class="down-episode" data-index="${count}">${count}<span class="ep-name">EP</span><svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><path d="M256 0a256 256 0 1 0 0 512A256 256 0 1 0 256 0zM376.9 294.6L269.8 394.5c-3.8 3.5-8.7 5.5-13.8 5.5s-10.1-2-13.8-5.5L135.1 294.6c-4.5-4.2-7.1-10.1-7.1-16.3c0-12.3 10-22.3 22.3-22.3l57.7 0 0-96c0-17.7 14.3-32 32-32l32 0c17.7 0 32 14.3 32 32l0 96 57.7 0c12.3 0 22.3 10 22.3 22.3c0 6.2-2.6 12.1-7.1 16.3z"/></svg></span>`);
}

if (e === undefined) {
$('.download-episode').hide();
}

$('.window-body-fs > .download-episode > .down-value > .down-episode').on('click', function (e) {
const element = $(e.currentTarget);
const index = element.attr('data-index');
Expand Down
1 change: 1 addition & 0 deletions javascript/pages/watch/mod_resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export async function LoadAnime(e = () => { }, isLogged = false) {
});

function Complete(response) {
console.log(response);
//Проверяем если есть у нас фрашиза
if (response.nodes) {
//Отоброжаем блок с франшизой
Expand Down
6 changes: 6 additions & 0 deletions javascript/pages/watch/mod_translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const WindowTranslation = {
});

$('.translation-param > .checkbox > input').prop('checked', $PARAMETERS.watch.dubanime);

//Автоматическое скрытие окна при выборе озвучки
Player().translation.events.onselected((e) => {
this.hide();
_windowTranslation.hide();
});
},
show: () => {
$("body").addClass("loading");
Expand Down
187 changes: 162 additions & 25 deletions javascript/server.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,166 @@
/**
* Когда была команда обновить файлы;
* В нашем примере это работает как обновление программы
*/
navigator.serviceWorker?.addEventListener('controllerchange', () => {
//Указываем что было обновление
localStorage.setItem('dialog-update', true);
//Чтобы изменения вступили в силу нужно перезагрузить страницу (программу)
window.location.reload();
});
const SW = navigator.serviceWorker;
let currentVersion = { ver: 'undef', hash: 'undef' };

(async () => {
if (SW) {
//Статус о регистрации sw.js в приложении
const regInfo = await SW.getRegistration();

if (regInfo === undefined) {
await SW.register('sw.js', { scope: '/' }).then(() => {
console.log('[SW]: Registered successfully.');
}).catch(error => {
console.log('[SW]: Registration failed:', error);
});
}

Main();
}

async function Main() {
const pages = ['/', '/index.html'];
let newServiceWorker = undefined;


//Скрипт только для главной страницы
if (pages.includes(window.location.pathname) && SW) {
//Сообщения от SW
SW.addEventListener('message', (ev) => {
try {
/**@type {{id: number, val: string | object}} */
const data = JSON.parse(ev.data);
if (data.id === 220) {
currentVersion = data.val;
SetVersion();
}
} catch {
console.log('[SW] - Message', ev);
}
})
//Статус о регистрации sw.js в приложении
const regInfo = await SW.getRegistration();

if (regInfo.installing) {
newServiceWorker = regInfo.installing;
} else if (regInfo.waiting) {
newServiceWorker = regInfo.waiting;
ShowUpdate();
} else if (regInfo.active) {
newServiceWorker = regInfo.active;
}

regInfo.onupdatefound = (ev) => {
SW.getRegistration().then((swr) => {
if (swr.installing) {
newServiceWorker = swr.installing;
} else if (swr.waiting) {
newServiceWorker = swr.waiting;
} else if (swr.active) {
newServiceWorker = swr.active;
}
newServiceWorker.addEventListener('statechange', (ev) => {
if (ev.currentTarget.state === 'activated') {
CompleteUpdate();
}
});
})
//Во время пользоваением приложения было изменение sw.js
ShowUpdate();
}

newServiceWorker.addEventListener('statechange', ev => {
//Установлена новая версия sw.js (обновляем страницу чтобы применить изменения)
if (ev.currentTarget.state === 'activated') {
CompleteUpdate();
}
});

SW.ready.then(registartion => {
if (registartion.active) {
registartion.active.postMessage(220);
}
});

async function ShowUpdate() {
const newVersion = await ParseVersion();
// console.log(`${currentVersion.ver} > ${newVersion.ver}`);
// console.log(`${currentVersion.hash} > ${newVersion.hash}`);
$('.app-update').css({ display: 'flex' });
if (currentVersion.ver === newVersion.ver) {
$('.update-content-version > .to-version > .cur').text(currentVersion.hash);
$('.update-content-version > .to-version > .next').text(newVersion.hash);
} else {
$('.update-content-version > .to-version > .cur').text(currentVersion.ver);
$('.update-content-version > .to-version > .next').text(newVersion.ver);
//Указываем что было обновление
localStorage.setItem('dialog-update', JSON.stringify({ show: true, ver: newVersion.ver, update: new Date().toJSON() }));
}
setTimeout(() => {
$('.app-update').addClass('show');
setTimeout(() => {
$('.update-progress > .progress').css({ width: '50%' });
setTimeout(() => {
SW.getRegistration().then((reg) => {
if (reg.waiting) {
reg.waiting.postMessage(221);
}
});
}, 500)
}, 500);
}, 300)
}

function CompleteUpdate() {
$('.update-progress > .progress').css({ width: '100%' });
setTimeout(() => {
location.reload()
}, 800);
}

function SetVersion() {
$('.github > .version-hash > .version > span').text(currentVersion.ver);
$('.github > .version-hash > .hash').text(currentVersion.hash);
try {
const data = JSON.parse(localStorage.getItem('dialog-update'));
let date = new Date(data.update);
$('.github > .date').text(`${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`);
} catch (error) {
console.log('Ошибка отображения версии', error);
}
}
}
}
})();

/**
* Регистрируем ServiceWorker
* Получает версию с файла sw.js
* @returns {Promise<{ver: string, hash: string}>}
*/
function registerServiceWorker() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js', { scope: '/' }).then(() => {
console.log('[SW]: Registered successfully.');
}).catch(error => {
console.log('[SW]: Registration failed:', error);
});
}
}
function ParseVersion() {
return new Promise((resolve) => {
fetch('sw.js').then((val) => {
val.text().then(val => {
const versionRegex = /const\s+version\s+=\s+'([^']+)';/;
const hashRegex = /const\s+hash\s+=\s+'([^']+)';/;

const versionMatch = val.match(versionRegex);
const hashMatch = val.match(hashRegex);

//Начало программы server.js
(() => {
//Регистриуем приложение service worker
registerServiceWorker();
})();
if (versionMatch && hashMatch) {
// Извлекаем значения версии и хэша из найденных совпадений
const versionValue = versionMatch[1];
const hashValue = hashMatch[1];

// Возвращаем объект с извлеченными значениями
return resolve({ ver: versionValue, hash: hashValue })
} else {
return resolve({ ver: '0.0.0', hash: '00000' });
}
}).catch(reason => {
return resolve({ ver: '0.0.0', hash: '00000' });
})
}).catch(reason => {
return resolve({ ver: '0.0.0', hash: '00000' });
});
});
}
2 changes: 0 additions & 2 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<meta name="page" content="settings">
<title>Tunime - Настройка</title>
<link rel="icon" type="image/png" href="/images/icon-web.png" />
<link rel="apple-touch-icon" sizes="120x120" href="icon-192x192.png" />
<link rel="apple-touch-icon" sizes="152x152" href="icon-192x192.png" />
<link rel="stylesheet" href="/style/css/main.css">

<meta name="apple-mobile-web-app-capable" content="yes">
Expand Down
Loading

0 comments on commit 24c27cd

Please sign in to comment.