Skip to content

Commit

Permalink
Merge pull request #19 from AN0NCER/develop
Browse files Browse the repository at this point in the history
May update
  • Loading branch information
AN0NCER authored Apr 30, 2023
2 parents 7e49ffd + ef4aebf commit 76ee2e6
Show file tree
Hide file tree
Showing 15 changed files with 1,256 additions and 547 deletions.
29 changes: 16 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,24 +159,26 @@
<div class="date">2022.12.28</div>
</div>

<span class="frame-dialog unselectable" style="display: none;">
<div class="dialog">
<div class="wraper">
<div class="title">
<span class="text"></span>
<span class="version"><span></span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<span class="windowed hide">
<span class="hide-window"></span>
<!--Окно с обновлением-->
<span class="window-content content-update">
<span class="content-wraper">
<div class="title-content">
<span class="title">Обновление</span>
<span class="tag"><span class="t">0.0.0</span>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<path
d="M0 80V229.5c0 17 6.7 33.3 18.7 45.3l176 176c25 25 65.5 25 90.5 0L418.7 317.3c25-25 25-65.5 0-90.5l-176-176c-12-12-28.3-18.7-45.3-18.7H48C21.5 32 0 53.5 0 80zm112 32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z" />
d="M0 80V229.5c0 17 6.7 33.3 18.7 45.3l176 176c25 25 65.5 25 90.5 0L418.7 317.3c25-25 25-65.5 0-90.5l-176-176c-12-12-28.3-18.7-45.3-18.7H48C21.5 32 0 53.5 0 80zm112 32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z">
</path>
</svg>
</span>
</div>
</div>
<div class="btn-submit">
<div class="submit">
Принять
<div class="update-content-wraper">
</div>
</div>
</div>
<div class="btn-submit">Принять</div>
</span>
</span>
</span>

