Список пользователей

1
Админ
Постов: 211
2
VIP
Постов: 72
3
Элита
Постов: 50
4
Проверенные
Постов: 35
5
VIP
Постов: 35
6
Проверенные
Постов: 32
7
Пользователи
Постов: 31
8
Проверенные
Постов: 29

  • Страница 1 из 1
  • 1
Парсер последних тем форума на главную страницу uCoz V 2.2
Дата: Четверг, 19.02.2026, 12:26 | Сообщение # 1 | | Написал: Узнаваемый
Автор темы
Мурчанн не в сети
        Сообщений:211
         Регистрация:20.10.2016

Полностью переработал парсер вывода новостей в несколько колонок.
Стили подключаются отдельно, поэтому вы можете легко настроить внешний вид карточек под свои задачи. Я оформил всё под дизайн своего сайта вы, при желании, можете адаптировать под свой.

Скрипт работает очень просто: достаточно указать ссылку на нужный раздел форума, и он автоматически будет подгружать оттуда последние новости. Количество выводимых карточек также настраивается укажите столько, сколько нужно вам.

В этой части задаются ключевые настройки работы парсера.

Код
/* ================= CONFIG ================= */

const container = document.querySelector('#custom-forum-cards');
if (!container) return;

const FORUM_URL = '/forum/3';
const CACHE_KEY = 'forum_cards_cache_nf_logic';
const FIRST_TOPIC_KEY = 'forum_first_topic_nf_logic';
const MAX_CARDS = 3;




Код
<style>
/* Контейнер */
#custom-forum-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 50px;
  justify-content: center;
  width: 100%;
  padding: 8px 0;
  margin-bottom: -14px;
  perspective: 1300px;

}

/* Карточка */
.custom-card {
  --clr-bg: #0e0e1f;
  --clr-glow: #00f0ff;
  --clr-accent: #ff2ed4;
  --clr-header: #6b48ff;
  --clr-badge: #00eaff;
  --clr-title: #ff2ed4;
  --clr-text: #d0e0ff;

  flex: 0 0 calc(25% - 21px);
  max-width: 246px;             /* 210 → +~10% ≈ 232 */
  height: 300px;                /* 270 → +~10% ≈ 297 */
  position: relative;
  border-radius: 8px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.75s cubic-bezier(0.23, 1, 0.32, 1);

}

.custom-card .card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.75s cubic-bezier(0.23, 1, 0.32, 1);
  border-radius: 18px;
  overflow: hidden;

}

.custom-card:hover .card-inner {
  transform: rotateY(180deg);
}

/* Лицевая и задняя стороны */
.card-front {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: linear-gradient(145deg, var(--clr-bg), #141428);
  border-radius: 18px;
  border: 1px solid rgba(100,140,255,0.15);
  box-shadow:
    inset 0 1px 3px rgba(180,200,255,0.06),
    inset 0 -6px 14px rgba(0,0,0,0.83);
}

.card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  transform: rotateY(180deg);
  background: linear-gradient(145deg, #180033, #0f001a);
  border-radius: 18px;
  color: #f0e8ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  padding: 18px;
  box-shadow: inset 0 0 45px rgba(255,46,212,0.22);
}

/* Свечение */
.custom-card::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 20px;
  background: conic-gradient(
    from 90deg at 50% 50%,
    transparent 0deg,
    var(--clr-glow) 60deg,
    var(--clr-accent) 150deg,
    var(--clr-glow) 300deg,
    transparent 360deg
  );
  opacity: 0.47;
  z-index: -1;
  filter: blur(12px);
  transition: opacity 0.75s ease;
}

.custom-card:hover::before {
  opacity: 0.87;
}

