Greasy Fork Pro X7P

Next-gen Greasy Fork enhancement suite: radial menu, smart drawer, command palette, live CSS editor, script tools, theme scheduler, focus mode.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey, Greasemonkey или Violentmonkey.

Для установки этого скрипта вам необходимо установить расширение, такое как Tampermonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Userscripts.

Чтобы установить этот скрипт, сначала вы должны установить расширение браузера, например Tampermonkey.

Чтобы установить этот скрипт, вы должны установить расширение — менеджер скриптов.

(у меня уже есть менеджер скриптов, дайте мне установить скрипт!)

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

(у меня уже есть менеджер стилей, дайте мне установить скрипт!)

// ==UserScript==
// @name         Greasy Fork Pro X7P
// @namespace    http://tampermonkey.net/
// @version      99.2
// @description  Next-gen Greasy Fork enhancement suite: radial menu, smart drawer, command palette, live CSS editor, script tools, theme scheduler, focus mode.
// @author       Mustafa Hakan
// @match        *://greasyfork.org/*
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @grant        GM_notification
// @run-at       document-start
// @icon         data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0%25' y1='0%25' x2='100%25' y2='100%25'%3E%3Cstop offset='0%25' style='stop-color:%234a7db8'/%3E%3Cstop offset='100%25' style='stop-color:%232a4d6e'/%3E%3C/linearGradient%3E%3C/defs%3E%3Ccircle cx='50' cy='50' r='18' fill='none' stroke='url(%23g)' stroke-width='5'/%3E%3Cpath d='M35 50h30M50 35v30' stroke='%23fff' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E
// ==/UserScript==