<footer></footer>
Expand All @@ -185,6 +187,7 @@
<script src="/javascript/library/swiper-bundle.min.js"></script>
<!--Custom library-->
<script src="/javascript/server.js"></script>
<script src="/javascript/engine/window_managment.js"></script>
<script src="/javascript/custom/updatedialog.js"></script>
<script src="/javascript/jmenu.js"></script>
<script src="/javascript/shikimori.js"></script>
Expand Down
251 changes: 132 additions & 119 deletions javascript/custom/updatedialog.js

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions javascript/engine/window_managment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//Управление окнами визуала
const WindowManagment = {
authorized: false,
showed: false,

target: {
/**
* Инициализация функции окна, запускается если прошел верификацию (this.verif)
*/
init: function () { },
/**
* Отображение окна
*/
show: function () { },
/**
* Скрытие окна
*/
hide: function () { },
/**
* Проверка для инициализация окна. Если проверка не нужна просто верни true
* @returns Возвращает boolean
*/
verif: function () { return true; },
},

init: function (authorized) {
this.authorized = authorized;
$('.hide-window').click(() => {
this.hide();
this.target.hide();
})
},

click: function (target = this.target) {
if (!target.verif()) {
return;
}
this.target = target;
this.target.init();
this.show();
this.target.show();
},

hide: async function () {
this.showed = false;
let el = $('.windowed');
$('.hide-window').css('opacity', 0);
await sleep(300);
el.addClass('hide');
$('.hide-window').css('opacity', '');
},

show: async function () {
this.showed = true;
let el = $('.windowed.hide');
el.css('display', 'block');
await sleep(10);
$('.hide-window').css('opacity', 1);
el.removeClass('hide');
el.css('display', '');
await sleep(300);
$('.hide-window').css('opacity', '');
}
}
38 changes: 28 additions & 10 deletions javascript/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let genres = '';
//Авторизация пользователя true / false
//Метод Main вызывается файлом shikimori.js
Main((e) => {
WindowManagment.init(e);
if (e) {
CountNotification();
ShowUser();
Expand Down Expand Up @@ -131,14 +132,15 @@ function CreateElementHistory(data) {
const prcnt = data.fullduration ? calculatePercentage(data.duration, data.fullduration) : calculatePercentage(data.duration, data.duration);
const time = Math.floor(data.duration / 60) + ':' + (data.duration % 60).toString().padEnd(2, '0');
const link = `watch.html?id=${data.id}&player=true&continue=${data.continue}`;
const image = data.image.includes("https://nyaa.shikimori.me/") ? data.image.replace('https://nyaa.shikimori.me/', '') : data.image.replace('https://nyaa.shikimori.one/', '') ? data.image.replace('https://nyaa.shikimori.one/', '') : data.image;
return `<div class="swiper-slide"><div class="frame-info"><div class="frame-status">
<div class="status">Эпизод: <b>${data.episode}</b> [${time}]</div>
<div class="name">${data.name}</div>
</div>
<a href="${link}">
<div class="btn"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M73 39c-14.8-9.1-33.4-9.4-48.5-.9S0 62.6 0 80V432c0 17.4 9.4 33.4 24.5 41.9s33.7 8.1 48.5-.9L361 297c14.3-8.7 23-24.2 23-41s-8.7-32.2-23-41L73 39z" /></svg>Продолжить</div></a></div><div class="frame-anime">
<div class="progress-watch" style="width: ${prcnt}%;"></div>
<img src="${data.image}"
<img src="https://nyaa.shikimori.me/${image}"
alt="${data.name}">
<a href="${link}">
<div class="btn"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M73 39c-14.8-9.1-33.4-9.4-48.5-.9S0 62.6 0 80V432c0 17.4 9.4 33.4 24.5 41.9s33.7 8.1 48.5-.9L361 297c14.3-8.7 23-24.2 23-41s-8.7-32.2-23-41L73 39z" /></svg></div></a></div></div>`;
Expand Down Expand Up @@ -204,25 +206,30 @@ async function GitHubRelease() {
$('.github > .version > span').text(data[0].tag_name);
$('.github > .date').text(`${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`);


//Если версия гита отличается от версии сохраненной, то показывем диалоговое окно
// console.log(localStorage.getItem('github-version'));

let saved_git_verrsion = JSON.parse(localStorage.getItem('github-version'));
if (saved_git_verrsion == null || saved_git_verrsion.tag != data[0].tag_name) {
//Если у пользователя нет ключа оюновления то он первый раз
if (localStorage.getItem(dialog.key) == null) {
localStorage.setItem(dialog.key, true);
if (localStorage.getItem(UpdateWindow.key) == null) {
localStorage.setItem(UpdateWindow.key, true);
}
//Елси было обновление то показываем диалоговое окно
if (localStorage.getItem(dialog.key) == "true") {
dialog.show(() => {
localStorage.setItem(dialog.key, false);
//Сохраняем новые данные с github
localStorage.setItem('github-version', JSON.stringify({ tag: data[0].tag_name, published_at: data[0].published_at }));
}, data);
if (localStorage.getItem(UpdateWindow.key) == "true") {
UpdateWindow.data = data;
WindowManagment.click(UpdateWindow);
}
}
}else{
//Если ответа от Githuba не будет то изменяем на сохранненый тег
let saved_git_verrsion = JSON.parse(localStorage.getItem('github-version'));
if (saved_git_verrsion == null){
return;
}
let date = new Date(saved_git_verrsion.published_at);
$('.github > .version > span').text(saved_git_verrsion.tag);
$('.github > .date').text(`${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`);
}
});
}
Expand Down Expand Up @@ -299,6 +306,17 @@ $('.search > .btn').click((e) => {
window.location.href = '/search.html?val=' + value;
});

//Событие Enter unput search
$('.search > input').on('keypress',function(e) {
if(e.which == 13) {
let value = this.value;
if(value.length <= 0){
return;
}
window.location.href = '/search.html?val=' + value;
}
});

/**
* Автоматическая авторизация
*/
Expand Down
55 changes: 28 additions & 27 deletions javascript/pages/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,45 +133,47 @@ async function LoadingAnimeFromTask(task = task_loading) {
//Локальный список задачи; Он нужен чтобы можно было сверить не был ли изменен один из списка задач
let local_task = task;

//Проходимся по локальному списку

//Проверяем что в списке нет ничего не нужного
//(То есть загруженных аниме)
for (let i = 0; i < local_task.length; i++) {
const id = local_task[i];

//Если списки стали отличаться то выходим из цикла, буле новая задача загрузки с новым списком с другими приоритетами
if (task_loading != task) {
return false;
}

//Чтоб случайно не созать уже в готовом елементе новый елемент делаем проверку на DOM
const elem = document.querySelector(`a[data-id="${id}"]`);
if (elem.childNodes.length == 0)
await LoadAnime(id);//Загружаем аниме
if (elem.childNodes.length != 0)
local_task.slice(i, 1);
}

await LoadAnimes(local_task);

/**
* Ставит аниме на очерель загрузки
* @param {Integer} id - аниме
* @param {Array} list - список для загрзки аниме
* @returns Boolean - выполнено
*/
async function LoadAnime(id) {
async function LoadAnimes(list) {
return new Promise((resolve) => {
//Указываем что загрузка пошла. Эту загрузку никак отменить нельзя
let target = $(`a[data-id="${id}"]`);
//Ставим чтобы можно было понять была ли запущена загрузка или нет
target.attr('data-loaded', true);
for (let i = 0; i < list.length; i++) {
const id = list[i];

//Делаем запро
shikimoriApi.Animes.id(id, async (response) => {
//Указываем что загрузка пошла. Эту загрузку никак отменить нельзя
let target = $(`a[data-id="${id}"]`);
//Ставим чтобы можно было понять была ли запущена загрузка или нет
target.attr('data-loaded', true);
}

shikimoriApi.Animes.animes({ ids: list.toString(), limit: list.length }, async (response) => {
if (response.failed && response.status == 429) {
await sleep(1000);
resolve(await LoadAnime(id));
resolve(await LoadAnimes(list));
return;
}

//Добавляем аниме
AddAnime(response);
for (let i = 0; i < response.length; i++) {
const element = response[i];
AddAnime(element)
}
resolve(true);
}, true);
})
});
}

Expand All @@ -186,7 +188,7 @@ async function LoadingAnimeFromTask(task = task_loading) {
//Устанавливем значения
target.attr('data-type', response.kind)
//Присваем стрктуру к елементу
target.append(GenerateCardHtml(response));
target.append(GenerateCardHtml(response, target.attr('data-score')));

//Если после того как мы узнали что тип не соответсвует этому елемент, то надо скрыть елемент
if (!current_type.includes(target.attr('data-type'))) {
Expand All @@ -201,8 +203,8 @@ async function LoadingAnimeFromTask(task = task_loading) {
* @param {Object} response shikimori ответ anime
* @returns Возваращет готовый html картки аниме
*/
function GenerateCardHtml(response) {
return `<div class="card-content"><img src="https://moe.shikimori.me/${response.image.original}"><div class="title"><span>${response.russian}</span></div>${response.user_rate.score > 0 ? `<div class="my-score"><svg width="7" height="6" viewBox="0 0 7 6" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.19916 0.210914C4.13607 0.0820221 4.00275 0 3.85634 0C3.70993 0 3.5778 0.0820221 3.51352 0.210914L2.74813 1.76113L1.0388 2.00954C0.89596 2.03063 0.776925 2.12906 0.732883 2.26381C0.68884 2.39856 0.72455 2.54737 0.82692 2.64697L2.06726 3.85504L1.77443 5.56227C1.75063 5.70288 1.81014 5.84583 1.92799 5.92902C2.04583 6.01222 2.20177 6.02276 2.33032 5.95597L3.85753 5.15333L5.38474 5.95597C5.5133 6.02276 5.66923 6.01339 5.78708 5.92902C5.90492 5.84466 5.96444 5.70288 5.94063 5.56227L5.64662 3.85504L6.88696 2.64697C6.98933 2.54737 7.02623 2.39856 6.98099 2.26381C6.93576 2.12906 6.81792 2.03063 6.67507 2.00954L4.96455 1.76113L4.19916 0.210914Z" fill="white"/></svg>${response.user_rate.score}</div>` : ""}</div><div class="card-information"><div class="year">${new Date(response.aired_on).getFullYear()}</div><div class="score"><svg width="8" height="8" viewBox="0 0 8 8" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.73196 0.745728C4.65834 0.595337 4.50279 0.499634 4.33196 0.499634C4.16112 0.499634 4.00696 0.595337 3.93196 0.745728L3.0389 2.55452L1.04446 2.84436C0.877789 2.86897 0.7389 2.98381 0.687511 3.14104C0.636122 3.29827 0.677789 3.4719 0.797233 3.58811L2.24446 4.99768L1.90279 6.98967C1.87501 7.15374 1.94446 7.32053 2.08196 7.4176C2.21946 7.51467 2.4014 7.52698 2.5514 7.44905L4.33334 6.51252L6.11529 7.44905C6.26529 7.52698 6.44723 7.51604 6.58473 7.4176C6.72223 7.31917 6.79168 7.15374 6.7639 6.98967L6.42084 4.99768L7.86807 3.58811C7.98751 3.4719 8.03057 3.29827 7.97779 3.14104C7.92501 2.98381 7.78751 2.86897 7.62084 2.84436L5.62501 2.55452L4.73196 0.745728Z" fill="#FFE600"/></svg>${response.score}</div></div>`;
function GenerateCardHtml(response, score) {
return `<div class="card-content"><img src="https://moe.shikimori.me/${response.image.original}"><div class="title"><span>${response.russian}</span></div>${score > 0 ? `<div class="my-score"><svg width="7" height="6" viewBox="0 0 7 6" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.19916 0.210914C4.13607 0.0820221 4.00275 0 3.85634 0C3.70993 0 3.5778 0.0820221 3.51352 0.210914L2.74813 1.76113L1.0388 2.00954C0.89596 2.03063 0.776925 2.12906 0.732883 2.26381C0.68884 2.39856 0.72455 2.54737 0.82692 2.64697L2.06726 3.85504L1.77443 5.56227C1.75063 5.70288 1.81014 5.84583 1.92799 5.92902C2.04583 6.01222 2.20177 6.02276 2.33032 5.95597L3.85753 5.15333L5.38474 5.95597C5.5133 6.02276 5.66923 6.01339 5.78708 5.92902C5.90492 5.84466 5.96444 5.70288 5.94063 5.56227L5.64662 3.85504L6.88696 2.64697C6.98933 2.54737 7.02623 2.39856 6.98099 2.26381C6.93576 2.12906 6.81792 2.03063 6.67507 2.00954L4.96455 1.76113L4.19916 0.210914Z" fill="white"/></svg>${score}</div>` : ""}</div><div class="card-information"><div class="year">${new Date(response.aired_on).getFullYear()}</div><div class="score"><svg width="8" height="8" viewBox="0 0 8 8" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.73196 0.745728C4.65834 0.595337 4.50279 0.499634 4.33196 0.499634C4.16112 0.499634 4.00696 0.595337 3.93196 0.745728L3.0389 2.55452L1.04446 2.84436C0.877789 2.86897 0.7389 2.98381 0.687511 3.14104C0.636122 3.29827 0.677789 3.4719 0.797233 3.58811L2.24446 4.99768L1.90279 6.98967C1.87501 7.15374 1.94446 7.32053 2.08196 7.4176C2.21946 7.51467 2.4014 7.52698 2.5514 7.44905L4.33334 6.51252L6.11529 7.44905C6.26529 7.52698 6.44723 7.51604 6.58473 7.4176C6.72223 7.31917 6.79168 7.15374 6.7639 6.98967L6.42084 4.99768L7.86807 3.58811C7.98751 3.4719 8.03057 3.29827 7.97779 3.14104C7.92501 2.98381 7.78751 2.86897 7.62084 2.84436L5.62501 2.55452L4.73196 0.745728Z" fill="#FFE600"/></svg>${response.score}</div></div>`;
}
}

Expand Down Expand Up @@ -254,9 +256,8 @@ function AddToLoadTask(response = response_user_rates) {
task_loading = []; // Очищаем список
for (let index = 0; index < response.length; index++) {
const element = response[index];

//Со
$('.content').append(`<a href="/watch.html?id=${element.target_id}" class="${!current_status.includes(element.status) ? "hide-anime" : "show-anime"}" data-id="${element.target_id}" data-status="${element.status}" data-type="all" data-loaded="false"></a>`);
$('.content').append(`<a href="/watch.html?id=${element.target_id}" class="${!current_status.includes(element.status) ? "hide-anime" : "show-anime"}" data-score="${element.score}" data-id="${element.target_id}" data-status="${element.status}" data-type="all" data-loaded="false"></a>`);

if (current_status.includes(element.status) && current_type.includes("all")) {
task_loading.push(element.target_id);
Expand Down
Loading

0 comments on commit 76ee2e6

Please sign in to comment.