/* ─── Содержимое ─── */
.custom-card-header {
  position: absolute;
  top: 0px;
  left: 0px;
  width: 59%;
  height: 34px;
  background: linear-gradient(90deg, #4b2ecc, #7c5cff);
  backdrop-filter: blur(8px);
  border-radius: 5px;
  border: 1px solid rgba(180,140,255,0.3);
  box-shadow: 0 3px 14px rgba(107,72,255,0.48), inset 0 1px 3px rgba(255,255,255,0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.0px;
  font-weight: 800;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: #f0f0ff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.68);
  z-index: 12;
  pointer-events: none;
}

.custom-card-img {
  width: 100%;
  height: 49%;
  margin-top: 45px;
  overflow: hidden;
  border-bottom: 1px solid rgba(100,140,255,0.21);
  border-radius: 15px;
}

.custom-card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.85s ease;
}

.custom-card:hover .custom-card-img img {
  transform: scale(1.14);
}

.custom-card-title {
  font-weight: 800;
  font-size: 13.4px;
  padding: 11px 15px 5px;
  background: linear-gradient(90deg, var(--clr-title), #ff6edb);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 11px rgba(255,46,212,0.52);
  letter-spacing: 0.25px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-card-desc {
  font-size: 11.6px;
  line-height: 1.42;
  color: #c5d2ff;
  padding: 0 15px 14px;
  opacity: 0.93;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  text-shadow: 0 1px 3px rgba(0,0,0,0.72);
}

.custom-card-badge {
  position: absolute;
  top: 9px;
  right: 11px;
  background: linear-gradient(135deg, #00eaff, #00c2ff);
  color: #0a1a33;
  padding: 4px 10px;
  border-radius: 55px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.65px;
  text-transform: uppercase;
  box-shadow: 0 0 14px rgba(0,234,255,0.58), inset 0 1px 3px rgba(255,255,255,0.32);
  border: 1px solid rgba(0,200,255,0.4);
  backdrop-filter: blur(4px);
  z-index: 10;
}

/* Затемнение при наведении */
.card-front::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 39%, rgba(20,10,40,0.73) 100%);
  transition: opacity 0.75s ease;
  opacity: 0.36;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.custom-card:hover .card-front::after {
  opacity: 0.74;
}
</style>

<section class="sect flex-grow-1">
<div class="sect__header d-flex">
<h2 class="sect__title flex-grow-1">
Forum Updates
<img src="https://jordan.moy.su/forumimages/3droom.png" alt="3D Room Icon" style="height:24px; margin-left:-2px; vertical-align:middle;">
</h2>
</div>

<div class="dark-border">
<div id="custom-forum-cards"></div>
</div>
</section>

<script>
(async function(){

/* ===== SINGLE RUN LOCK ===== */
if(window.__CF_LOCK__) return;
window.__CF_LOCK__=true;

/* ================= CONFIG ================= */

const container = document.querySelector('#custom-forum-cards');
if (!container) return;

const FORUM_URL = '/forum/3';
const CACHE_KEY = 'forum_cards_cache_nf_logic';
const FIRST_TOPIC_KEY = 'forum_first_topic_nf_logic';
const MAX_CARDS = 3;

/* ================= UTILS ================= */

const toAbsolute=url=>!url?''
:url.startsWith('http')?url
:url.startsWith('//')?location.protocol+url
:location.origin+(url.startsWith('/')?url:'/'+url);

const escapeHtml=text=>String(text||'').replace(/[&<>"']/g,m=>(
{'&':'&','<':'<','>':'>','"':'"',"'":'''}[m]
));

function safeGet(k){try{return JSON.parse(localStorage.getItem(k)||'null')}catch{return null}}
function safeSet(k,v){try{localStorage.setItem(k,JSON.stringify(v))}catch{}}
function clearCache(){localStorage.removeItem(CACHE_KEY)}

async function fetchHTML(url){
const r=await fetch(url,{credentials:'same-origin',cache:'no-cache'});
if(!r.ok) throw 'fetch fail';
return await r.text();
}

/* ================= RENDER ================= */

function renderCards(cards){
if(!cards?.length) return;

container.innerHTML='';
cards.forEach(parsed=>{

const title = escapeHtml(parsed.title||'Без названия');
const desc  = escapeHtml(parsed.text||'');
const img   = parsed.img||'/forumimages/Newsletter-3.png';

const card=document.createElement('a');
card.className='custom-card';
card.href=parsed.href;
card.target='_self';

card.innerHTML=`
<div class="custom-card-header">
<div class="custom-card-header-text" style="--header-text-x: 0px; --header-text-y: 5px;">
Web Lab: UI & Scripts
</div>
</div>

<div class="custom-card-img">
<img src="${img}" alt="${title}">
<div class="custom-card-badge">Новое</div>
</div>

<div class="custom-card-title">${title}</div>
<div class="custom-card-desc">${desc}</div>
`;

container.appendChild(card);
});
}

/* ================= PARSE THREAD LIST ================= */

function parseThreadsList(doc){
const arr=[];
const items=doc.querySelectorAll('.threadNametd .threadLink');

for(let i=0;i<items.length&&arr.length<MAX_CARDS;i++){
const a=items[i];
const href=toAbsolute(a.getAttribute('href')||'');
const title=a.textContent.trim();
arr.push({href,title});
}
return arr;
}

/* ================= PARSE FIRST POST ================= */

function parseFirstPost(html){
const doc=new DOMParser().parseFromString(html,'text/html');

let text='',img='';

const post=doc.querySelector('.post_content,.post_body,.post,.ipsType_richText');
if(post){
text=post.textContent.trim().slice(0,89);
const im=post.querySelector('img');
if(im) img=toAbsolute(im.getAttribute('src')||'');
}

return {text,img};
}

/* ================= SHOW CACHE INSTANT ================= */

const cached=safeGet(CACHE_KEY);
if(cached?.cards) renderCards(cached.cards);

/* ================= NF LOGIC ================= */

try{

const html=await fetchHTML(FORUM_URL);
const doc=new DOMParser().parseFromString(html,'text/html');

const threads=parseThreadsList(doc);
if(!threads.length) return;

const firstTitle=threads[0].title.trim();
const savedTitle=localStorage.getItem(FIRST_TOPIC_KEY);

/* === SAME TOPIC → SLEEP === */
if(savedTitle && savedTitle===firstTitle) return;

/* === NEW TOPIC → UPDATE === */

localStorage.setItem(FIRST_TOPIC_KEY,firstTitle);
clearCache();

const cards=(await Promise.all(
threads.map(t=>
fetchHTML(t.href)
.then(h=>({...t,...parseFirstPost(h)}))
.catch(()=>t)
)
)).filter(Boolean);

safeSet(CACHE_KEY,{cards});
renderCards(cards);

}catch(e){
console.log('forum cards error',e);
}

})();
</script>

Мурчанн

Признаюсь, не знаю почему, но глядя на звезды мне всегда хочется мечтать.
  • Страница 1 из 1
  • 1
Поиск: