// ==UserScript== // @name Kwork Helper // @namespace http://tampermonkey.net/ // @version 2.1.2 // @description Optimization of Kwork: stats, competition, sniper mode, author blacklist, fav tags, infinite scroll, and AI pitch generator. // @author Herman Guilliman // @updateURL https://raw.githubusercontent.com/hermanguilliman/kwork-helper/main/kwork-helper.user.js // @downloadURL https://raw.githubusercontent.com/hermanguilliman/kwork-helper/main/kwork-helper.user.js // @match https://kwork.ru/projects* // @icon https://www.google.com/s2/favicons?sz=64&domain=kwork.ru // @grant GM_notification // @grant GM_xmlhttpRequest // @connect * // @copyright 2026, Herman Guilliman (hermanguilliman@proton.me) // ==/UserScript== (function () { "use strict"; const DEFAULTS = { goodPrice: 3000, badPrice: 500, goodHireRate: 40, badHireRate: 20, goodOffersMax: 3, badOffersMin: 15, refreshTime: 60, aiBaseUrl: "https://api.openai.com/v1", aiApiKey: "", aiModel: "gpt-4o-mini", aiMaxTokens: 700, aiPrompt: "Ты опытный фрилансер на Kwork (лимит откликов — 30 в месяц, нужно беречь каждый). Проанализируй заказ с учетом бюджета, статистики покупателя и числа конкурентов.\nОтветь кратко по пунктам:\n1. Вердикт: [ОТКЛИКАТЬСЯ / ОСТОРОЖНО / ПРОПУСТИТЬ] и почему (адекватность цены за объем, надежность клиента, конкуренция).\n2. Подводные камни: что обязательно уточнить.\n3. Если вердикт не ПРОПУСТИТЬ — напиши короткий цепляющий отклик (2-4 предложения по делу, без воды, с вопросом по задаче) строго внутри тегов текст отклика.", goodWords: [], stopAuthors: [], stopWords: [ "за отзыв", "ради отзыва", "для отзыва", "за процент", "на процент", "% от продаж", "бюджет 0", "бесплатно", "бартер", "нет бюджета", ], urgentWords: [ "срочно", "asap", "сегодня", "сейчас", "вчера", "быстро", "горит", ], }; function escapeHtml(value) { return String(value) .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } function playNotificationSound() { try { const Ctx = window.AudioContext || window.webkitAudioContext; if (!Ctx) return; const ctx = new Ctx(); const now = ctx.currentTime; const osc = ctx.createOscillator(); const gain = ctx.createGain(); osc.type = "sine"; osc.frequency.setValueAtTime(587.33, now); // D5 osc.frequency.setValueAtTime(880, now + 0.12); // A5 gain.gain.setValueAtTime(0.08, now); gain.gain.exponentialRampToValueAtTime(0.001, now + 0.45); osc.connect(gain); gain.connect(ctx.destination); osc.start(now); osc.stop(now + 0.45); } catch (e) { // Игнорируем блокировку автовоспроизведения браузером } } const CORE_SELECTORS = { ".want-card": "карточки заказов", ".wants-card__header-title": "заголовок карточки", ".wants-card__price": "блок цены", ".wants-card__description-text": "описание заказа", ".want-payer-statistic": "статистика заказчика", }; const seenSelectors = new Set(); const reportedDomBreaks = new Set(); const reportedSafeErrors = new Set(); function safe(label, fn) { try { fn(); } catch (err) { const key = label + ": " + (err && err.message ? err.message : err); if (!reportedSafeErrors.has(key)) { reportedSafeErrors.add(key); console.error(`[Kwork Helper] Сбой шага «${label}»:`, err); } } } function checkDomHealth() { if (!document.querySelector(".want-card")) return; for (const sel of Object.keys(CORE_SELECTORS)) { if (sel === ".want-card") continue; if (document.querySelector(sel)) { seenSelectors.add(sel); } else if (seenSelectors.has(sel) && !reportedDomBreaks.has(sel)) { reportedDomBreaks.add(sel); console.warn( `[Kwork Helper] Селектор «${sel}» (${CORE_SELECTORS[sel]}) больше не найден — похоже, Kwork изменил вёрстку.`, ); } } } const CSS = ` /* CORE PANEL & UI */ #kw_panel { position: fixed; top: 40%; left: 0; z-index: 999990; font-family: 'Roboto', sans-serif; display: flex; flex-direction: row; align-items: flex-start; pointer-events: none; transform: translateY(-50%); } .kw-fab { width: 24px; height: 40px; border-radius: 0 8px 8px 0; background: #87B448; box-shadow: 2px 2px 8px rgba(0,0,0,0.15); cursor: pointer; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 11px; user-select: none; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); pointer-events: auto; position: relative; opacity: 0.6; transform: translateX(-2px); } .kw-fab:hover, #kw_panel.open .kw-fab { width: 45px; opacity: 1; transform: translateX(0); background: linear-gradient(135deg, #87B448 0%, #609438 100%); font-size: 13px; } .kw-menu { background: #fff; width: 250px; border-radius: 8px; box-shadow: 4px 4px 20px rgba(0,0,0,0.15); margin-left: 10px; border: 1px solid #eee; overflow: hidden; opacity: 0; transform: translateX(-20px) scale(0.95); transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1); pointer-events: none; visibility: hidden; } #kw_panel.open .kw-menu { opacity: 1; transform: translateX(0) scale(1); pointer-events: auto; visibility: visible; } .kw-head { padding: 12px 15px; background: #f8f9fa; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; } .kw-title { font-weight: 700; font-size: 13px; color: #333; } .kw-btn-icon { cursor: pointer; color: #888; font-size: 16px; transition: color 0.2s; } .kw-btn-icon:hover { color: #333; } .kw-body { padding: 15px; } .kw-opt-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: #555; margin-bottom: 12px; } /* SWITCHES & SLIDERS */ .kw-switch { position: relative; width: 36px; height: 20px; flex-shrink: 0; } .kw-switch input { opacity: 0; width: 0; height: 0; } .kw-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #e0e0e0; transition: .3s; border-radius: 34px; } .kw-slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2); } input:checked + .kw-slider { background-color: #87B448; } input:checked + .kw-slider:before { transform: translateX(16px); } .kw-timer-status { font-size: 11px; color: #87B448; text-align: center; margin-top: 10px; font-weight: 600; background: #f0f7e6; padding: 4px; border-radius: 4px; } /* BADGES & STRIPS */ .kw-badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 6px; font-size: 12px; font-weight: 700; margin: 0 4px; vertical-align: middle; } .kw-badge-good { background: #e6f9ed; color: #27ae60; border: 1px solid #c3e6cb; } .kw-badge-bad { background: #fdeaea; color: #e74c3c; border: 1px solid #f5c6cb; } .kw-badge-mid { background: #fff8e1; color: #f39c12; border: 1px solid #ffeeba; } .kw-badge-neutral { background: #f8f9fa; color: #6c757d; border: 1px solid #dee2e6; } .kw-badge-fav { background: linear-gradient(135deg, #fff9db 0%, #fff3bf 100%); color: #b47d00; border: 1px solid #ffd43b; box-shadow: 0 1px 3px rgba(255, 212, 59, 0.3); } .kw-badge-new { background: #e7f5ff; color: #1971c2; border: 1px solid #a5d8ff; font-size: 11px; padding: 1px 7px; margin-right: 6px; } .kw-badge-spam { background: #f2f2f2; color: #999; border: 1px solid #e0e0e0; margin-bottom: 5px; display:inline-block; font-size: 10px; border-radius: 12px; text-transform: uppercase; padding: 2px 8px; } .kw-strip-good { border-left: 3px solid #58cf7e !important; background: linear-gradient(90deg, rgba(88, 207, 126, 0.04) 0%, #fff 15%) !important; } .kw-strip-bad { border-left: 3px solid #ff6b6b !important; background: linear-gradient(90deg, rgba(255, 107, 107, 0.04) 0%, #fff 15%) !important; } .kw-strip-fav { box-shadow: 0 0 0 1px #ffd43b, 0 4px 12px rgba(255, 212, 59, 0.15) !important; } .kw-spam-card { opacity: 0.4; filter: grayscale(100%); transition: all 0.3s; } .kw-spam-card:hover { opacity: 0.9; filter: grayscale(0%); } .kw-hidden { display: none !important; } /* ICONS & UTILS */ .kw-urgent-fire { font-size: 14px; margin-right: 5px; animation: pulse 1.5s infinite; cursor: help; } .kw-block-user-btn { cursor: pointer; border: none; background: none; font-size: 12px; padding: 0 4px; margin-left: 4px; opacity: 0.35; transition: opacity 0.2s, transform 0.2s; vertical-align: middle; } .kw-block-user-btn:hover { opacity: 1; transform: scale(1.2); } /* MODAL SETTINGS */ .kw-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 999995; display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: 0.2s; } .kw-overlay.open { opacity: 1; visibility: visible; } .kw-modal { background: #fff; width: 540px; max-height: 90vh; overflow-y: auto; border-radius: 12px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); transform: translateY(20px); transition: 0.3s; } .kw-overlay.open .kw-modal { transform: translateY(0); } .kw-modal-title { font-size: 18px; font-weight: bold; margin-bottom: 16px; color: #333; display:flex; justify-content:space-between; border-bottom: 1px solid #eee; padding-bottom: 10px;} .kw-modal-close { cursor: pointer; color: #999; } .kw-section-head { display: flex; justify-content: space-between; align-items: center; margin: 15px 0 8px; } .kw-section-title { font-size: 13px; font-weight: 700; color: #444; margin: 15px 0 8px; display: block; } .kw-section-head .kw-section-title { margin: 0; } .kw-link-btn { background: none; border: none; color: #3498db; font-size: 11px; cursor: pointer; padding: 0; text-decoration: underline; } .kw-link-btn:hover { color: #1d6fa5; } .kw-input-group { display: flex; gap: 10px; margin-bottom: 8px; } .kw-input { flex: 1; padding: 8px 12px; border: 1px solid #ddd; border-radius: 8px; outline: none; transition: 0.2s; font-size: 13px; width: 100%; box-sizing: border-box; } .kw-input:focus { border-color: #87B448; } .kw-textarea { width: 100%; height: 95px; resize: vertical; font-family: sans-serif; } .kw-btn { background: #87B448; color: #fff; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-weight: 600; transition: 0.2s; font-size: 13px; } .kw-btn:hover { background: #609438; } .kw-btn-save { width: 100%; margin-top: 20px; padding: 12px; font-size: 14px; } .kw-tags { display: flex; flex-wrap: wrap; gap: 6px; max-height: 85px; overflow-y: auto; padding: 8px; background: #f9f9f9; border-radius: 8px; border: 1px solid #eee; min-height: 36px; } .kw-tag { background: #fff; border: 1px solid #ddd; padding: 4px 10px; border-radius: 20px; font-size: 12px; color: #555; display: flex; align-items: center; gap: 6px; } .kw-tag-fav { background: #fff9db; border-color: #ffd43b; color: #8c6200; } .kw-tag-rm { cursor: pointer; color: #ff4757; font-weight: bold; } /* AI & PITCH BOX */ .kw-ai-btn { cursor: pointer; margin-left: 8px; font-size: 16px; background: none; border: none; padding: 0; transition: transform 0.2s; filter: grayscale(100%); opacity: 0.6; vertical-align: middle; } .kw-ai-btn:hover { transform: scale(1.2); filter: grayscale(0%); opacity: 1; } .kw-ai-btn.loading { animation: kw-ai-pulse 1.2s ease-in-out infinite; pointer-events: none; } .kw-ai-response-box { margin-top: 12px; padding: 12px; border-radius: 8px; background: #f4f8fb; border: 1px solid #dcebf7; color: #2c3e50; font-size: 13px; line-height: 1.5; white-space: pre-wrap; position: relative; } .kw-ai-response-box::before { content: "🤖 Анализ нейросети:"; display: block; font-weight: bold; color: #3498db; margin-bottom: 6px; } .kw-ai-pitch-box { margin-top: 10px; padding: 10px 12px; border-radius: 6px; background: #fff; border: 1px dashed #87B448; color: #222; } .kw-ai-pitch-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 12px; color: #609438; margin-bottom: 6px; } .kw-copy-pitch-btn { background: #e6f9ed; color: #27ae60; border: 1px solid #c3e6cb; border-radius: 6px; padding: 3px 10px; font-size: 11px; font-weight: 600; cursor: pointer; transition: 0.2s; } .kw-copy-pitch-btn:hover { background: #27ae60; color: #fff; } .kw-ai-error { background: #fff5f5; border-color: #ffcccc; color: #c0392b; } .kw-ai-error::before { content: "❌ Ошибка:"; color: #c0392b; } /* LOADERS & ANIMATIONS */ .kw-pulse-ring::after { content: ''; position: absolute; top: -3px; left: 0; right: -3px; bottom: -3px; border-radius: 0 8px 8px 0; border: 2px solid #87B448; animation: pulse-ring 2s infinite; pointer-events: none; } .kw-loader { text-align: center; padding: 20px; font-size: 14px; color: #888; font-weight: bold; display: none; width: 100%; clear: both; background: #fafafa; border: 1px dashed #ccc; margin-top: 20px; } .kw-loader.active { display: block; } @keyframes pulse-ring { 0% { transform: scale(1); opacity: 1; } 100% { transform: scaleX(1.1) scaleY(1.3); opacity: 0; } } @keyframes pulse { 0% { transform: scale(0.95); opacity: 0.7; } 50% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(0.95); opacity: 0.7; } } @keyframes kw-ai-pulse { 0%, 100% { transform: scale(1); filter: blur(0); opacity: 0.65; } 50% { transform: scale(1.4); filter: blur(2.5px); opacity: 1; } } `; class ConfigManager { constructor() { this.keys = { stopWords: "kw_stop_words", goodWords: "kw_good_words", stopAuthors: "kw_stop_authors", autoRefresh: "kw_autorefresh", sniperMode: "kw_sniper_mode", hideSpam: "kw_hide_spam", infiniteScroll: "kw_infinite_scroll", aiBaseUrl: "kw_ai_base_url", aiApiKey: "kw_ai_api_key", aiModel: "kw_ai_model", aiMaxTokens: "kw_ai_max_tokens", aiPrompt: "kw_ai_prompt", }; } get(key) { return localStorage.getItem(key) === "true"; } set(key, val) { localStorage.setItem(key, val); } getString(key, defaultVal) { return localStorage.getItem(key) || defaultVal; } setString(key, val) { localStorage.setItem(key, val); } getList(key, defaultList) { try { const raw = localStorage.getItem(key); return raw ? JSON.parse(raw) : defaultList; } catch (e) { return defaultList; } } setList(key, list) { localStorage.setItem(key, JSON.stringify(list)); } getStopWords() { return this.getList(this.keys.stopWords, DEFAULTS.stopWords); } setStopWords(words) { this.setList(this.keys.stopWords, words); } getGoodWords() { return this.getList(this.keys.goodWords, DEFAULTS.goodWords); } setGoodWords(words) { this.setList(this.keys.goodWords, words); } getStopAuthors() { return this.getList(this.keys.stopAuthors, DEFAULTS.stopAuthors); } setStopAuthors(authors) { this.setList(this.keys.stopAuthors, authors); } getAiConfig() { return { baseUrl: this.getString( this.keys.aiBaseUrl, DEFAULTS.aiBaseUrl, ), apiKey: this.getString(this.keys.aiApiKey, DEFAULTS.aiApiKey), model: this.getString(this.keys.aiModel, DEFAULTS.aiModel), maxTokens: parseInt( this.getString(this.keys.aiMaxTokens, DEFAULTS.aiMaxTokens), 10, ), prompt: this.getString(this.keys.aiPrompt, DEFAULTS.aiPrompt), }; } setAiConfig(cfg) { this.setString(this.keys.aiBaseUrl, cfg.baseUrl); this.setString(this.keys.aiApiKey, cfg.apiKey); this.setString(this.keys.aiModel, cfg.model); this.setString(this.keys.aiMaxTokens, cfg.maxTokens); this.setString(this.keys.aiPrompt, cfg.prompt); } } class AiClient { constructor(configManager) { this.config = configManager; } analyze(jobText) { return new Promise((resolve, reject) => { const cfg = this.config.getAiConfig(); if (!cfg.apiKey) { reject(new Error("Не задан API Key в настройках!")); return; } const messages = [ { role: "system", content: cfg.prompt }, { role: "user", content: `ДЕТАЛИ ЗАКАЗА:\n${jobText}` }, ]; const payload = { model: cfg.model, messages: messages, max_tokens: cfg.maxTokens, temperature: 0.7, }; GM_xmlhttpRequest({ method: "POST", url: cfg.baseUrl + (cfg.baseUrl.endsWith("/") ? "" : "/") + "chat/completions", headers: { "Content-Type": "application/json", Authorization: `Bearer ${cfg.apiKey}`, }, data: JSON.stringify(payload), timeout: 30000, onload: (response) => { try { let data; try { data = JSON.parse(response.responseText); } catch (e) { if (response.status !== 200) { throw new Error( `HTTP ${response.status} (Not JSON)`, ); } throw new Error("Некорректный JSON ответ"); } if (response.status !== 200) { let errorMsg = `Ошибка API (${response.status})`; if (data.error && data.error.message) { errorMsg = `API: ${data.error.message}`; } else if (data.message) { errorMsg = `API: ${data.message}`; } if (response.status === 401) errorMsg = "Ошибка 401: Неверный API Key"; if (response.status === 429) errorMsg = "Ошибка 429: Лимит запросов исчерпан"; if (response.status >= 500) errorMsg = `Ошибка ${response.status}: Проблема на сервере ИИ`; throw new Error(errorMsg); } const content = data.choices?.[0]?.message?.content || "Пустой ответ от нейросети."; resolve(content); } catch (e) { reject(e); } }, onerror: () => { reject(new Error("Ошибка сети / Connection Error")); }, ontimeout: () => { reject(new Error("Таймаут соединения (30с)")); }, }); }); } } class InfiniteScrollManager { constructor(app) { this.app = app; this.isEnabled = this.app.config.get( this.app.config.keys.infiniteScroll, ); this.isLoading = false; this.isFinished = false; this.page = 1; this.loader = null; this.container = null; this.iframe = null; setTimeout(() => this.init(), 1000); } init() { const params = new URLSearchParams(window.location.search); this.page = parseInt(params.get("page"), 10) || 1; this.loader = document.createElement("div"); this.loader.className = "kw-loader"; this.loader.innerHTML = "⏳ Загрузка заказов..."; this.container = document.querySelector(".project-list") || document.querySelector(".wants-content"); if (this.container) { const innerList = this.container.querySelector(".project-list"); if (innerList) this.container = innerList; if (this.container.parentNode) this.container.parentNode.insertBefore( this.loader, this.container.nextSibling, ); } window.addEventListener( "scroll", () => { if (this.isEnabled) this.onScroll(); }, { passive: true }, ); this.updateState(); } toggle(state) { this.isEnabled = state; this.updateState(); } updateState() { const pags = document.querySelectorAll(".pagination, .paging"); pags.forEach((el) => { el.style.display = this.isEnabled ? "none" : ""; }); if (this.loader) this.loader.style.display = "none"; } onScroll() { if (this.isLoading || this.isFinished) return; const scrollHeight = document.documentElement.scrollHeight; const scrollTop = window.scrollY || document.documentElement.scrollTop; const clientHeight = document.documentElement.clientHeight; if (scrollTop + clientHeight >= scrollHeight - 600) this.loadNextPage(); } loadNextPage() { this.isLoading = true; this.loader.classList.add("active"); this.loader.style.display = "block"; this.page++; const url = new URL(window.location.href); url.searchParams.set("page", this.page); if (this.iframe) this.iframe.remove(); this.iframe = document.createElement("iframe"); this.iframe.style.display = "none"; this.iframe.src = url.toString(); document.body.appendChild(this.iframe); this.iframe.onload = () => { this.onIframeLoad(); }; setTimeout(() => { if (this.isLoading) { this.isLoading = false; this.loader.classList.remove("active"); } }, 10000); } getCardSignature(card) { if (!card) return ""; const id = card.getAttribute("data-id"); if (id) return "ID:" + id; const link = card.querySelector(".wants-card__header-title a"); if (link && link.href) { const m = link.href.match(/\/projects\/(\d+)/); if (m) return "ID:" + m[1]; } const title = card.querySelector(".wants-card__header-title"); const price = card.querySelector(".wants-card__price"); return ( (title ? title.textContent.trim() : "") + "|" + (price ? price.textContent.trim() : "") ); } onIframeLoad() { try { const doc = this.iframe.contentDocument || this.iframe.contentWindow.document; setTimeout(() => { const newCards = doc.querySelectorAll(".want-card"); if (newCards.length === 0) { this.finishFeed(); return; } if (this.container) { const currentCards = this.container.querySelectorAll(".want-card"); if (currentCards.length > 0 && newCards.length > 0) { const lastCurrent = currentCards[currentCards.length - 1]; const lastNew = newCards[newCards.length - 1]; if ( this.getCardSignature(lastCurrent) === this.getCardSignature(lastNew) ) { this.finishFeed(); return; } } newCards.forEach((card) => { const importedCard = document.adoptNode(card); importedCard.removeAttribute("data-kw-state"); importedCard.removeAttribute("data-kw-stats"); importedCard.removeAttribute("data-kw-comp"); importedCard.setAttribute( "data-kw-from-scroll", "1", ); const oldAi = importedCard.querySelector(".kw-ai-btn"); if (oldAi) oldAi.remove(); this.container.appendChild(importedCard); }); this.app.processor.processBatch( document.querySelectorAll(".want-card"), ); this.loader.innerHTML = "⏳ Загрузка заказов..."; } this.iframe.remove(); this.iframe = null; this.isLoading = false; this.loader.classList.remove("active"); this.loader.style.display = "none"; }, 1500); } catch (err) { console.error(err); this.isLoading = false; this.loader.classList.remove("active"); } } finishFeed() { this.loader.innerHTML = "🏁 Заказов больше нет"; this.loader.classList.add("active"); this.loader.style.display = "block"; this.isFinished = true; this.isLoading = false; if (this.iframe) { this.iframe.remove(); this.iframe = null; } } } class UIManager { constructor(app) { this.app = app; this.panel = null; this.timeLeft = DEFAULTS.refreshTime; const style = document.createElement("style"); style.textContent = CSS; document.head.appendChild(style); } renderPanel() { if (document.getElementById("kw_panel")) return; const div = document.createElement("div"); div.id = "kw_panel"; let isAuto = this.app.config.get(this.app.config.keys.autoRefresh); let isInf = this.app.config.get( this.app.config.keys.infiniteScroll, ); if (isAuto && isInf) { isInf = false; this.app.config.set(this.app.config.keys.infiniteScroll, false); this.app.infinite.toggle(false); } const isHide = this.app.config.get(this.app.config.keys.hideSpam); const isSniper = this.app.config.get( this.app.config.keys.sniperMode, ); div.innerHTML = `
KH
Kwork Helper 2.1⚙️
Авто-обновление
🎯 Снайпер-пуши
Скрывать спам и ЧС
Бесконечная лента
Обновление: ${this.timeLeft}с
`; document.body.appendChild(div); this.panel = div; this.bindEvents(); this.updateTimerUI(); } bindEvents() { const fab = document.getElementById("kw_fab_btn"); const autoInp = document.getElementById("kw_inp_auto"); const sniperInp = document.getElementById("kw_inp_sniper"); const infInp = document.getElementById("kw_inp_inf"); const spamInp = document.getElementById("kw_inp_spam"); fab.addEventListener("click", () => this.panel.classList.toggle("open"), ); document.addEventListener("click", (e) => { if (!this.panel.contains(e.target)) this.panel.classList.remove("open"); }); autoInp.addEventListener("change", (e) => { const isEnabled = e.target.checked; this.app.config.set( this.app.config.keys.autoRefresh, isEnabled, ); if (isEnabled) { infInp.checked = false; this.app.config.set( this.app.config.keys.infiniteScroll, false, ); this.app.infinite.toggle(false); this.timeLeft = DEFAULTS.refreshTime; window.location.reload(); } else { this.updateTimerUI(); } }); sniperInp.addEventListener("change", (e) => { this.app.config.set( this.app.config.keys.sniperMode, e.target.checked, ); if (e.target.checked) { playNotificationSound(); } }); infInp.addEventListener("change", (e) => { const isEnabled = e.target.checked; this.app.config.set( this.app.config.keys.infiniteScroll, isEnabled, ); this.app.infinite.toggle(isEnabled); if (isEnabled) { autoInp.checked = false; this.app.config.set( this.app.config.keys.autoRefresh, false, ); this.updateTimerUI(); } }); spamInp.addEventListener("change", (e) => { this.app.config.set( this.app.config.keys.hideSpam, e.target.checked, ); this.app.processor.toggleSpam(e.target.checked); }); document .getElementById("kw_btn_settings") .addEventListener("click", () => { this.panel.classList.remove("open"); this.openSettings(); }); } updateTimerUI() { const isAuto = this.app.config.get( this.app.config.keys.autoRefresh, ); const txt = document.getElementById("kw_timer_txt"); const fab = document.getElementById("kw_fab_btn"); if (isAuto) { fab.classList.add("kw-pulse-ring"); if (txt) { txt.style.display = "block"; txt.innerText = `Обновление: ${this.timeLeft}с`; } } else { fab.classList.remove("kw-pulse-ring"); if (txt) txt.style.display = "none"; } } openSettings() { if (document.querySelector(".kw-overlay")) document.querySelector(".kw-overlay").remove(); const aiConfig = this.app.config.getAiConfig(); const modalHtml = `
⚙️ Настройки Kwork Helper✕
⭐ Маркер «Моё» (любимые ключевые слова / ваш стек)
🛑 Фильтр стоп-слов
🚫 Чёрный список заказчиков (логины)
🤖 Настройки нейросети (OpenAI / OpenRouter)
Системный промпт
`; document.body.insertAdjacentHTML("beforeend", modalHtml); const overlay = document.querySelector(".kw-overlay"); overlay.addEventListener("click", (e) => { if (e.target === overlay) overlay.remove(); }); const setupTagList = ( containerId, inputId, addBtnId, getter, setter, extraClass = "", ) => { const render = () => { const items = getter(); const container = document.getElementById(containerId); container.innerHTML = items .map( (w) => `
${escapeHtml(w)} ×
`, ) .join(""); container.querySelectorAll(".kw-tag-rm").forEach((btn) => { btn.onclick = () => { setter(getter().filter((x) => x !== btn.dataset.w)); this.app.reprocessAll(true); render(); }; }); }; const add = () => { const inp = document.getElementById(inputId); const val = inp.value.trim().toLowerCase(); if (!val) return; const items = getter(); if (!items.includes(val)) { items.push(val); setter(items); this.app.reprocessAll(true); render(); } inp.value = ""; }; document.getElementById(addBtnId).onclick = add; document.getElementById(inputId).onkeypress = (e) => { if (e.key === "Enter") add(); }; render(); }; setupTagList( "kw_good_tags_container", "kw_good_inp", "kw_good_add", () => this.app.config.getGoodWords(), (v) => this.app.config.setGoodWords(v), "kw-tag-fav", ); setupTagList( "kw_tags_container", "kw_word_inp", "kw_word_add", () => this.app.config.getStopWords(), (v) => this.app.config.setStopWords(v), ); setupTagList( "kw_author_tags_container", "kw_author_inp", "kw_author_add", () => this.app.config.getStopAuthors(), (v) => this.app.config.setStopAuthors(v), ); document.getElementById("kw_reset_prompt").onclick = () => { document.getElementById("kw_ai_prompt").value = DEFAULTS.aiPrompt; document.getElementById("kw_ai_tokens").value = DEFAULTS.aiMaxTokens; }; document.getElementById("kw_modal_close").onclick = () => overlay.remove(); document.getElementById("kw_save_all").onclick = () => { const newAiConfig = { baseUrl: document.getElementById("kw_ai_base").value.trim(), apiKey: document.getElementById("kw_ai_key").value.trim(), model: document.getElementById("kw_ai_model").value.trim(), maxTokens: document .getElementById("kw_ai_tokens") .value.trim(), prompt: document .getElementById("kw_ai_prompt") .value.trim(), }; this.app.config.setAiConfig(newAiConfig); GM_notification({ text: "Настройки успешно сохранены", title: "Kwork Helper", timeout: 2000, }); overlay.remove(); }; } } class CardProcessor { constructor(app) { this.app = app; } processBatch(nodeList) { nodeList.forEach((card) => this.process(card)); } extractAuthor(card) { const userLink = card.querySelector('a[href*="/user/"]'); if (!userLink) return { username: null, linkEl: null }; const href = userLink.getAttribute("href") || ""; const match = href.match(/\/user\/([^/?#]+)/i); const username = ( match ? match[1] : userLink.textContent.trim() ).toLowerCase(); return { username, linkEl: userLink }; } process(card) { if (card.hasAttribute("data-kw-state")) { if (card.dataset.kwStats !== "1") { safe("статистика", () => this.forceReplaceStats(card)); } if (card.dataset.kwComp !== "1") { safe("конкуренция", () => this.highlightCompetition(card)); } return; } const textContent = (card.innerText || "").toLowerCase(); const { username, linkEl } = this.extractAuthor(card); if (username) card.dataset.kwAuthor = username; let isSpam = false; let spamReason = "spam"; safe("спам и ЧС фильтр", () => { const stopAuthors = this.app.config.getStopAuthors(); const stopWords = this.app.config.getStopWords(); if (username && stopAuthors.includes(username)) { isSpam = true; spamReason = `ЧС: @${username}`; } else if (stopWords.some((w) => textContent.includes(w))) { isSpam = true; spamReason = "spam"; } if (isSpam) { this.markAsSpam(card, spamReason); } }); safe("кнопка ЧС автора", () => this.addBlockAuthorBtn(card, username, linkEl), ); safe("статистика", () => this.forceReplaceStats(card)); safe("конкуренция", () => this.highlightCompetition(card)); safe("цена", () => this.highlightPrice(card)); safe("маркер Моё", () => this.highlightFavWords(card, textContent)); if (DEFAULTS.urgentWords.some((w) => textContent.includes(w))) { safe("срочность", () => { const title = card.querySelector( ".wants-card__header-title", ); if (title && !title.querySelector(".kw-urgent-fire")) title.insertAdjacentHTML( "afterbegin", '🔥', ); }); } safe("AI-кнопка", () => this.addAiBtn(card)); if (!isSpam) { card.setAttribute("data-kw-state", "active"); } safe("снайпер-проверка", () => this.app.checkNewAndSniper(card, isSpam), ); } addBlockAuthorBtn(card, username, linkEl) { if (!username || !linkEl) return; if (card.querySelector(".kw-block-user-btn")) return; const btn = document.createElement("button"); btn.type = "button"; btn.className = "kw-block-user-btn"; btn.innerHTML = "🚫"; btn.title = `В чёрный список: скрывать заказы от @${username}`; btn.onclick = (e) => { e.preventDefault(); e.stopPropagation(); const list = this.app.config.getStopAuthors(); if (!list.includes(username)) { list.push(username); this.app.config.setStopAuthors(list); this.app.reprocessAll(true); GM_notification({ title: "Kwork Helper: Чёрный список", text: `Заказчик @${username} добавлен в чёрный список`, timeout: 2500, }); } }; linkEl.insertAdjacentElement("afterend", btn); } highlightFavWords(card, textContent) { const goodWords = this.app.config.getGoodWords(); if (!goodWords.length) return; const matched = goodWords.filter((w) => textContent.includes(w)); if (!matched.length) return; card.dataset.kwFav = matched.join(", "); card.classList.add("kw-strip-fav"); const title = card.querySelector(".wants-card__header-title"); if (title && !title.querySelector(".kw-badge-fav")) { title.insertAdjacentHTML( "afterbegin", `⭐ Моё: ${escapeHtml(matched.slice(0, 3).join(", "))}`, ); } } markAsSpam(card, labelText = "spam") { card.classList.add("kw-spam-card"); const header = card.querySelector( ".wants-card__header-right-block", ); if (header && !card.querySelector(".kw-badge-spam")) header.insertAdjacentHTML( "afterbegin", `
${escapeHtml(labelText)}
`, ); if (this.app.config.get(this.app.config.keys.hideSpam)) card.classList.add("kw-hidden"); card.setAttribute("data-kw-state", "spam"); } unmarkSpam(card) { card.classList.remove("kw-spam-card", "kw-hidden"); const badge = card.querySelector(".kw-badge-spam"); if (badge) badge.remove(); card.removeAttribute("data-kw-state"); } toggleSpam(hide) { document.querySelectorAll(".kw-spam-card").forEach((c) => { if (hide) c.classList.add("kw-hidden"); else c.classList.remove("kw-hidden"); }); } forceReplaceStats(card) { const statsBlock = card.querySelector(".want-payer-statistic"); if (!statsBlock) return; if (statsBlock.querySelector(".kw-hire-badge")) { card.dataset.kwStats = "1"; return; } const fullStatsText = statsBlock.textContent || ""; const hireMatch = fullStatsText.match(/Нанято:\s*(\d+)%/i); const projMatch = fullStatsText.match( /(?:Открыто|Размещено)?\s*проектов:\s*(\d+)/i, ); if (projMatch) { card.dataset.kwProjects = String(parseInt(projMatch[1], 10)); } let textNode = null; const walker = document.createTreeWalker( statsBlock, NodeFilter.SHOW_TEXT, ); while (walker.nextNode()) { if (walker.currentNode.nodeValue.includes("Нанято")) { textNode = walker.currentNode; break; } } let badgeHTML = ""; if (hireMatch) { const p = parseInt(hireMatch[1], 10); card.dataset.kwHireRate = String(p); const type = p < DEFAULTS.badHireRate ? "bad" : p >= DEFAULTS.goodHireRate ? "good" : "mid"; const label = type === "bad" ? "Риск" : type === "good" ? "Надежный" : "Средне"; const icon = type === "bad" ? "⚠️" : type === "good" ? "🛡️" : "⚖️"; badgeHTML = `${icon} ${label} (${p}% нанятых)`; } else { badgeHTML = `❓ Нет данных`; } if (textNode) { // Если родительский узел содержит только "Нанято: 70%" или "Нанято:", заменяем его целиком let targetNode = textNode; if ( textNode.parentNode && textNode.parentNode !== statsBlock && /^Нанято:?\s*(\d+%\s*)?$/i.test( textNode.parentNode.textContent.trim(), ) ) { targetNode = textNode.parentNode; } const span = document.createElement("span"); span.innerHTML = badgeHTML; targetNode.parentNode.replaceChild(span, targetNode); // Удаляем оставшийся "хвост" с процентами (даже через пробелы или комментарии Vue) let cur = span.nextSibling; while (cur) { const next = cur.nextSibling; if ( cur.nodeType === Node.COMMENT_NODE || (cur.nodeType === Node.TEXT_NODE && cur.nodeValue.trim() === "") ) { cur = next; continue; } if ( cur.textContent && /^\s*:?\s*\d+%\s*$/.test(cur.textContent) ) { cur.remove(); } else if ( cur.nodeType === Node.TEXT_NODE && /^\s*:?\s*\d+%/.test(cur.nodeValue) ) { cur.nodeValue = cur.nodeValue.replace( /^\s*:?\s*\d+%\s*/, "", ); } break; } } else { const container = statsBlock.querySelector( ".dib.v-align-t:last-child", ); if (container && !container.querySelector(".kw-hire-badge")) { const div = document.createElement("div"); div.innerHTML = badgeHTML; div.style.marginTop = "4px"; container.appendChild(div); } } card.dataset.kwStats = "1"; } highlightCompetition(card) { if (card.querySelector(".kw-comp-badge")) { card.dataset.kwComp = "1"; return; } const walker = document.createTreeWalker( card, NodeFilter.SHOW_TEXT, ); let textNode = null; while (walker.nextNode()) { if (walker.currentNode.nodeValue.includes("Предложений")) { textNode = walker.currentNode; break; } } if (!textNode) return; let targetNode = textNode; if ( textNode.parentNode && textNode.parentNode !== card && /^Предложений:?\s*(\d+|нет)?\s*$/i.test( textNode.parentNode.textContent.trim(), ) ) { targetNode = textNode.parentNode; } const combinedText = targetNode.textContent + " " + (targetNode.nextSibling ? targetNode.nextSibling.textContent || "" : "") + " " + (targetNode.nextElementSibling ? targetNode.nextElementSibling.textContent || "" : ""); const match = combinedText.match(/Предложений:?\s*(\d+|нет)/i); if (!match) return; const count = match[1].toLowerCase() === "нет" ? 0 : parseInt(match[1], 10) || 0; card.dataset.kwOffers = String(count); let type = "mid"; let icon = "👥"; if (count <= DEFAULTS.goodOffersMax) { type = "good"; icon = "🎯"; } else if (count >= DEFAULTS.badOffersMin) { type = "bad"; icon = "🔥"; } const span = document.createElement("span"); span.className = `kw-badge kw-badge-${type} kw-comp-badge`; span.textContent = `${icon} Предложений: ${count}`; targetNode.parentNode.replaceChild(span, targetNode); // Удаляем оставшийся "хвост" с числом откликов, если он был в соседнем узле let cur = span.nextSibling; while (cur) { const next = cur.nextSibling; if ( cur.nodeType === Node.COMMENT_NODE || (cur.nodeType === Node.TEXT_NODE && cur.nodeValue.trim() === "") ) { cur = next; continue; } if ( cur.textContent && /^\s*:?\s*(\d+|нет)\s*$/i.test(cur.textContent) ) { cur.remove(); } else if ( cur.nodeType === Node.TEXT_NODE && /^\s*:?\s*(\d+|нет)\b/i.test(cur.nodeValue) ) { cur.nodeValue = cur.nodeValue.replace( /^\s*:?\s*(\d+|нет)\s*/i, "", ); } break; } card.dataset.kwComp = "1"; } highlightPrice(card) { const isLowPriceLabel = card.querySelector( ".wants-card__review--low-price", ); if (isLowPriceLabel) { card.classList.add("kw-strip-bad"); return; } const priceEl = card.querySelector(".wants-card__price"); const higherPriceEl = card.querySelector( ".wants-card__description-higher-price", ); let price = 0; let higherPrice = 0; if (priceEl) { price = parseInt( priceEl.textContent .replace(/\s/g, "") .replace(/\D/g, ""), 10, ) || 0; } if (higherPriceEl) { higherPrice = parseInt( higherPriceEl.textContent .replace(/\s/g, "") .replace(/\D/g, ""), 10, ) || 0; } const effectivePrice = Math.max(price, higherPrice); card.dataset.kwPrice = String(effectivePrice); if (effectivePrice >= DEFAULTS.goodPrice) card.classList.add("kw-strip-good"); else if (effectivePrice <= DEFAULTS.badPrice && effectivePrice > 0) card.classList.add("kw-strip-bad"); } addAiBtn(card) { const link = card.querySelector(".wants-card__header-title a"); if (!link) return; if (link.parentNode.querySelector(".kw-ai-btn")) return; const btn = document.createElement("button"); btn.className = "kw-ai-btn"; btn.innerHTML = "🤖"; btn.title = "Анализ нейросетью + генерация отклика"; btn.onclick = async (e) => { e.preventDefault(); e.stopPropagation(); const existing = card.querySelector(".kw-ai-response-box"); if (existing) { existing.remove(); return; } btn.classList.add("loading"); const descBlock = card.querySelector( ".wants-card__description-text", ); const fullTextEl = descBlock.querySelector(".overflow-hidden") ?.nextElementSibling || descBlock; const fullText = fullTextEl.innerText; const title = link.innerText.trim(); let priceText = "Бюджет не указан"; const priceBlock = card.querySelector(".wants-card__right"); if (priceBlock) { priceText = priceBlock.innerText .replace(/\s+/g, " ") .trim(); } const hireRate = card.dataset.kwHireRate ? `${card.dataset.kwHireRate}%` : "Нет данных (новичок)"; const projectsCount = card.dataset.kwProjects ? `${card.dataset.kwProjects} проектов` : "Неизвестно"; const offersCount = card.dataset.kwOffers ? `${card.dataset.kwOffers} откликов` : "Неизвестно"; const fullPrompt = [ `Заголовок: ${title}`, `Бюджет: ${priceText}`, `Статистика заказчика: Нанято ${hireRate}, размещено ${projectsCount}`, `Конкуренция по заказу: уже подано ${offersCount}`, `Описание задачи:\n${fullText}`, ].join("\n\n"); const cacheKey = this.app.infinite.getCardSignature(card) + "|" + priceText; const cached = this.app.aiCache.get(cacheKey); if (cached) { btn.classList.remove("loading"); this.showAiResponse(card, cached); return; } try { const response = await this.app.ai.analyze(fullPrompt); btn.classList.remove("loading"); this.app.cacheAiResponse(cacheKey, response); this.showAiResponse(card, response); } catch (error) { btn.classList.remove("loading"); const box = document.createElement("div"); box.className = "kw-ai-response-box kw-ai-error"; box.innerText = ` ${error.message}`; card.querySelector( ".wants-card__description-text", ).appendChild(box); } }; link.parentNode.appendChild(btn); } showAiResponse(card, rawText) { const box = document.createElement("div"); box.className = "kw-ai-response-box"; const pitchMatch = rawText.match(/([\s\S]*?)<\/pitch>/i); const cleanAnalysis = rawText .replace(/[\s\S]*?<\/pitch>/gi, "") .trim(); const analysisEl = document.createElement("div"); analysisEl.textContent = cleanAnalysis; box.appendChild(analysisEl); if (pitchMatch && pitchMatch[1].trim()) { const pitchText = pitchMatch[1].trim(); const pitchBox = document.createElement("div"); pitchBox.className = "kw-ai-pitch-box"; const head = document.createElement("div"); head.className = "kw-ai-pitch-head"; head.innerHTML = `✍️ Черновик отклика:`; const copyBtn = document.createElement("button"); copyBtn.type = "button"; copyBtn.className = "kw-copy-pitch-btn"; copyBtn.textContent = "📋 Скопировать отклик"; copyBtn.onclick = (e) => { e.preventDefault(); e.stopPropagation(); navigator.clipboard.writeText(pitchText).then(() => { copyBtn.textContent = "✅ Скопировано!"; setTimeout(() => { copyBtn.textContent = "📋 Скопировать отклик"; }, 2000); }); }; head.appendChild(copyBtn); const pitchBody = document.createElement("div"); pitchBody.textContent = pitchText; pitchBox.appendChild(head); pitchBox.appendChild(pitchBody); box.appendChild(pitchBox); } card.querySelector(".wants-card__description-text").appendChild( box, ); } } class KworkAssistant { constructor() { this.config = new ConfigManager(); this.ai = new AiClient(this.config); this.processor = new CardProcessor(this); this.infinite = new InfiniteScrollManager(this); this.ui = new UIManager(this); this.aiCache = new Map(); this.initSeenCards(); } initSeenCards() { this.isFirstSessionLoad = false; try { const raw = sessionStorage.getItem("kw_seen_cards"); if (raw) { this.seenCards = new Set(JSON.parse(raw)); } else { this.seenCards = new Set(); this.isFirstSessionLoad = true; } } catch (e) { this.seenCards = new Set(); this.isFirstSessionLoad = true; } } saveSeenCards() { try { const arr = Array.from(this.seenCards).slice(-400); sessionStorage.setItem("kw_seen_cards", JSON.stringify(arr)); } catch (e) { // ignore quota errors } } checkNewAndSniper(card, isSpam) { if (card.hasAttribute("data-kw-from-scroll")) return; const sig = this.infinite.getCardSignature(card); if (!sig) return; if (this.isFirstSessionLoad) { this.seenCards.add(sig); return; } if (this.seenCards.has(sig)) return; this.seenCards.add(sig); this.saveSeenCards(); const title = card.querySelector(".wants-card__header-title"); if (title && !title.querySelector(".kw-badge-new")) { title.insertAdjacentHTML( "afterbegin", '✨ НОВЫЙ', ); } if (isSpam) return; if (!this.config.get(this.config.keys.sniperMode)) return; const price = parseInt(card.dataset.kwPrice || "0", 10); const hireRate = card.dataset.kwHireRate !== undefined ? parseInt(card.dataset.kwHireRate, 10) : null; const offers = parseInt(card.dataset.kwOffers || "0", 10); const hasFav = Boolean(card.dataset.kwFav); if (offers >= DEFAULTS.badOffersMin) return; if (hireRate !== null && hireRate < DEFAULTS.badHireRate) return; if (price > 0 && price <= DEFAULTS.badPrice && !hasFav) return; const isTargetOrder = hasFav || price >= DEFAULTS.goodPrice || (price > DEFAULTS.badPrice && hireRate !== null && hireRate >= DEFAULTS.goodHireRate); if (isTargetOrder) { const titleText = card .querySelector(".wants-card__header-title a") ?.textContent?.trim() || "Новый заказ"; const priceLabel = price > 0 ? `${price} ₽` : "Бюджет в ТЗ"; const hireLabel = hireRate !== null ? `Нанято: ${hireRate}%` : "Новичок"; const favPrefix = hasFav ? `⭐ [${card.dataset.kwFav}] ` : ""; playNotificationSound(); GM_notification({ title: `🎯 Снайпер Kwork: ${priceLabel} (${hireLabel})`, text: `${favPrefix}${titleText}`, timeout: 8000, onclick: () => { window.focus(); card.scrollIntoView({ behavior: "smooth", block: "center", }); }, }); } } cacheAiResponse(key, response) { if (!key) return; this.aiCache.set(key, response); if (this.aiCache.size > 200) { const oldest = this.aiCache.keys().next().value; if (oldest !== undefined) this.aiCache.delete(oldest); } } restoreScroll() { const raw = sessionStorage.getItem("kw_scroll_pos"); if (raw === null) return; sessionStorage.removeItem("kw_scroll_pos"); const y = parseInt(raw, 10); if (!Number.isFinite(y) || y < 800) return; window.scrollTo(0, y); } init() { safe("панель управления", () => this.ui.renderPanel()); safe("раскрытие описаний", () => this.fixExpandButtons()); safe("восстановление скролла", () => this.restoreScroll()); this.runLoop(); if (this.isFirstSessionLoad && this.seenCards.size > 0) { this.isFirstSessionLoad = false; this.saveSeenCards(); } new MutationObserver((ms) => { if (ms.some((m) => m.addedNodes.length)) this.runLoop(); }).observe( document.querySelector(".wants-content") || document.body, { childList: true, subtree: true }, ); setInterval(() => this.tick(), 1000); setInterval(() => this.runLoop(), 1500); } fixExpandButtons() { document.addEventListener("click", (e) => { if (!e.target.classList.contains("kw-link-dashed")) return; const btn = e.target; const text = btn.innerText.toLowerCase(); if ( !text.includes("показать полностью") && !text.includes("скрыть") ) return; const descContainer = btn.closest( ".wants-card__description-text", ); if (!descContainer) return; const shortBlock = descContainer.querySelector(".overflow-hidden"); const fullBlock = shortBlock ? shortBlock.nextElementSibling : null; if (shortBlock && fullBlock) { if (text.includes("показать полностью")) { shortBlock.style.display = "none"; fullBlock.style.display = "block"; } else { fullBlock.style.display = "none"; shortBlock.style.display = "block"; } } }); } runLoop() { this.loopCount = (this.loopCount || 0) + 1; if (this.loopCount % 10 === 1) checkDomHealth(); safe("обработка карточек", () => { document.querySelectorAll(".want-card").forEach((card) => { this.processor.process(card); }); if (this.isFirstSessionLoad && this.seenCards.size > 0) { this.isFirstSessionLoad = false; this.saveSeenCards(); } }); } reprocessAll(force = false) { if (force) { document.querySelectorAll(".want-card").forEach((c) => { this.processor.unmarkSpam(c); c.removeAttribute("data-kw-state"); c.removeAttribute("data-kw-fav"); c.classList.remove( "kw-strip-good", "kw-strip-bad", "kw-strip-fav", ); const favBadge = c.querySelector(".kw-badge-fav"); if (favBadge) favBadge.remove(); }); } this.runLoop(); } tick() { if (!this.config.get(this.config.keys.autoRefresh)) return; this.ui.timeLeft--; this.ui.updateTimerUI(); if (this.ui.timeLeft <= 0) { sessionStorage.setItem("kw_scroll_pos", String(window.scrollY)); window.location.reload(); } } } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", () => new KworkAssistant().init(), ); } else { new KworkAssistant().init(); } })();