(function() {
  'use strict';

  const D = {
    en: {
      drawer: 'Control Panel',
      tab1: 'Look',
      tab2: 'Typo',
      tab3: 'Layout',
      tab4: 'Code',
      tab5: 'Tools',
      tab6: 'Keys',
      tab7: 'Meta',
      on: 'ON',
      off: 'OFF',
      reading: 'Reading Mode',
      compact: 'Compact',
      anim: 'Animations',
      stats: 'Stats Bar',
      copyBtn: 'Copy Code',
      srchHl: 'Search HL',
      wrap: 'Wrap Code',
      hover: 'Card Hover',
      grad: 'Gradient Header',
      contrast: 'High Contrast',
      autoTheme: 'Auto Theme',
      dark: 'Dark',
      light: 'Light',
      top: 'Back to Top',
      codeSrch: 'Search in Code',
      copyTitle: 'Copy Title',
      sched: 'Schedule Theme',
      set: 'Set',
      scripts: 'Scripts',
      theme: 'Theme',
      ver: 'Version',
      font: 'Font Size',
      width: 'Page Width',
      lh: 'Line Height',
      ls: 'Letter Spacing',
      ws: 'Word Spacing',
      fw: 'Font Weight',
      extLinks: 'Highlight External',
      installs: 'Install Counts',
      author: 'Author Badge',
      dates: 'Script Dates',
      sidebar: 'Hide Sidebar',
      fullCode: 'Full Width Code',
      invert: 'Invert Code',
      darkImg: 'Darken Images',
      blur: 'Blur Images',
      outline: 'Outline Links',
      shadow: 'Text Shadow',
      center: 'Center Content',
      uline: 'Underline Links',
      larger: 'Larger Targets',
      grayscale: 'Grayscale',
      sepia: 'Sepia',
      night: 'Night Light',
      removeCol: 'Remove Colors',
      monospace: 'Monospace All',
      justify: 'Justify Text',
      hideInstall: 'Hide Install',
      zen: 'Zen Mode',
      resetAll: 'Reset All',
      export: 'Export',
      import: 'Import',
      lang: 'Language',
      sortName: 'Sort by Name',
      sortDate: 'Sort by Date',
      sortRating: 'Sort by Rating',
      sortInstalls: 'Sort by Installs',
      resetSort: 'Reset Sort',
      copyLinks: 'Copy Links',
      openAll: 'Open All',
      copyInfo: 'Copy Info',
      focusSearch: 'Focus Search',
      topPage: 'Page Top',
      middle: 'Page Middle',
      bottom: 'Page Bottom',
      autoScroll: 'Auto Scroll',
      stopScroll: 'Stop Scroll',
      quickUp: 'Quick Up',
      quickDown: 'Quick Down',
      copyHeadings: 'Copy Headings',
      charCount: 'Char Count',
      wordCount: 'Word Count',
      readTime: 'Read Time'
    },
    tr: {
      drawer: 'Kontrol Paneli',
      tab1: 'Görünüm',
      tab2: 'Tipografi',
      tab3: 'Düzen',
      tab4: 'Kod',
      tab5: 'Araçlar',
      tab6: 'Tuşlar',
      tab7: 'Meta',
      on: 'AÇIK',
      off: 'KAPALI',
      reading: 'Okuma Modu',
      compact: 'Kompakt',
      anim: 'Animasyonlar',
      stats: 'İstatistik Çubuğu',
      copyBtn: 'Kodu Kopyala',
      srchHl: 'Arama Vurgusu',
      wrap: 'Kod Sarma',
      hover: 'Kart Vurgusu',
      grad: 'Gradyan Başlık',
      contrast: 'Yüksek Kontrast',
      autoTheme: 'Otomatik Tema',
      dark: 'Koyu',
      light: 'Açık',
      top: 'Başa Dön',
      codeSrch: 'Kodda Ara',
      copyTitle: 'Başlığı Kopyala',
      sched: 'Zamanlama',
      set: 'Ayarla',
      scripts: 'Betikler',
      theme: 'Tema',
      ver: 'Sürüm',
      font: 'Yazı Boyutu',
      width: 'Sayfa Genişliği',
      lh: 'Satır Yüksekliği',
      ls: 'Harf Aralığı',
      ws: 'Kelime Aralığı',
      fw: 'Yazı Kalınlığı',
      extLinks: 'Harici Linkler',
      installs: 'Kurulum Sayısı',
      author: 'Yazar Rozeti',
      dates: 'Betik Tarihi',
      sidebar: 'Kenar Çubuğu',
      fullCode: 'Tam Geniş Kod',
      invert: 'Ters Renk Kod',
      darkImg: 'Resim Karart',
      blur: 'Resim Bulanıklaştır',
      outline: 'Link Çerçevele',
      shadow: 'Yazı Gölgesi',
      center: 'Ortala',
      uline: 'Alt Çizgili Link',
      larger: 'Büyük Tıklama',
      grayscale: 'Gri Ton',
      sepia: 'Sepya',
      night: 'Gece Işığı',
      removeCol: 'Renkleri Kaldır',
      monospace: 'Monospace',
      justify: 'İki Yana Yasla',
      hideInstall: 'Kur Butonu Gizle',
      zen: 'Zen Modu',
      resetAll: 'Sıfırla',
      export: 'Dışa Aktar',
      import: 'İçe Aktar',
      lang: 'Dil',
      sortName: 'İsme Göre Sırala',
      sortDate: 'Tarihe Göre Sırala',
      sortRating: 'Puana Göre Sırala',
      sortInstalls: 'Kuruluma Göre Sırala',
      resetSort: 'Sıralamayı Sıfırla',
      copyLinks: 'Linkleri Kopyala',
      openAll: 'Hepsini Aç',
      copyInfo: 'Bilgileri Kopyala',
      focusSearch: 'Aramaya Odaklan',
      topPage: 'Sayfa Başı',
      middle: 'Sayfa Ortası',
      bottom: 'Sayfa Sonu',
      autoScroll: 'Otomatik Kaydır',
      stopScroll: 'Kaydırmayı Durdur',
      quickUp: 'Hızlı Yukarı',
      quickDown: 'Hızlı Aşağı',
      copyHeadings: 'Başlıkları Kopyala',
      charCount: 'Karakter Sayısı',
      wordCount: 'Kelime Sayısı',
      readTime: 'Okuma Süresi'
    }
  };

  let L = GM_getValue('lang','en');
  const _ = k => (D[L] && D[L][k]) ? D[L][k] : (D['en'][k] || k);

  const P = {
    bg: '#0f1a2e',
    bgL: '#152238',
    bgD: '#0a1220',
    txt: '#e0e8f0',
    muted: '#8090b0',
    acc: '#4a7db8',
    accS: '#5b8ec9',
    gold: '#5b8ec9',
    goldL: '#7aa8d8',
    border: 'rgba(255,255,255,0.08)',
    borderS: 'rgba(255,255,255,0.18)',
    shadow: '0 8px 24px rgba(0,0,0,0.6)',
    r: '14px',
    rs: '8px'
  };

  const DEF = {
    theme: 'dark',
    fontSize: '16px',
    reading: false,
    compact: false,
    anim: true,
    stats: true,
    srchHl: true,
    copyBtn: true,
    wrap: false,
    width: '900px',
    hover: true,
    autoTheme: false,
    contrast: false,
    grad: true,
    lh: '1.6',
    ls: '0px',
    ws: '0px',
    fw: '400',
    extLinks: false,
    installs: false,
    author: false,
    dates: false,
    schedDark: '',
    schedLight: '',
    invert: false,
    darkImg: false,
    blur: false,
    outline: false,
    shadow: false,
    center: false,
    uline: false,
    larger: false,
    grayscale: false,
    sepia: false,
    night: false,
    removeCol: false,
    monospace: false,
    justify: false,
    sidebar: false,
    fullCode: false,
    hideInstall: false,
    zen: false,
    charCount: false,
    wordCount: false,
    readTime: false,
    blueTheme: false,
    purpleTheme: false,
    orangeTheme: false
  };

  let S = {};
  for (let k in DEF) S[k] = GM_getValue(k, DEF[k]);
  const save = () => { for (let k in S) GM_setValue(k, S[k]); };

  function applyVars() {
    let s = document.documentElement.style;
    s.setProperty('--p-bg', P.bg);
    s.setProperty('--p-bgL', P.bgL);
    s.setProperty('--p-bgD', P.bgD);
    s.setProperty('--p-txt', P.txt);
    s.setProperty('--p-muted', P.muted);
    s.setProperty('--p-acc', S.blueTheme ? '#5a8ec0' : S.purpleTheme ? '#8b6bb8' : S.orangeTheme ? '#c8905a' : P.acc);
    s.setProperty('--p-accS', S.blueTheme ? '#7aa8d8' : S.purpleTheme ? '#a088c8' : S.orangeTheme ? '#d8a878' : P.accS);
    s.setProperty('--p-gold', S.blueTheme ? '#5a8ec0' : S.purpleTheme ? '#8b6bb8' : S.orangeTheme ? '#c8905a' : P.gold);
    s.setProperty('--p-goldL', S.blueTheme ? '#7aa8d8' : S.purpleTheme ? '#a088c8' : S.orangeTheme ? '#d8a878' : P.goldL);
    s.setProperty('--p-border', P.border);
    s.setProperty('--p-borderS', P.borderS);
    s.setProperty('--p-shadow', P.shadow);
    s.setProperty('--p-r', P.r);
    s.setProperty('--p-rs', P.rs);
    s.setProperty('--p-trans', S.anim ? '0.3s ease' : '0s');
  }

  function fullCSS() {
    let old = document.getElementById('elite-style');
    if (old) old.remove();
    let css = '*{box-sizing:border-box}body{font-family:system-ui,sans-serif;background:var(--p-bg);color:var(--p-txt);line-height:'+S.lh+';letter-spacing:'+S.ls+';word-spacing:'+S.ws+';font-weight:'+S.fw+';min-height:100vh;'+(S.grayscale?'filter:grayscale(100%);':'')+(S.sepia?'filter:sepia(80%);':'')+(S.night?'filter:brightness(0.8) sepia(20%);':'')+(S.removeCol?'filter:saturate(0);':'')+'}';
    css += 'a{color:var(--p-gold);text-decoration:none;'+(S.uline?'text-decoration:underline':'')+'}a:hover{color:var(--p-accS)}';
    css += '#main-header,.navbar,.top-bar{background:var(--p-bgD)!important;border-bottom:1px solid var(--p-border)!important;box-shadow:var(--p-shadow)!important;padding:12px 20px!important;position:sticky!important;top:0!important;z-index:900}';
    css += '.content,.main-content,#content,main,article{background:var(--p-bgL)!important;border-radius:var(--p-r)!important;border:1px solid var(--p-border)!important;padding:24px!important;margin:20px auto!important;max-width:'+S.width+'!important;box-shadow:var(--p-shadow)!important;'+(S.center?'margin-left:auto!important;margin-right:auto!important':'')+'}';
    css += '.card,.script-item,.script-list-item{background:var(--p-bgD)!important;border:1px solid var(--p-border)!important;border-radius:var(--p-r)!important;padding:16px!important;margin-bottom:12px!important;box-shadow:var(--p-shadow)!important;'+(S.larger?'padding:24px!important':'')+'}';
    if (S.hover) css += '.card:hover,.script-item:hover,.script-list-item:hover{transform:translateY(-2px)!important;box-shadow:0 12px 28px rgba(0,0,0,0.7)!important;border-color:var(--p-gold)!important}';
    css += 'button,.btn{background:var(--p-acc)!important;color:#fff!important;border:1px solid var(--p-gold)!important;border-radius:var(--p-rs)!important;padding:8px 14px!important;font-weight:600!important;cursor:pointer!important}';
    css += 'button:hover,.btn:hover{background:var(--p-goldL)!important}';
    css += 'input,textarea,select{background:var(--p-bgD)!important;border:1px solid var(--p-border)!important;border-radius:var(--p-rs)!important;padding:10px 14px!important;color:var(--p-txt)!important}';
    css += 'pre,code,.code,.highlight{background:var(--p-bgD)!important;border:1px solid var(--p-border)!important;border-radius:var(--p-rs)!important;padding:12px!important;font-family:"Fira Code",monospace!important;color:var(--p-txt)!important;white-space:'+(S.wrap?'pre-wrap':'pre')+'!important;'+(S.invert?'filter:invert(100%);':'')+(S.fullCode?'max-width:100%!important;width:100%!important':'')+'}';
    if (S.darkImg) css += 'img{filter:brightness(0.7)}';
    if (S.blur) css += 'img{filter:blur(8px);transition:filter 0.3s}img:hover{filter:blur(0)}';
    if (S.monospace) css += 'body,p,span,div,a,li,td,th{font-family:"Fira Code",monospace!important}';
    if (S.justify) css += 'p,div.content{text-align:justify!important}';
    if (S.sidebar) css += '.sidebar,.side-panel,aside,#sidebar{display:none!important}';
    if (S.outline) css += 'a{border:1px solid var(--p-gold)!important;padding:2px 4px!important;border-radius:3px!important}';
    if (S.shadow) css += 'body{text-shadow:0 1px 2px rgba(0,0,0,0.5)}';
    if (S.hideInstall) css += '.install-button,.btn-install,.install-link{display:none!important}';
    css += '#elite-stats{position:fixed;top:60px;right:20px;background:var(--p-bgD);border:1px solid var(--p-gold);border-radius:var(--p-rs);padding:8px 12px;font-size:0.8rem;color:var(--p-muted);z-index:950}';
    css += '#elite-fab{position:fixed;bottom:24px;right:24px;width:52px;height:52px;border-radius:50%;background:var(--p-acc);border:2px solid var(--p-gold);box-shadow:var(--p-shadow);cursor:pointer;z-index:1100;display:flex;align-items:center;justify-content:center}';
    css += '#elite-fab svg{width:28px;height:28px;fill:#fff}';
    css += '#elite-badge{position:fixed;bottom:80px;right:18px;background:var(--p-gold);color:#fff;padding:4px 10px;border-radius:20px;font-size:0.7rem;font-weight:700;letter-spacing:1px;z-index:1100}';
    css += '#elite-radial{position:fixed;bottom:60px;right:60px;width:160px;height:160px;z-index:1099;pointer-events:none}';
    css += '.elite-radial-item{position:absolute;width:44px;height:44px;border-radius:50%;background:var(--p-acc);border:2px solid var(--p-gold);display:flex;align-items:center;justify-content:center;cursor:pointer;pointer-events:auto;box-shadow:var(--p-shadow);color:#fff;transition:all 0.3s cubic-bezier(0,0,0.2,1);opacity:0;transform:scale(0)}';
    css += '.elite-radial-item.open{opacity:1;transform:scale(1)}';
    css += '.elite-radial-item:nth-child(1){top:0;left:50%;margin-left:-22px}.elite-radial-item:nth-child(2){top:50%;left:0;margin-top:-22px}.elite-radial-item:nth-child(3){top:50%;right:0;margin-top:-22px}';
    css += '#elite-overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.4);z-index:1199;display:none}#elite-overlay.open{display:block}';
    css += '#elite-drawer{position:fixed;bottom:-100%;left:50%;transform:translateX(-50%);width:680px;max-width:95vw;height:78vh;background:var(--p-bgL);border:2px solid var(--p-gold);border-radius:24px 24px 0 0;box-shadow:var(--p-shadow);z-index:1200;transition:bottom 0.4s cubic-bezier(0,0,0.2,1);display:flex;flex-direction:column}#elite-drawer.open{bottom:0}';
    css += '#elite-drawer-head{padding:16px 20px;border-bottom:1px solid var(--p-border);display:flex;justify-content:space-between;align-items:center;font-weight:600;background:var(--p-bgD);border-radius:24px 24px 0 0}';
    css += '#elite-tabs{display:flex;flex-wrap:wrap;border-bottom:1px solid var(--p-border);background:var(--p-bg)}.elite-tab{flex:1;padding:10px 4px;text-align:center;cursor:pointer;font-weight:600;font-size:0.75rem;border-bottom:2px solid transparent;color:var(--p-muted);white-space:nowrap}.elite-tab.active{color:var(--p-gold);border-bottom-color:var(--p-gold)}';
    css += '#elite-content{flex:1;overflow-y:auto;padding:14px 20px}';
    css += '.elite-btn{display:flex;justify-content:space-between;align-items:center;width:100%;margin-bottom:6px;padding:10px 12px;background:var(--p-bg);border:1px solid var(--p-border);border-radius:var(--p-rs);cursor:pointer;font-weight:500;font-size:0.85rem}.elite-btn:hover{border-color:var(--p-gold);background:var(--p-bgD)}';
    css += '.elite-status{font-size:0.7rem;padding:2px 8px;border-radius:20px;font-weight:600}.elite-status.on{background:var(--p-acc);color:#fff}.elite-status.off{background:transparent;border:1px solid var(--p-borderS);color:var(--p-muted)}';
    css += '.elite-section{font-size:0.7rem;text-transform:uppercase;letter-spacing:1px;color:var(--p-muted);margin:12px 0 8px;border-bottom:1px solid var(--p-border);padding-bottom:4px}';
    css += 'input[type="range"]{-webkit-appearance:none;width:100%;height:6px;background:var(--p-bg);border-radius:3px;margin:8px 0}input[type="range"]::-webkit-slider-thumb{-webkit-appearance:none;width:18px;height:18px;border-radius:50%;background:var(--p-gold);cursor:pointer;border:2px solid var(--p-bgD)}';
    css += '::-webkit-scrollbar{width:8px}::-webkit-scrollbar-track{background:var(--p-bgD)}::-webkit-scrollbar-thumb{background:var(--p-acc);border-radius:4px}';
    css += '@media(max-width:768px){#elite-drawer{width:100%;max-width:100%}#elite-fab{bottom:16px;right:16px}}';
    GM_addStyle(css);
    let a = document.querySelectorAll('style');
    if (a.length) a[a.length-1].id = 'elite-style';
  }

  let radialOpen = false, drawerOpen = false, autoScrollId;

  function createUI() {
    let badge = document.createElement('div'); badge.id='elite-badge'; badge.textContent='PRO'; document.body.appendChild(badge);
    let fab = document.createElement('div'); fab.id='elite-fab';
    fab.innerHTML = `<svg viewBox="0 0 24 24"><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/></svg>`;
    fab.addEventListener('click', ()=>{ radialOpen=!radialOpen; document.querySelectorAll('.elite-radial-item').forEach(e=>e.classList.toggle('open',radialOpen)); });
    document.body.appendChild(fab);

    let radial = document.createElement('div'); radial.id='elite-radial';
    radial.innerHTML = `
      <div class="elite-radial-item" id="r-settings"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg></div>
      <div class="elite-radial-item" id="r-tools"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg></div>
      <div class="elite-radial-item" id="r-profile"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg></div>`;
    document.body.appendChild(radial);
    document.getElementById('r-settings').addEventListener('click', ()=>{ radialOpen=false; document.querySelectorAll('.elite-radial-item').forEach(e=>e.classList.remove('open')); openDrawer(); });
    document.getElementById('r-tools').addEventListener('click', ()=>{ radialOpen=false; document.querySelectorAll('.elite-radial-item').forEach(e=>e.classList.remove('open')); quickTools(); });
    document.getElementById('r-profile').addEventListener('click', ()=>{ window.open('https://greasyfork.org/tr/users/1573407-mustafa-hakan','_blank'); radialOpen=false; document.querySelectorAll('.elite-radial-item').forEach(e=>e.classList.remove('open')); });

    let overlay = document.createElement('div'); overlay.id='elite-overlay'; overlay.addEventListener('click', ()=>{ drawerOpen=false; document.getElementById('elite-drawer').classList.remove('open'); overlay.classList.remove('open'); });
    document.body.appendChild(overlay);

    let drawer = document.createElement('div'); drawer.id='elite-drawer';
    drawer.innerHTML = `
      <div id="elite-drawer-head"><span>${_('drawer')}</span><span id="drawer-close" style="cursor:pointer"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg></span></div>
      <div id="elite-tabs">
        <div class="elite-tab active" data-tab="Look">${_('tab1')}</div>
        <div class="elite-tab" data-tab="Typo">${_('tab2')}</div>
        <div class="elite-tab" data-tab="Layout">${_('tab3')}</div>
        <div class="elite-tab" data-tab="Code">${_('tab4')}</div>
        <div class="elite-tab" data-tab="Tools">${_('tab5')}</div>
        <div class="elite-tab" data-tab="Keys">${_('tab6')}</div>
        <div class="elite-tab" data-tab="Meta">${_('tab7')}</div>
      </div>
      <div id="elite-content"></div>`;
    document.body.appendChild(drawer);
    document.getElementById('drawer-close').addEventListener('click', ()=>{ drawerOpen=false; drawer.classList.remove('open'); overlay.classList.remove('open'); });
    document.querySelectorAll('.elite-tab').forEach(tab=>{
      tab.addEventListener('click', ()=>{
        document.querySelectorAll('.elite-tab').forEach(t=>t.classList.remove('active'));
        tab.classList.add('active');
        switchTab(tab.dataset.tab);
      });
    });
    switchTab('Look');
  }

  function openDrawer(){ drawerOpen=true; document.getElementById('elite-drawer').classList.add('open'); document.getElementById('elite-overlay').classList.add('open'); }

  function btnToggle(id,label,key){
    return `<div class="elite-btn" id="${id}"><span>${label}</span><span class="elite-status ${S[key]?'on':'off'}">${S[key]?_('on'):_('off')}</span></div>`;
  }

  function updateToggle(id, key){
    let b = document.getElementById(id); if(!b) return;
    let s = b.querySelector('.elite-status');
    if(s){ s.textContent = S[key] ? _('on') : _('off'); s.className = 'elite-status '+(S[key]?'on':'off'); }
  }

  function switchTab(tab){
    let c = document.getElementById('elite-content');
    if (!c) return;
    if (tab==='Look'){
      c.innerHTML = btnToggle('cc-reading',_('reading'),'reading')+
        btnToggle('cc-compact',_('compact'),'compact')+
        btnToggle('cc-hover',_('hover'),'hover')+
        btnToggle('cc-grad',_('grad'),'grad')+
        btnToggle('cc-center',_('center'),'center')+
        btnToggle('cc-shadow',_('shadow'),'shadow')+
        btnToggle('cc-uline',_('uline'),'uline')+
        btnToggle('cc-larger',_('larger'),'larger')+
        `<label style="font-size:0.85rem">${_('font')}: <span id="fs-val">${S.fontSize}</span></label>
        <input type="range" id="fs-range" min="12" max="22" value="${parseInt(S.fontSize)}">`+
        `<label style="font-size:0.85rem">${_('width')}:</label>
        <select id="width-sel" style="width:100%"><option value="700px" ${S.width==='700px'?'selected':''}>Narrow</option><option value="900px" ${S.width==='900px'?'selected':''}>Normal</option><option value="1100px" ${S.width==='1100px'?'selected':''}>Wide</option><option value="100%" ${S.width==='100%'?'selected':''}>Full</option></select>`;
      document.getElementById('fs-range').addEventListener('input', function(){
        document.getElementById('fs-val').textContent = this.value+'px';
        S.fontSize = this.value+'px'; save(); applyAll();
      });
      document.getElementById('width-sel').addEventListener('change', function(){ S.width = this.value; save(); applyAll(); });
      ['reading','compact','hover','grad','center','shadow','uline','larger'].forEach(k=> bindToggle('cc-'+k, k));
    }
    else if (tab==='Typo'){
      c.innerHTML = btnToggle('cc-extLinks',_('extLinks'),'extLinks')+
        btnToggle('cc-monospace',_('monospace'),'monospace')+
        btnToggle('cc-justify',_('justify'),'justify')+
        `<label style="font-size:0.85rem">${_('lh')}: <span id="lh-val">${S.lh}</span></label>
        <input type="range" id="lh-range" min="1.2" max="2.2" step="0.1" value="${S.lh}">`+
        `<label style="font-size:0.85rem">${_('ls')}: <span id="ls-val">${S.ls}</span></label>
        <input type="range" id="ls-range" min="-1" max="3" step="0.1" value="${parseFloat(S.ls)}">`+
        `<label style="font-size:0.85rem">${_('ws')}: <span id="ws-val">${S.ws}</span></label>
        <input type="range" id="ws-range" min="0" max="6" step="0.1" value="${parseFloat(S.ws)}">`+
        `<label style="font-size:0.85rem">${_('fw')}: <span id="fw-val">${S.fw}</span></label>
        <input type="range" id="fw-range" min="300" max="700" step="100" value="${S.fw}">`;
      document.getElementById('lh-range').addEventListener('input', function(){ document.getElementById('lh-val').textContent=this.value; S.lh=this.value; save(); applyAll(); });
      document.getElementById('ls-range').addEventListener('input', function(){ document.getElementById('ls-val').textContent=this.value+'px'; S.ls=this.value+'px'; save(); applyAll(); });
      document.getElementById('ws-range').addEventListener('input', function(){ document.getElementById('ws-val').textContent=this.value+'px'; S.ws=this.value+'px'; save(); applyAll(); });
      document.getElementById('fw-range').addEventListener('input', function(){ document.getElementById('fw-val').textContent=this.value; S.fw=this.value; save(); applyAll(); });
      ['extLinks','monospace','justify'].forEach(k=> bindToggle('cc-'+k, k));
    }
    else if (tab==='Layout'){
      c.innerHTML = btnToggle('cc-sidebar',_('sidebar'),'sidebar')+
        btnToggle('cc-fullCode',_('fullCode'),'fullCode')+
        btnToggle('cc-darkImg',_('darkImg'),'darkImg')+
        btnToggle('cc-blur',_('blur'),'blur')+
        btnToggle('cc-outline',_('outline'),'outline')+
        btnToggle('cc-grayscale',_('grayscale'),'grayscale')+
        btnToggle('cc-sepia',_('sepia'),'sepia')+
        btnToggle('cc-night',_('night'),'night')+
        btnToggle('cc-removeCol',_('removeCol'),'removeCol');
      ['sidebar','fullCode','darkImg','blur','outline','grayscale','sepia','night','removeCol'].forEach(k=> bindToggle('cc-'+k, k));
    }
    else if (tab==='Code'){
      c.innerHTML = btnToggle('cc-copyBtn',_('copyBtn'),'copyBtn')+
        btnToggle('cc-srchHl',_('srchHl'),'srchHl')+
        btnToggle('cc-wrap',_('wrap'),'wrap')+
        btnToggle('cc-invert',_('invert'),'invert')+
        btnToggle('cc-fullCode',_('fullCode'),'fullCode')+
        `<div class="elite-btn" id="cc-codeSrch"><span>${_('codeSrch')}</span></div>`;
      document.getElementById('cc-codeSrch').addEventListener('click',()=>{
        let q=prompt('Search in code:'); if(!q) return;
        document.querySelectorAll('pre,code').forEach(el=>{
          el.innerHTML = el.innerHTML.replace(new RegExp('('+q.replace(/[.*+?^${}()|[\]\\]/g,'\\$&')+')','gi'), '<span style="background:#4a7db8;color:#fff;border-radius:3px">$1</span>');
        });
      });
      ['copyBtn','srchHl','wrap','invert'].forEach(k=> bindToggle('cc-'+k, k));
    }
    else if (tab==='Tools'){
      c.innerHTML = btnToggle('cc-stats',_('stats'),'stats')+
        btnToggle('cc-installs',_('installs'),'installs')+
        btnToggle('cc-author',_('author'),'author')+
        btnToggle('cc-dates',_('dates'),'dates')+
        btnToggle('cc-hideInstall',_('hideInstall'),'hideInstall')+
        `<div class="elite-btn" id="cc-sortName"><span>${_('sortName')}</span></div>
        <div class="elite-btn" id="cc-sortDate"><span>${_('sortDate')}</span></div>
        <div class="elite-btn" id="cc-sortRating"><span>${_('sortRating')}</span></div>
        <div class="elite-btn" id="cc-sortInstalls"><span>${_('sortInstalls')}</span></div>
        <div class="elite-btn" id="cc-resetSort"><span>${_('resetSort')}</span></div>
        <div class="elite-btn" id="cc-copyLinks"><span>${_('copyLinks')}</span></div>
        <div class="elite-btn" id="cc-openAll"><span>${_('openAll')}</span></div>
        <div class="elite-btn" id="cc-copyInfo"><span>${_('copyInfo')}</span></div>`;
      ['stats','installs','author','dates','hideInstall'].forEach(k=> bindToggle('cc-'+k, k));
      document.getElementById('cc-sortName').addEventListener('click',()=>sort('name'));
      document.getElementById('cc-sortDate').addEventListener('click',()=>sort('date'));
      document.getElementById('cc-sortRating').addEventListener('click',()=>sort('rating'));
      document.getElementById('cc-sortInstalls').addEventListener('click',()=>sort('installs'));
      document.getElementById('cc-resetSort').addEventListener('click',()=>location.reload());
      document.getElementById('cc-copyLinks').addEventListener('click',()=>{
        let links=[]; document.querySelectorAll('.script-item a[href^="/"], .script-list-item a[href^="/"]').forEach(a=>{ if(a.href) links.push(a.href); });
        navigator.clipboard.writeText(links.join('\n'));
      });
      document.getElementById('cc-openAll').addEventListener('click',()=>{
        let links=document.querySelectorAll('.script-item a[href^="/"], .script-list-item a[href^="/"]');
        if(links.length>10 && !confirm('Open '+links.length+'?')) return;
        links.forEach((a,i)=>setTimeout(()=>window.open(a.href,'_blank'), i*300));
      });
      document.getElementById('cc-copyInfo').addEventListener('click',()=>{
        let info=[]; document.querySelectorAll('.script-item, .script-list-item').forEach(item=>{
          let t=item.querySelector('h2 a, .script-title a'); if(t) info.push(t.textContent.trim()+' - '+t.href);
        });
        navigator.clipboard.writeText(info.join('\n'));
      });
    }
    else if (tab==='Keys'){
      c.innerHTML = `<div class="elite-btn" id="cc-top"><span>${_('topPage')}</span></div>
        <div class="elite-btn" id="cc-middle"><span>${_('middle')}</span></div>
        <div class="elite-btn" id="cc-bottom"><span>${_('bottom')}</span></div>
        <div class="elite-btn" id="cc-autoScroll"><span>${_('autoScroll')}</span></div>
        <div class="elite-btn" id="cc-stopScroll"><span>${_('stopScroll')}</span></div>
        <div class="elite-btn" id="cc-quickUp"><span>${_('quickUp')}</span></div>
        <div class="elite-btn" id="cc-quickDown"><span>${_('quickDown')}</span></div>
        <div class="elite-btn" id="cc-focusSearch"><span>${_('focusSearch')}</span></div>
        <div class="elite-btn" id="cc-copyTitle"><span>${_('copyTitle')}</span></div>
        <div class="elite-btn" id="cc-copyHeadings"><span>${_('copyHeadings')}</span></div>
        <div class="elite-btn" id="cc-charCount"><span>${_('charCount')}</span></div>
        <div class="elite-btn" id="cc-wordCount"><span>${_('wordCount')}</span></div>
        <div class="elite-btn" id="cc-readTime"><span>${_('readTime')}</span></div>`;
      document.getElementById('cc-top').addEventListener('click',()=>window.scrollTo({top:0,behavior:'smooth'}));
      document.getElementById('cc-middle').addEventListener('click',()=>window.scrollTo({top:document.body.scrollHeight/2,behavior:'smooth'}));
      document.getElementById('cc-bottom').addEventListener('click',()=>window.scrollTo({top:document.body.scrollHeight,behavior:'smooth'}));
      document.getElementById('cc-autoScroll').addEventListener('click',()=>{ if(autoScrollId) clearInterval(autoScrollId); autoScrollId=setInterval(()=>window.scrollBy(0,2),50); });
      document.getElementById('cc-stopScroll').addEventListener('click',()=>{ if(autoScrollId){ clearInterval(autoScrollId); autoScrollId=null; } });
      document.getElementById('cc-quickUp').addEventListener('click',()=>window.scrollBy(0,-500));
      document.getElementById('cc-quickDown').addEventListener('click',()=>window.scrollBy(0,500));
      document.getElementById('cc-focusSearch').addEventListener('click',()=>{ let s=document.querySelector('input[type="search"], input[name="q"]'); if(s) s.focus(); });
      document.getElementById('cc-copyTitle').addEventListener('click',()=>navigator.clipboard.writeText(document.title));
      document.getElementById('cc-copyHeadings').addEventListener('click',()=>{
        let h=[]; document.querySelectorAll('h1,h2,h3,h4').forEach(e=>h.push(e.textContent.trim())); navigator.clipboard.writeText(h.join('\n'));
      });
      document.getElementById('cc-charCount').addEventListener('click',()=>{ S.charCount=!S.charCount; save(); updateStats(); });
      document.getElementById('cc-wordCount').addEventListener('click',()=>{ S.wordCount=!S.wordCount; save(); updateStats(); });
      document.getElementById('cc-readTime').addEventListener('click',()=>{ S.readTime=!S.readTime; save(); updateStats(); });
    }
    else if (tab==='Meta'){
      c.innerHTML = `
        <div class="elite-section">${_('theme')}</div>
        <div class="elite-btn" id="cc-themeDark">${_('dark')}</div>
        <div class="elite-btn" id="cc-themeLight">${_('light')}</div>
        <div class="elite-btn" id="cc-autoTheme">${_('autoTheme')} <span class="elite-status ${S.autoTheme?'on':'off'}">${S.autoTheme?_('on'):_('off')}</span></div>
        <div class="elite-btn" id="cc-blueTheme">Blue Theme <span class="elite-status ${S.blueTheme?'on':'off'}">${S.blueTheme?_('on'):_('off')}</span></div>
        <div class="elite-btn" id="cc-purpleTheme">Purple Theme <span class="elite-status ${S.purpleTheme?'on':'off'}">${S.purpleTheme?_('on'):_('off')}</span></div>
        <div class="elite-btn" id="cc-orangeTheme">Orange Theme <span class="elite-status ${S.orangeTheme?'on':'off'}">${S.orangeTheme?_('on'):_('off')}</span></div>
        <div class="elite-section">${_('sched')}</div>
        <label>${_('dark')}: <input type="time" id="sched-dark" value="${S.schedDark||''}" style="width:100%"></label>
        <label>${_('light')}: <input type="time" id="sched-light" value="${S.schedLight||''}" style="width:100%"></label>
        <div class="elite-btn" id="cc-schedSave">${_('set')}</div>
        <div class="elite-btn" id="cc-schedClear">Clear</div>
        <div class="elite-section">System</div>
        <div class="elite-btn" id="cc-export">${_('export')}</div>
        <div class="elite-btn" id="cc-import">${_('import')}</div>
        <div class="elite-btn" id="cc-zen">${_('zen')} <span class="elite-status ${S.zen?'on':'off'}">${S.zen?_('on'):_('off')}</span></div>
        <div class="elite-btn" id="cc-lang">${_('lang')}: ${L.toUpperCase()}</div>
        <div class="elite-btn" id="cc-resetAll">${_('resetAll')}</div>`;
      document.getElementById('cc-themeDark').addEventListener('click',()=>{ S.theme='dark'; save(); applyAll(); });
      document.getElementById('cc-themeLight').addEventListener('click',()=>{ S.theme='light'; save(); applyAll(); });
      bindToggle('cc-autoTheme','autoTheme');
      bindToggle('cc-blueTheme','blueTheme');
      bindToggle('cc-purpleTheme','purpleTheme');
      bindToggle('cc-orangeTheme','orangeTheme');
      document.getElementById('cc-schedSave').addEventListener('click',()=>{
        S.schedDark=document.getElementById('sched-dark').value; S.schedLight=document.getElementById('sched-light').value; save();
      });
      document.getElementById('cc-schedClear').addEventListener('click',()=>{ S.schedDark=''; S.schedLight=''; save(); });
      document.getElementById('cc-export').addEventListener('click',()=>{ navigator.clipboard.writeText(JSON.stringify(S,null,2)); alert('Copied'); });
      document.getElementById('cc-import').addEventListener('click',()=>{
        let j=prompt('Paste JSON:'); if(!j) return;
        try{ let d=JSON.parse(j); for(let k in d) if(DEF.hasOwnProperty(k)){ S[k]=d[k]; GM_setValue(k,d[k]); } applyAll(); }catch(e){ alert('Invalid'); }
      });
      bindToggle('cc-zen','zen');
      document.getElementById('cc-lang').addEventListener('click',()=>{ L = L==='en'?'tr':'en'; GM_setValue('lang',L); applyAll(); location.reload(); });
      document.getElementById('cc-resetAll').addEventListener('click',()=>{ if(confirm('Reset?')){ for(let k in DEF){ S[k]=DEF[k]; GM_setValue(k,DEF[k]); } applyAll(); } });
    }
  }

  function bindToggle(id, key){
    let el = document.getElementById(id); if(!el) return;
    el.addEventListener('click', ()=>{ S[key]=!S[key]; save(); applyAll(); updateToggle(id, key); });
  }

  function sort(type){
    let container = document.querySelector('.script-list, .scripts-container, #content');
    if(!container) return;
    let items = Array.from(container.querySelectorAll('.script-item, .script-list-item'));
    if(items.length<2) return;
    items.sort((a,b)=>{
      let get = el=>{
        if(type==='name'){ let t=el.querySelector('h2 a, .script-title a'); return t?t.textContent.trim().toLowerCase():''; }
        if(type==='date'){ let d=el.querySelector('time, .script-date'); return d?new Date(d.getAttribute('datetime')||d.textContent).getTime():0; }
        if(type==='rating'){ let r=el.querySelector('.rating, .script-rating'); return r?-parseFloat(r.textContent.replace(/[^0-9.]/g,''))||0:0; }
        if(type==='installs'){ let i=el.querySelector('.downloads, .total-installs'); return i?-parseInt(i.textContent.replace(/[^0-9]/g,''))||0:0; }
        return 0;
      };
      return get(a)-get(b);
    });
    items.forEach(item=>container.appendChild(item));
  }

  function quickTools(){
    let m=document.createElement('div'); m.style.cssText='position:fixed;bottom:140px;right:24px;background:var(--p-bgL);border:2px solid var(--p-gold);border-radius:16px;padding:8px;z-index:1200;box-shadow:var(--p-shadow);max-height:300px;overflow-y:auto';
    m.innerHTML = `<div class="elite-btn" id="qt-top">${_('top')}</div><div class="elite-btn" id="qt-copyTitle">${_('copyTitle')}</div><div class="elite-btn" id="qt-codeSrch">${_('codeSrch')}</div>`;
    document.body.appendChild(m);
    document.getElementById('qt-top').addEventListener('click',()=>{ window.scrollTo({top:0,behavior:'smooth'}); m.remove(); });
    document.getElementById('qt-copyTitle').addEventListener('click',()=>{ navigator.clipboard.writeText(document.title); m.remove(); });
    document.getElementById('qt-codeSrch').addEventListener('click',()=>{
      let q=prompt('Search code:'); if(!q) return;
      document.querySelectorAll('pre,code').forEach(el=>{
        el.innerHTML=el.innerHTML.replace(new RegExp('('+q.replace(/[.*+?^${}()|[\]\\]/g,'\\$&')+')','gi'),'<span style="background:#4a7db8;color:#fff;border-radius:3px">$1</span>');
      });
      m.remove();
    });
    setTimeout(()=>{ if(m.parentNode) m.remove(); },5000);
  }

  function updateStats(){
    let ex = document.getElementById('elite-stats');
    if(ex) ex.remove();
    if(!S.charCount && !S.wordCount && !S.readTime) return;
    let txt = document.body.innerText||'';
    let parts = [];
    if(S.charCount) parts.push('Chars: '+txt.length);
    if(S.wordCount) parts.push('Words: '+txt.split(/\s+/).length);
    if(S.readTime) parts.push('Read: ~'+Math.ceil(txt.split(/\s+/).length/200)+' min');
    let d=document.createElement('div'); d.id='elite-stats'; d.innerHTML=parts.join(' | ');
    document.body.appendChild(d);
  }

  function applyAll(){
    applyVars();
    fullCSS();
    document.documentElement.classList.toggle('reading-mode', S.reading);
    document.documentElement.classList.toggle('compact-mode', S.compact);
    document.documentElement.classList.toggle('high-contrast', S.contrast);
    document.documentElement.classList.toggle('zen-mode', S.zen);
    document.querySelectorAll('pre').forEach(pre=>{ pre.style.whiteSpace = S.wrap?'pre-wrap':'pre'; });
    addCopyButtons();
    highlightSearch();
    updateStats();
    if(S.extLinks) extLinks(true); else extLinks(false);
    if(S.installs) installsBadge(true); else installsBadge(false);
    if(S.author) authorBadge(true); else authorBadge(false);
    if(S.dates) dateBadge(true); else dateBadge(false);
  }

  function addCopyButtons(){
    if(!S.copyBtn) return;
    document.querySelectorAll('pre').forEach(pre=>{
      if(pre.querySelector('.elite-copy')) return;
      let btn=document.createElement('button'); btn.textContent='Copy'; btn.className='elite-copy';
      btn.style.cssText='position:absolute;top:8px;right:8px;padding:4px 10px;font-size:0.8rem;z-index:5;opacity:0.7';
      btn.addEventListener('click',()=>{ navigator.clipboard.writeText(pre.textContent).then(()=>{ btn.textContent='Copied!'; setTimeout(()=>btn.textContent='Copy',1500); }); });
      pre.style.position='relative'; pre.appendChild(btn);
    });
  }

  function highlightSearch(){
    if(!S.srchHl) return;
    let p=new URLSearchParams(window.location.search), q=p.get('q'); if(!q) return;
    let terms=q.split(/\s+/).filter(Boolean);
    document.querySelectorAll('.content, .main-content, #content, main, article').forEach(container=>{
      let walker=document.createTreeWalker(container, NodeFilter.SHOW_TEXT, null, false), nodes=[];
      while(walker.nextNode()) nodes.push(walker.currentNode);
      nodes.forEach(node=>{
        let html=node.textContent, changed=false;
        terms.forEach(term=>{
          let r=new RegExp('('+term.replace(/[.*+?^${}()|[\]\\]/g,'\\$&')+')','gi');
          if(r.test(html)){ html=html.replace(r,'<span style="background:#4a7db8;color:#fff;border-radius:3px">$1</span>'); changed=true; }
        });
        if(changed){ let s=document.createElement('span'); s.innerHTML=html; node.parentNode.replaceChild(s,node); }
      });
    });
  }

  function extLinks(enable){
    let id='elite-ext-style', el=document.getElementById(id);
    if(enable){
      if(!el){ el=document.createElement('style'); el.id=id; el.textContent='a[href^="http"]:not([href*="greasyfork.org"]){background:#4a7db8!important;color:#fff!important;padding:0 4px;border-radius:3px}'; document.head.appendChild(el); }
    }else{ if(el) el.remove(); }
  }

  function installsBadge(enable){
    document.querySelectorAll('.script-item, .script-list-item').forEach(item=>{
      let b=item.querySelector('.elite-install');
      if(enable){
        if(!b){ let d=item.querySelector('.downloads, .total-installs'); if(d){ b=document.createElement('span'); b.className='elite-install'; b.style.cssText='background:var(--p-acc);color:#fff;padding:2px 8px;border-radius:20px;font-size:0.75rem;margin-left:8px'; b.textContent=d.textContent.replace(/[^0-9]/g,'')+' installs'; let meta=item.querySelector('.script-info, .script-meta'); if(meta) meta.appendChild(b); } }
      }else{ if(b) b.remove(); }
    });
  }

  function authorBadge(enable){
    document.querySelectorAll('.script-item, .script-list-item').forEach(item=>{
      let b=item.querySelector('.elite-author');
      if(enable){
        if(!b){ let a=item.querySelector('.author a, .script-author a'); if(a){ b=document.createElement('span'); b.className='elite-author'; b.style.cssText='background:var(--p-accS);color:#fff;padding:2px 8px;border-radius:20px;font-size:0.75rem;margin-left:8px'; b.textContent=a.textContent.trim(); let meta=item.querySelector('.script-info, .script-meta'); if(meta) meta.appendChild(b); } }
      }else{ if(b) b.remove(); }
    });
  }

  function dateBadge(enable){
    document.querySelectorAll('.script-item, .script-list-item').forEach(item=>{
      let b=item.querySelector('.elite-date');
      if(enable){
        if(!b){ let t=item.querySelector('time, .script-date'); if(t){ b=document.createElement('span'); b.className='elite-date'; b.style.cssText='background:var(--p-acc);color:#fff;padding:2px 8px;border-radius:20px;font-size:0.75rem;margin-left:8px'; b.textContent=t.textContent.trim(); let meta=item.querySelector('.script-info, .script-meta'); if(meta) meta.appendChild(b); } }
      }else{ if(b) b.remove(); }
    });
  }

  function checkSchedule(){
    if(!S.schedDark && !S.schedLight) return;
    let now=new Date(), cur=now.getHours()*60+now.getMinutes();
    if(S.schedDark){
      let p=S.schedDark.split(':'), dh=+p[0], dm=+p[1];
      if(!isNaN(dh) && !isNaN(dm) && Math.abs(cur-(dh*60+dm))<=2 && S.theme!=='dark'){ S.theme='dark'; save(); applyAll(); }
    }
    if(S.schedLight){
      let p=S.schedLight.split(':'), lh=+p[0], lm=+p[1];
      if(!isNaN(lh) && !isNaN(lm) && Math.abs(cur-(lh*60+lm))<=2 && S.theme!=='light'){ S.theme='light'; save(); applyAll(); }
    }
  }
  setInterval(checkSchedule, 60000);

  function createStatsBar(){
    let bar=document.createElement('div'); bar.id='elite-bar';
    bar.style.cssText='position:fixed;bottom:0;left:0;right:0;background:var(--p-bgD);border-top:1px solid var(--p-border);padding:6px 16px;display:flex;justify-content:space-around;font-size:0.8rem;color:var(--p-muted);z-index:999';
    bar.innerHTML=`<span>${_('scripts')}: <b>${document.querySelectorAll('.script-item, .script-list-item').length}</b></span><span>${document.title.slice(0,30)}</span><span>${_('theme')}: ${S.theme}</span>`;
    document.body.appendChild(bar);
    setInterval(()=>{ let b=bar.querySelector('b'); if(b) b.textContent=document.querySelectorAll('.script-item, .script-list-item').length; },3000);
  }

  function init(){
    applyAll();
    createUI();
    createStatsBar();
    if(typeof GM_registerMenuCommand==='function'){
      GM_registerMenuCommand('Toggle Panel', ()=>{ radialOpen? (radialOpen=false, document.querySelectorAll('.elite-radial-item').forEach(e=>e.classList.remove('open'))) : (radialOpen=true, document.querySelectorAll('.elite-radial-item').forEach(e=>e.classList.add('open'))); });
      GM_registerMenuCommand('Toggle Dark/Light', ()=>{ S.theme=S.theme==='dark'?'light':'dark'; save(); applyAll(); });
      GM_registerMenuCommand(_('top'), ()=>window.scrollTo({top:0,behavior:'smooth'}));
    }
    new MutationObserver(()=>{
      addCopyButtons(); highlightSearch(); updateStats();
      if(S.extLinks) extLinks(true); if(S.installs) installsBadge(true); if(S.author) authorBadge(true); if(S.dates) dateBadge(true);
    }).observe(document.body, {childList:true, subtree:true});

    document.addEventListener('keydown', e=>{
      if(e.ctrlKey && e.shiftKey && e.key==='P'){ e.preventDefault(); radialOpen=!radialOpen; document.querySelectorAll('.elite-radial-item').forEach(el=>el.classList.toggle('open',radialOpen)); }
      if(e.ctrlKey && e.key==='k'){ e.preventDefault(); openDrawer(); }
      if(e.key==='Escape'){ radialOpen=false; document.querySelectorAll('.elite-radial-item').forEach(el=>el.classList.remove('open')); drawerOpen=false; document.getElementById('elite-drawer').classList.remove('open'); document.getElementById('elite-overlay').classList.remove('open'); if(autoScrollId){ clearInterval(autoScrollId); autoScrollId=null; } }
    });
  }

  if(document.readyState==='loading') document.addEventListener('DOMContentLoaded', init);
  else init();
})();