Обновлен сервисный рабочий скрипт для улучшения кэширования и обработки запросов. Добавлены новые маршруты для кэширования HTML и статических ресурсов, а также улучшена логика обработки внешних ссылок в Markdown. Удалены устаревшие стили для кнопок и ссылок. Оптимизирована работа с чекбоксами в списках.

This commit is contained in:
Fovway 2025-11-04 10:43:07 +07:00
parent 2ec93b8cc2
commit a78d976bcf
3 changed files with 71 additions and 46 deletions

View File

@ -81,15 +81,34 @@ define(['./workbox-9dc17825'], (function (workbox) { 'use strict';
"url": "registerSW.js", "url": "registerSW.js",
"revision": "3ca0b8505b4bec776b69afdba2768812" "revision": "3ca0b8505b4bec776b69afdba2768812"
}, { }, {
"url": "index.html", "url": "/index.html",
"revision": "0.o51qplqi6t" "revision": "0.3mraah3n9jg"
}], {}); }], {});
workbox.cleanupOutdatedCaches(); workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), { workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("/index.html"), {
allowlist: [/^\/$/] allowlist: [/^\/$/],
denylist: [/^\/api/, /^\/_/]
})); }));
workbox.registerRoute(({
request
}) => request.destination === "document" || request.url.endsWith("/") || request.url.endsWith("/index.html"), new workbox.NetworkFirst({
"cacheName": "html-cache",
"networkTimeoutSeconds": 3,
plugins: [new workbox.ExpirationPlugin({
maxEntries: 10,
maxAgeSeconds: 86400
})]
}), 'GET');
workbox.registerRoute(/\.(?:js|css|woff|woff2|ttf|eot)$/, new workbox.CacheFirst({
"cacheName": "static-resources-cache",
plugins: [new workbox.ExpirationPlugin({
maxEntries: 200,
maxAgeSeconds: 31536000
})]
}), 'GET');
workbox.registerRoute(/^https:\/\/api\./, new workbox.NetworkFirst({ workbox.registerRoute(/^https:\/\/api\./, new workbox.NetworkFirst({
"cacheName": "api-cache", "cacheName": "api-cache",
"networkTimeoutSeconds": 3,
plugins: [new workbox.ExpirationPlugin({ plugins: [new workbox.ExpirationPlugin({
maxEntries: 50, maxEntries: 50,
maxAgeSeconds: 3600 maxAgeSeconds: 3600
@ -97,7 +116,7 @@ define(['./workbox-9dc17825'], (function (workbox) { 'use strict';
}), 'GET'); }), 'GET');
workbox.registerRoute(/\/api\//, new workbox.NetworkFirst({ workbox.registerRoute(/\/api\//, new workbox.NetworkFirst({
"cacheName": "api-cache-local", "cacheName": "api-cache-local",
"networkTimeoutSeconds": 10, "networkTimeoutSeconds": 3,
plugins: [new workbox.ExpirationPlugin({ plugins: [new workbox.ExpirationPlugin({
maxEntries: 100, maxEntries: 100,
maxAgeSeconds: 86400 maxAgeSeconds: 86400

View File

@ -118,7 +118,6 @@ body {
button { button {
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
-moz-tap-highlight-color: transparent; -moz-tap-highlight-color: transparent;
tap-highlight-color: transparent;
outline: none; outline: none;
box-shadow: none; box-shadow: none;
} }
@ -137,7 +136,6 @@ a,
div[role="button"] { div[role="button"] {
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
-moz-tap-highlight-color: transparent; -moz-tap-highlight-color: transparent;
tap-highlight-color: transparent;
outline: none; outline: none;
box-shadow: none; box-shadow: none;
} }

View File

@ -24,50 +24,58 @@ const spoilerExtension = {
}; };
// Кастомный renderer для внешних ссылок и чекбоксов // Кастомный renderer для внешних ссылок и чекбоксов
const renderer: any = { const renderer = new marked.Renderer();
link(token: any) {
const href = token.href;
const title = token.title;
const text = token.text;
// Переопределяем link для внешних ссылок
const originalLink = renderer.link.bind(renderer);
renderer.link = function(token: any) {
const href = token.href;
const title = token.title;
const text = token.text;
try {
const url = new URL(href, window.location.href);
const isExternal = url.origin !== window.location.origin;
if (isExternal) {
return `<a href="${href}" title="${
title || ""
}" target="_blank" rel="noopener noreferrer" class="external-link">${text}</a>`;
}
} catch {}
return originalLink(token);
};
// Переопределяем listitem для поддержки чекбоксов
renderer.listitem = function(token: any) {
const task = token.task;
const checked = token.checked;
// Получаем токены для обработки
const tokens = token.tokens || [];
let text: string;
// Используем this.parser.parseInline для обработки токенов (this указывает на renderer)
if (tokens.length > 0) {
try { try {
const url = new URL(href, window.location.href);
const isExternal = url.origin !== window.location.origin;
if (isExternal) {
return `<a href="${href}" title="${
title || ""
}" target="_blank" rel="noopener noreferrer" class="external-link">${text}</a>`;
}
} catch {}
return `<a href="${href}"${title ? ` title="${title}"` : ""}>${text}</a>`;
},
// Кастомный renderer для элементов списка с чекбоксами
listitem(token: any) {
const task = token.task;
const checked = token.checked;
// Используем tokens для правильной обработки форматирования внутри элементов списка
// token.tokens содержит массив токенов для вложенного содержимого
const tokens = token.tokens || [];
let text: string;
if (tokens.length > 0) {
// Используем this.parser.parseInline для правильной обработки вложенного форматирования
// this указывает на экземпляр Parser в контексте renderer
text = this.parser.parseInline(tokens); text = this.parser.parseInline(tokens);
} else { } catch (error) {
// Fallback на token.text, если tokens отсутствуют // Если ошибка, используем fallback
console.warn('Error parsing list item tokens:', error);
text = token.text || ''; text = token.text || '';
} }
} else {
text = token.text || '';
}
if (task) { // Если это задача (чекбокс), добавляем чекбокс
const checkbox = `<input type="checkbox" ${checked ? "checked" : ""} />`; if (task) {
return `<li class="task-list-item">${checkbox} ${text}</li>\n`; const checkbox = `<input type="checkbox" ${checked ? "checked" : ""} disabled />`;
} return `<li class="task-list-item">${checkbox} ${text}</li>\n`;
return `<li>${text}</li>\n`; }
},
return `<li>${text}</li>\n`;
}; };
// Настройка marked // Настройка marked