Added lite versions
This commit is contained in:
1 parent
4a18a18aae
commit
fff03bf0d4
3 files changed
+567
No files matched your search
@@ -0,0 +1,208 @@
|
||||
// ==UserScript==
|
||||
// @name CatWar Mod Lite
|
||||
// @name:ru Варомод Лайт
|
||||
// @namespace https://catwar.net/blog482084
|
||||
// @version 0.1
|
||||
// @description Облегчённый набор улучшений интерфейса CatWar без тяжёлых наблюдателей
|
||||
// @author ScriptTeam Lite
|
||||
// @license MIT; https://opensource.org/licenses/MIT
|
||||
// @match https://*.catwar.net/*
|
||||
// ==/UserScript==
|
||||
|
||||
(function (window, document) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Простые настройки, которые можно менять через консоль:
|
||||
* window.CWModLite.set('compactLayout', true)
|
||||
* window.CWModLite.set('quickLinks', ['about','top','sniff','settings'])
|
||||
*/
|
||||
|
||||
const STORAGE_KEY = 'cwmod-lite';
|
||||
const defaults = {
|
||||
compactLayout: false,
|
||||
quickLinks: ['index', 'top', 'sniff', 'settings']
|
||||
};
|
||||
|
||||
const linkMap = {
|
||||
index: { href: '/', title: 'Главная' },
|
||||
about: { href: '/about', title: 'Об игре' },
|
||||
top: { href: '/top', title: 'СИ' },
|
||||
sniff: { href: '/sniff', title: 'Лента' },
|
||||
blogs: { href: '/blogs', title: 'Блоги' },
|
||||
settings: { href: '/settings#cwmod', title: 'Настройки' },
|
||||
mobile: { href: '/mobile', title: 'Мобильная версия' }
|
||||
};
|
||||
|
||||
const state = Object.assign({}, defaults, loadSettings());
|
||||
const styles = {};
|
||||
|
||||
const isCW3 = /^https:\/\/\w*\.?catwar\.net\/cw3(?!\/(kns|jagd))/.test(window.location.href);
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
applyCommon();
|
||||
if (isCW3) {
|
||||
enhanceMenu();
|
||||
applyCompactLayout();
|
||||
injectToggle();
|
||||
}
|
||||
});
|
||||
|
||||
window.CWModLite = {
|
||||
get(key) {
|
||||
return state[key];
|
||||
},
|
||||
set(key, value) {
|
||||
state[key] = value;
|
||||
saveSettings(state);
|
||||
if (key === 'compactLayout') applyCompactLayout();
|
||||
if (key === 'quickLinks') enhanceMenu(true);
|
||||
return state[key];
|
||||
},
|
||||
reset() {
|
||||
Object.keys(defaults).forEach(function (key) {
|
||||
state[key] = defaults[key];
|
||||
});
|
||||
saveSettings(state);
|
||||
enhanceMenu(true);
|
||||
applyCompactLayout();
|
||||
}
|
||||
};
|
||||
|
||||
function applyCommon() {
|
||||
const footer = document.getElementById('footer');
|
||||
if (footer) {
|
||||
const text = footer.innerHTML;
|
||||
if (!/\/settings#cwmod/.test(text)) {
|
||||
footer.innerHTML = text.replace('<br>©', ' | <a href="/settings#cwmod">Настройки</a><br>©');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function enhanceMenu(forceRefresh) {
|
||||
const menu = document.querySelector('#app > span.small, .small');
|
||||
if (!menu) return;
|
||||
let placeholder = menu.querySelector('[data-cwmod-lite="links"]');
|
||||
if (placeholder && !forceRefresh) return;
|
||||
|
||||
const selectedLinks = Array.isArray(state.quickLinks) ? state.quickLinks : defaults.quickLinks;
|
||||
const fragment = document.createDocumentFragment();
|
||||
const wrapper = document.createElement('span');
|
||||
wrapper.dataset.cwmodLite = 'links';
|
||||
|
||||
selectedLinks.forEach(function (key, index) {
|
||||
const link = linkMap[key];
|
||||
if (!link) return;
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = link.href;
|
||||
anchor.textContent = link.title;
|
||||
anchor.rel = 'noopener';
|
||||
anchor.target = '_self';
|
||||
if (index > 0) wrapper.appendChild(document.createTextNode(' | '));
|
||||
wrapper.appendChild(anchor);
|
||||
});
|
||||
|
||||
if (placeholder) {
|
||||
placeholder.replaceWith(wrapper);
|
||||
} else {
|
||||
fragment.appendChild(document.createTextNode(' | '));
|
||||
fragment.appendChild(wrapper);
|
||||
menu.appendChild(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
function applyCompactLayout() {
|
||||
toggleStyle('compact', state.compactLayout, `
|
||||
body {
|
||||
background-color: #f7f7f7;
|
||||
}
|
||||
#app {
|
||||
max-width: 1040px;
|
||||
margin: 10px auto;
|
||||
padding: 0 10px;
|
||||
}
|
||||
#main_table {
|
||||
width: 100%;
|
||||
max-width: 1040px;
|
||||
border-collapse: collapse;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
#fightLog {
|
||||
max-height: 280px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.small {
|
||||
display: inline-flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
}
|
||||
`);
|
||||
}
|
||||
|
||||
function injectToggle() {
|
||||
const menu = document.querySelector('#app > span.small, .small');
|
||||
if (!menu || menu.querySelector('[data-cwmod-lite="toggle"]')) return;
|
||||
|
||||
const toggle = document.createElement('button');
|
||||
toggle.type = 'button';
|
||||
toggle.dataset.cwmodLite = 'toggle';
|
||||
toggle.textContent = state.compactLayout ? 'Лайт-режим вкл.' : 'Включить лайт-режим';
|
||||
toggle.style.marginLeft = '8px';
|
||||
toggle.style.padding = '2px 8px';
|
||||
toggle.style.fontSize = '12px';
|
||||
toggle.style.borderRadius = '6px';
|
||||
toggle.style.border = '1px solid rgba(0,0,0,0.1)';
|
||||
toggle.style.background = '#ffffffaa';
|
||||
toggle.style.cursor = 'pointer';
|
||||
|
||||
toggle.addEventListener('click', function () {
|
||||
state.compactLayout = !state.compactLayout;
|
||||
saveSettings(state);
|
||||
applyCompactLayout();
|
||||
toggle.textContent = state.compactLayout ? 'Лайт-режим вкл.' : 'Включить лайт-режим';
|
||||
});
|
||||
|
||||
menu.appendChild(document.createTextNode(' | '));
|
||||
menu.appendChild(toggle);
|
||||
}
|
||||
|
||||
function toggleStyle(key, shouldEnable, cssText) {
|
||||
if (!shouldEnable) {
|
||||
if (styles[key] && styles[key].parentNode) {
|
||||
styles[key].parentNode.removeChild(styles[key]);
|
||||
}
|
||||
styles[key] = null;
|
||||
return;
|
||||
}
|
||||
if (styles[key]) return;
|
||||
const style = document.createElement('style');
|
||||
style.dataset.cwmodLiteStyle = key;
|
||||
style.textContent = cssText;
|
||||
document.head.appendChild(style);
|
||||
styles[key] = style;
|
||||
}
|
||||
|
||||
function loadSettings() {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return {};
|
||||
const data = JSON.parse(raw);
|
||||
return (data && typeof data === 'object') ? data : {};
|
||||
} catch (err) {
|
||||
console.warn('[CWModLite] Не удалось загрузить настройки', err);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function saveSettings(settings) {
|
||||
try {
|
||||
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
|
||||
} catch (err) {
|
||||
console.warn('[CWModLite] Не удалось сохранить настройки', err);
|
||||
}
|
||||
}
|
||||
})(window, document);
|
||||
|
||||
+357
@@ -0,0 +1,357 @@
|
||||
// ==UserScript==
|
||||
// @name CW: Shed Lite
|
||||
// @version 0.3
|
||||
// @description Облегчённая версия CW:Shed — базовые уведомления без тяжёлых наблюдателей
|
||||
// @author Tis & Lite maintainers
|
||||
// @license MIT; https://opensource.org/licenses/MIT
|
||||
// @match *://catwar.net/*
|
||||
// @match *://catwar.su/*
|
||||
// ==/UserScript==
|
||||
|
||||
(function (window, document) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Настройки можно менять из консоли:
|
||||
* window.CWShedLite.set('smellTimer', false)
|
||||
* window.CWShedLite.set('actionAlertThreshold', 2)
|
||||
*/
|
||||
|
||||
const STORAGE_KEY = 'cwshed-lite';
|
||||
const SMELL_STORAGE_KEY = 'cwshed-lite-smell-end';
|
||||
|
||||
const defaults = {
|
||||
smellTimer: true,
|
||||
smellTimerSound: 'https://cat.nyan404.ru/data/action_end.mp3',
|
||||
smellTimerVolume: 0.25,
|
||||
actionAlert: true,
|
||||
actionAlertTitle: true,
|
||||
actionAlertThreshold: 1,
|
||||
actionAlertSound: 'https://cat.nyan404.ru/data/action_end.mp3',
|
||||
actionAlertVolume: 0.2,
|
||||
showDmId: true
|
||||
};
|
||||
|
||||
const smellDurations = {
|
||||
'0': 3600,
|
||||
'1': 3600,
|
||||
'2': 3600,
|
||||
'3': 3600,
|
||||
'4': 1800,
|
||||
'5': 1200,
|
||||
'6': 900,
|
||||
'7': 720,
|
||||
'8': 600,
|
||||
'9': 0
|
||||
};
|
||||
|
||||
const settings = Object.assign({}, defaults, loadSettings());
|
||||
let smellTimerHandle = null;
|
||||
let smellClickHandler = null;
|
||||
let actionIntervalHandle = null;
|
||||
let storedTitle = document.title;
|
||||
let lastActionAlert = 0;
|
||||
let actionListenersAttached = false;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', init, { once: true });
|
||||
|
||||
window.CWShedLite = {
|
||||
get(key) {
|
||||
return settings[key];
|
||||
},
|
||||
set(key, value) {
|
||||
settings[key] = value;
|
||||
saveSettings(settings);
|
||||
if (key.startsWith('smellTimer')) restartSmellTimer();
|
||||
if (key.startsWith('actionAlert')) restartActionWatcher();
|
||||
if (key === 'showDmId') injectDmId(true);
|
||||
return settings[key];
|
||||
},
|
||||
reset() {
|
||||
Object.keys(defaults).forEach(function (key) {
|
||||
settings[key] = defaults[key];
|
||||
});
|
||||
saveSettings(settings);
|
||||
restartSmellTimer();
|
||||
restartActionWatcher();
|
||||
injectDmId(true);
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
if (isGamePage()) {
|
||||
if (settings.smellTimer) setupSmellTimer();
|
||||
if (settings.actionAlert || settings.actionAlertTitle) setupActionWatcher();
|
||||
}
|
||||
if (isDmPage() && settings.showDmId) {
|
||||
injectDmId();
|
||||
}
|
||||
}
|
||||
|
||||
function isGamePage() {
|
||||
return /^\/cw3(\/(kns|jagd))?/.test(window.location.pathname);
|
||||
}
|
||||
|
||||
function isDmPage() {
|
||||
return /^\/ls/.test(window.location.pathname);
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------
|
||||
* Вспомогательные утилиты
|
||||
* ---------------------
|
||||
*/
|
||||
function loadSettings() {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return {};
|
||||
const data = JSON.parse(raw);
|
||||
return (data && typeof data === 'object') ? data : {};
|
||||
} catch (err) {
|
||||
console.warn('[CWShedLite] Настройки не загружены', err);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function saveSettings(value) {
|
||||
try {
|
||||
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(value));
|
||||
} catch (err) {
|
||||
console.warn('[CWShedLite] Настройки не сохранены', err);
|
||||
}
|
||||
}
|
||||
|
||||
function createAudio(src, volume) {
|
||||
const audio = new Audio();
|
||||
audio.preload = 'none';
|
||||
audio.src = src;
|
||||
audio.volume = volume;
|
||||
return audio;
|
||||
}
|
||||
|
||||
function parseSeconds(text) {
|
||||
if (!text) return NaN;
|
||||
const clean = text.replace(/\u00A0/g, ' ');
|
||||
const hourMatch = clean.match(/(\d+)\s*ч/);
|
||||
const minMatch = clean.match(/(\d+)\s*мин/);
|
||||
const secMatch = clean.match(/(\d+)\s*с/);
|
||||
let total = 0;
|
||||
if (hourMatch) total += parseInt(hourMatch[1], 10) * 3600;
|
||||
if (minMatch) total += parseInt(minMatch[1], 10) * 60;
|
||||
if (secMatch) total += parseInt(secMatch[1], 10);
|
||||
return total || NaN;
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------
|
||||
* Смелл-таймер
|
||||
* ---------------------
|
||||
*/
|
||||
function setupSmellTimer() {
|
||||
const menu = document.querySelector('#app > span.small, .small');
|
||||
if (!menu || menu.querySelector('#cwshed-lite-smell')) return;
|
||||
|
||||
const label = document.createElement('span');
|
||||
label.id = 'cwshed-lite-smell';
|
||||
label.style.marginLeft = '8px';
|
||||
label.textContent = 'Нюх: —';
|
||||
|
||||
menu.appendChild(document.createTextNode(' | '));
|
||||
menu.appendChild(label);
|
||||
|
||||
if (smellClickHandler) {
|
||||
document.removeEventListener('click', smellClickHandler, true);
|
||||
}
|
||||
|
||||
smellClickHandler = function (event) {
|
||||
const actionLink = event.target.closest('#dein a[data-id="14"], #actions a[data-id="14"]');
|
||||
if (!actionLink) return;
|
||||
const levelNode = document.querySelector('#smell b');
|
||||
const level = levelNode ? levelNode.textContent.trim() : '';
|
||||
const seconds = smellDurations[level] || smellDurations['0'];
|
||||
if (!seconds) {
|
||||
clearSmellTimer();
|
||||
return;
|
||||
}
|
||||
startSmellTimer(seconds);
|
||||
};
|
||||
|
||||
document.addEventListener('click', smellClickHandler, true);
|
||||
|
||||
const savedEnd = Number(window.localStorage.getItem(SMELL_STORAGE_KEY) || 0);
|
||||
if (savedEnd > Date.now()) {
|
||||
startSmellTimer(Math.floor((savedEnd - Date.now()) / 1000));
|
||||
} else {
|
||||
window.localStorage.removeItem(SMELL_STORAGE_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
function startSmellTimer(seconds) {
|
||||
const label = document.getElementById('cwshed-lite-smell');
|
||||
if (!label) return;
|
||||
const endTime = Date.now() + seconds * 1000;
|
||||
window.localStorage.setItem(SMELL_STORAGE_KEY, String(endTime));
|
||||
if (smellTimerHandle) window.clearInterval(smellTimerHandle);
|
||||
|
||||
const audio = settings.smellTimerSound ? createAudio(settings.smellTimerSound, settings.smellTimerVolume) : null;
|
||||
|
||||
const tick = function () {
|
||||
const remaining = Math.max(0, Math.floor((endTime - Date.now()) / 1000));
|
||||
if (remaining <= 0) {
|
||||
label.textContent = 'Нюх: готово';
|
||||
window.localStorage.removeItem(SMELL_STORAGE_KEY);
|
||||
window.clearInterval(smellTimerHandle);
|
||||
smellTimerHandle = null;
|
||||
if (audio) {
|
||||
audio.currentTime = 0;
|
||||
void audio.play();
|
||||
}
|
||||
return;
|
||||
}
|
||||
label.textContent = 'Нюх: ' + formatTime(remaining);
|
||||
};
|
||||
|
||||
tick();
|
||||
smellTimerHandle = window.setInterval(tick, 1000);
|
||||
}
|
||||
|
||||
function clearSmellTimer() {
|
||||
if (smellTimerHandle) {
|
||||
window.clearInterval(smellTimerHandle);
|
||||
smellTimerHandle = null;
|
||||
}
|
||||
if (smellClickHandler) {
|
||||
document.removeEventListener('click', smellClickHandler, true);
|
||||
smellClickHandler = null;
|
||||
}
|
||||
window.localStorage.removeItem(SMELL_STORAGE_KEY);
|
||||
const label = document.getElementById('cwshed-lite-smell');
|
||||
if (label) label.textContent = 'Нюх: —';
|
||||
}
|
||||
|
||||
function restartSmellTimer() {
|
||||
clearSmellTimer();
|
||||
if (settings.smellTimer && isGamePage()) {
|
||||
setupSmellTimer();
|
||||
}
|
||||
}
|
||||
|
||||
function formatTime(totalSeconds) {
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
const segments = [];
|
||||
if (hours) segments.push(hours + ' ч');
|
||||
if (minutes) segments.push(minutes + ' мин');
|
||||
segments.push(seconds + ' с');
|
||||
return segments.join(' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------
|
||||
* Уведомление о конце действия
|
||||
* ---------------------
|
||||
*/
|
||||
function setupActionWatcher() {
|
||||
if (actionIntervalHandle) window.clearInterval(actionIntervalHandle);
|
||||
const audio = (settings.actionAlert && settings.actionAlertSound)
|
||||
? createAudio(settings.actionAlertSound, settings.actionAlertVolume)
|
||||
: null;
|
||||
|
||||
if (!actionListenersAttached) {
|
||||
window.addEventListener('focus', restoreTitle);
|
||||
window.addEventListener('blur', function () {
|
||||
storedTitle = storedTitle || document.title;
|
||||
});
|
||||
actionListenersAttached = true;
|
||||
}
|
||||
|
||||
actionIntervalHandle = window.setInterval(function () {
|
||||
const timerNode = document.querySelector('#sek');
|
||||
if (!timerNode) {
|
||||
restoreTitle();
|
||||
lastActionAlert = 0;
|
||||
return;
|
||||
}
|
||||
const secondsLeft = parseSeconds(timerNode.textContent);
|
||||
if (Number.isNaN(secondsLeft)) return;
|
||||
|
||||
if (settings.actionAlertTitle) {
|
||||
if (secondsLeft > 0) {
|
||||
document.title = '(' + secondsLeft + ' с) CatWar';
|
||||
} else {
|
||||
restoreTitle();
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.actionAlert && secondsLeft <= settings.actionAlertThreshold && secondsLeft >= 0) {
|
||||
const now = Date.now();
|
||||
if (now - lastActionAlert > 1500) {
|
||||
lastActionAlert = now;
|
||||
if (audio) {
|
||||
audio.currentTime = 0;
|
||||
void audio.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function restoreTitle() {
|
||||
if (storedTitle) {
|
||||
document.title = storedTitle;
|
||||
}
|
||||
}
|
||||
|
||||
function restartActionWatcher() {
|
||||
if (!isGamePage()) return;
|
||||
if (actionIntervalHandle) {
|
||||
window.clearInterval(actionIntervalHandle);
|
||||
actionIntervalHandle = null;
|
||||
}
|
||||
if (settings.actionAlert || settings.actionAlertTitle) {
|
||||
setupActionWatcher();
|
||||
} else {
|
||||
restoreTitle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ---------------------
|
||||
* ID собеседника в ЛС
|
||||
* ---------------------
|
||||
*/
|
||||
function injectDmId(force) {
|
||||
const container = document.getElementById('main');
|
||||
if (!container) return;
|
||||
|
||||
const applyId = function () {
|
||||
if (!settings.showDmId && !force) return;
|
||||
const login = document.getElementById('msg_login');
|
||||
if (!login) return;
|
||||
const href = login.getAttribute('href') || '';
|
||||
const match = href.match(/(\d+)/);
|
||||
if (!match) return;
|
||||
let badge = document.getElementById('cwshed-lite-dm-id');
|
||||
if (!settings.showDmId) {
|
||||
if (badge && badge.parentNode) badge.parentNode.removeChild(badge);
|
||||
return;
|
||||
}
|
||||
if (!badge) {
|
||||
badge = document.createElement('span');
|
||||
badge.id = 'cwshed-lite-dm-id';
|
||||
badge.style.marginLeft = '6px';
|
||||
badge.style.fontSize = '12px';
|
||||
badge.style.color = '#555';
|
||||
login.insertAdjacentElement('afterend', badge);
|
||||
}
|
||||
badge.textContent = '[' + match[1] + ']';
|
||||
};
|
||||
|
||||
applyId();
|
||||
const observer = new MutationObserver(function () {
|
||||
applyId();
|
||||
});
|
||||
observer.observe(container, { childList: true, subtree: true });
|
||||
}
|
||||
})(window, document);
|
||||
@@ -75,6 +75,8 @@
|
||||
<ul style="list-style: none; padding: 0;">
|
||||
<li><i class="fas fa-toolbox emoji"></i><a href="https://cat.nyan404.ru/cw.js" target="_blank">CW:SHED</a></li>
|
||||
<li><i class="fas fa-cube emoji"></i><a href="https://cat.nyan404.ru/CatWarMod.js" target="_blank">CatWarMod</a></li>
|
||||
<li><i class="fas fa-feather emoji"></i><a href="https://cat.nyan404.ru/cw-lite.js" target="_blank">ПОЖАЛУЙСТА НЕ ИСПОЛЬЗУЙТЕ ТЕСТОВОЕ CW:SHED Lite ПОЖАЛУЙСТА НЕ ИСПОЛЬЗУЙТЕ</a></li>
|
||||
<li><i class="fas fa-leaf emoji"></i><a href="https://cat.nyan404.ru/CatWarModLite.js" target="_blank">ПОЖАЛУЙСТА НЕ ИСПОЛЬЗУЙТЕ ТЕСТОВОЕ CatWarMod Lite ПОЖАЛУЙСТА НЕ ИСПОЛЬЗУЙТЕ</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user