יום שני, 30 ביוני 2025

תפריט שאלות של השיחה הנוכחית ChatGPT

קוד להוספת תפריט של כל השאלות שנשאלו בשיחה הנוכחית:

(() => {
  const style = document.createElement('style');
  style.textContent = `
    #floatingMenu {
      position: fixed;
      top: 100px;
      right: 10px;
      width: 270px;
      max-height: 400px;
      background: rgba(0,0,0,0.6);
      color: white;
      font-family: Arial, sans-serif;
      font-size: 14px;
      border-radius: 6px;
      box-shadow: 0 0 10px black;
      display: flex;
      flex-direction: column;
      user-select: none;
      z-index: 999999;
      overflow: hidden;
      transition: max-height 0.4s ease;
    }
    #floatingMenu.collapsed {
      max-height: 40px;
    }
    #floatingMenuHeader {
      padding: 8px 10px;
      background: rgba(0,0,0,0.8);
      cursor: move;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-weight: bold;
    }
    #floatingMenuTitle {
      flex-grow: 1;
    }
    #floatingMenuControls {
      display: flex;
      align-items: center;
    }
    #floatingMenuControls > button {
      cursor: pointer;
      margin-left: 10px;
      font-weight: bold;
      user-select: none;
      background: none;
      border: none;
      color: white;
      font-size: 16px;
      line-height: 1;
      padding: 0;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    #floatingMenuControls > button:focus {
      outline: 2px solid #fff;
      outline-offset: 2px;
    }
    #searchInput {
      margin: 0 10px;
      padding: 5px 8px;
      border-radius: 4px;
      border: none;
      font-size: 14px;
      width: calc(100% - 20px);
      box-sizing: border-box;
      max-height: 0;
      opacity: 0;
      pointer-events: none;
      transition: max-height 0.4s ease, opacity 0.4s ease, margin 0.4s ease;
      direction: rtl;
    }
    #searchInput.visible {
      max-height: 40px;
      opacity: 1;
      pointer-events: auto;
      margin: 5px 10px;
    }
    #floatingMenuList {
      padding: 5px 10px;
      transition: opacity 0.3s ease;
      flex-grow: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
    #floatingMenuList.scrollable {
      overflow-y: auto;
      max-height: 340px;
    }
    #floatingMenuList div {
      padding: 5px 8px;
      border-radius: 4px;
      margin-bottom: 4px;
      background: rgba(255,255,255,0.1);
      cursor: pointer;
      white-space: nowrap;
      text-overflow: ellipsis;
      /*overflow: hidden;*/
    }
    #floatingMenuList div:hover,
    #floatingMenuList div:focus {
      background: rgba(255,255,255,0.25);
      outline: none;
    }
    #floatingMenu.collapsed #searchInput,
    #floatingMenu.collapsed #floatingMenuList {
      opacity: 0;
      pointer-events: none;
      height: 0;
      padding: 0 10px;
      overflow: hidden !important;
      transition: opacity 0.4s ease, height 0.4s ease, padding 0.4s ease, margin 0.4s ease;
    }
  `;
  document.head.appendChild(style);

  // --- יצירת מבנה התפריט ---
  const menu = document.createElement('div');
  menu.id = 'floatingMenu';
  menu.setAttribute('role', 'region');
  menu.setAttribute('aria-label', 'תפריט שאלות');

  const header = document.createElement('div');
  header.id = 'floatingMenuHeader';
  header.setAttribute('role', 'banner');

  const title = document.createElement('div');
  title.id = 'floatingMenuTitle';
  title.textContent = 'שאלות';

  const controls = document.createElement('div');
  controls.id = 'floatingMenuControls';

  const toggleSearchBtn = document.createElement('button');
  toggleSearchBtn.id = 'toggleSearchBtn';
  toggleSearchBtn.setAttribute('aria-expanded', 'false');
  toggleSearchBtn.setAttribute('aria-controls', 'searchInput');
  toggleSearchBtn.setAttribute('aria-label', 'הצג או הסתר שדה חיפוש');
  toggleSearchBtn.textContent = '?';

  const collapseBtn = document.createElement('button');
  collapseBtn.id = 'collapseBtn';
  collapseBtn.setAttribute('aria-expanded', 'true');
  collapseBtn.setAttribute('aria-controls', 'floatingMenuList');
  collapseBtn.setAttribute('aria-label', 'הצג/הסתר תפריט');
  collapseBtn.textContent = '-';

  const closeBtn = document.createElement('button');
  closeBtn.id = 'closeBtn';
  closeBtn.setAttribute('aria-label', 'סגור תפריט');
  closeBtn.textContent = '×';

  //controls.appendChild(toggleSearchBtn);
  controls.appendChild(collapseBtn);
  controls.appendChild(closeBtn);
  header.appendChild(title);
  header.appendChild(controls);

  const searchInput = document.createElement('input');
  searchInput.id = 'searchInput';
  searchInput.type = 'search';
  searchInput.placeholder = 'חפש שאלות...';
  searchInput.setAttribute('aria-label', 'חיפוש שאלות');

  const listContainer = document.createElement('div');
  listContainer.id = 'floatingMenuList';
  listContainer.setAttribute('role', 'list');
  listContainer.setAttribute('tabindex', '0');
  listContainer.setAttribute('aria-live', 'polite');
  listContainer.setAttribute('aria-relevant', 'additions removals');

  menu.appendChild(header);
  menu.appendChild(searchInput);
  menu.appendChild(listContainer);
  document.body.appendChild(menu);

  // --- פונקציות עזר ---
  function isHebrewChar(char) {
    return /[\u0590-\u05FF]/.test(char);
  }

  function hasClassOrParentHasClass(el, className) {
    while (el) {
      if (el.classList && el.classList.contains(className)) {
        return true;
      }
      el = el.parentElement;
    }
    return false;
  }

  function getQuestions() {
    const qs = document.querySelectorAll('.whitespace-pre-wrap');
    const questions = [];
    qs.forEach((q, i) => {
      let len = 27;
      if (hasClassOrParentHasClass(q, 'text-page-header')) {
        return;
      }
      let text = q.textContent.trim().replace(/\s+/g, ' ');
      if (text.length > len) text = text.slice(0, len) + '…';
      questions.push({ el: q, text, index: i, fullText: q.textContent.trim() });
    });
    return questions;
  }

  let previousQuestionsJSON = null;

  function updateList() {
    const questions = getQuestions();
    const currentQuestionsJSON = JSON.stringify(questions.map(q => q.fullText));
    if (currentQuestionsJSON === previousQuestionsJSON) return;
    previousQuestionsJSON = currentQuestionsJSON;

    const searchTerm = searchInput.value.trim().toLowerCase();
    listContainer.innerHTML = '';

    const filtered = questions.filter(q => q.fullText.toLowerCase().includes(searchTerm));

    listContainer.classList.toggle('scrollable', filtered.length > 10);

    if (filtered.length === 0) {
      const noResultDiv = document.createElement('div');
      noResultDiv.textContent = 'לא נמצאו שאלות';
      noResultDiv.style.textAlign = 'center';
      noResultDiv.style.opacity = '0.7';
      listContainer.appendChild(noResultDiv);
      return;
    }

    filtered.forEach(({ el, text, index, fullText }) => {
      const item = document.createElement('div');
      item.setAttribute('role', 'listitem');
      item.setAttribute('tabindex', '-1');
      item.textContent = text || `שאלה ${index + 1}`;
      item.title = fullText;

      if (text && isHebrewChar(text[0])) {
        item.style.textAlign = 'right';
        item.style.direction = 'rtl';
      } else {
        item.style.textAlign = 'left';
        item.style.direction = 'ltr';
      }

      item.addEventListener('click', e => {
        e.preventDefault();
        el.scrollIntoView({ behavior: 'smooth', block: 'center' });
        el.style.transition = 'background-color 0.5s';
        const origBG = el.style.backgroundColor;
        el.style.backgroundColor = 'yellow';
        setTimeout(() => {
          el.style.backgroundColor = origBG || '';
        }, 1000);
      });

      item.addEventListener('keydown', e => {
        if (e.key === 'Enter' || e.key === ' ') {
          e.preventDefault();
          item.click();
        }
      });

      listContainer.appendChild(item);
    });
  }

  closeBtn.addEventListener('click', () => {
    menu.style.display = 'none';
  });

  collapseBtn.addEventListener('click', () => {
    const isCollapsed = menu.classList.toggle('collapsed');
    collapseBtn.textContent = isCollapsed ? '+' : '-';
    collapseBtn.setAttribute('aria-expanded', String(!isCollapsed));
  });

  toggleSearchBtn.addEventListener('click', () => {
    const visible = searchInput.classList.toggle('visible');
    toggleSearchBtn.setAttribute('aria-expanded', String(visible));
    if (visible) {
      searchInput.focus();
    } else {
      searchInput.value = '';
      updateList();
    }
  });

  let isDragging = false;
  let dragStartX, dragStartY, menuStartX, menuStartY;

  header.addEventListener('mousedown', e => {
    isDragging = true;
    dragStartX = e.clientX;
    dragStartY = e.clientY;
    const rect = menu.getBoundingClientRect();
    menuStartX = rect.left;
    menuStartY = rect.top;
    e.preventDefault();
  });

  window.addEventListener('mousemove', e => {
    if (!isDragging) return;
    let newX = menuStartX + (e.clientX - dragStartX);
    let newY = menuStartY + (e.clientY - dragStartY);

    const maxX = window.innerWidth - menu.offsetWidth - 10;
    const maxY = window.innerHeight - menu.offsetHeight - 10;
    if (newX > maxX) newX = maxX;
    if (newX < 0) newX = 0;
    if (newY > maxY) newY = maxY;
    if (newY < 0) newY = 0;

    menu.style.right = 'auto';
    menu.style.left = newX + 'px';
    menu.style.top = newY + 'px';
  });

  window.addEventListener('mouseup', () => {
    isDragging = false;
  });

  searchInput.addEventListener('input', () => {
    updateList();
  });

  listContainer.addEventListener('keydown', e => {
    const focusableItems = Array.from(listContainer.querySelectorAll('[role=listitem]'));
    if (focusableItems.length === 0) return;

    let currentIndex = focusableItems.indexOf(document.activeElement);

    if (currentIndex === -1) {
      if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
        e.preventDefault();
        focusableItems[0].focus();
      }
      return;
    }

    if (e.key === 'ArrowDown') {
      e.preventDefault();
      const nextIndex = (currentIndex + 1) % focusableItems.length;
      focusableItems[nextIndex].focus();
    } else if (e.key === 'ArrowUp') {
      e.preventDefault();
      const prevIndex = (currentIndex - 1 + focusableItems.length) % focusableItems.length;
      focusableItems[prevIndex].focus();
    }
  });

  // ---------------------------------
  // החלפת setInterval ב-MutationObserver
  // ---------------------------------
  const questionsContainer = document.body; // אפשר לשנות למיכל הספציפי שלך אם קיים

  const observer = new MutationObserver((mutationsList) => {
    let shouldUpdate = false;
    for (const mutation of mutationsList) {
      if (
        mutation.type === 'childList' ||
        mutation.type === 'characterData' ||
        mutation.type === 'subtree'
      ) {
        shouldUpdate = true;
        break;
      }
    }
    if (shouldUpdate) {
      updateList();
    }
  });

  observer.observe(questionsContainer, {
    childList: true,
    subtree: true,
    characterData: true,
  });

  // קריאה ראשונית לעדכון
  updateList();
})();

  
לחץ כאן כדי להעתיק את הקוד

קוד לשמירה בתור bookmark:

javascript:(()=>{const style=document.createElement('style');style.textContent=`#floatingMenu{position:fixed;top:100px;right:10px;width:270px;max-height:400px;background:rgba(0,0,0,0.6);color:white;font-family:Arial,sans-serif;font-size:14px;border-radius:6px;box-shadow:0 0 10px black;display:flex;flex-direction:column;user-select:none;z-index:999999;overflow:hidden;transition:max-height 0.4s ease;}#floatingMenu.collapsed{max-height:40px;}#floatingMenuHeader{padding:8px 10px;background:rgba(0,0,0,0.8);cursor:move;display:flex;justify-content:space-between;align-items:center;font-weight:bold;}#floatingMenuTitle{flex-grow:1;}#floatingMenuControls{display:flex;align-items:center;}#floatingMenuControls>button{cursor:pointer;margin-left:10px;font-weight:bold;user-select:none;background:none;border:none;color:white;font-size:16px;line-height:1;padding:0;display:flex;align-items:center;justify-content:center;}#floatingMenuControls>button:focus{outline:2px solid #fff;outline-offset:2px;}#searchInput{margin:0 10px;padding:5px 8px;border-radius:4px;border:none;font-size:14px;width:calc(100% - 20px);box-sizing:border-box;max-height:0;opacity:0;pointer-events:none;transition:max-height 0.4s ease,opacity 0.4s ease,margin 0.4s ease;direction:rtl;}#searchInput.visible{max-height:40px;opacity:1;pointer-events:auto;margin:5px 10px;}#floatingMenuList{padding:5px 10px;transition:opacity 0.3s ease;flex-grow:1;display:flex;flex-direction:column;overflow:hidden;}#floatingMenuList.scrollable{overflow-y:auto;max-height:340px;}#floatingMenuList div{padding:5px 8px;border-radius:4px;margin-bottom:4px;background:rgba(255,255,255,0.1);cursor:pointer;white-space:nowrap;text-overflow:ellipsis;}#floatingMenuList div:hover,#floatingMenuList div:focus{background:rgba(255,255,255,0.25);outline:none;}#floatingMenu.collapsed #searchInput,#floatingMenu.collapsed #floatingMenuList{opacity:0;pointer-events:none;height:0;padding:0 10px;overflow:hidden !important;transition:opacity 0.4s ease,height 0.4s ease,padding 0.4s ease,margin 0.4s ease;}`;document.head.appendChild(style);const menu=document.createElement('div');menu.id='floatingMenu';menu.setAttribute('role','region');menu.setAttribute('aria-label','תפריט שאלות');const header=document.createElement('div');header.id='floatingMenuHeader';header.setAttribute('role','banner');const title=document.createElement('div');title.id='floatingMenuTitle';title.textContent='שאלות';const controls=document.createElement('div');controls.id='floatingMenuControls';const toggleSearchBtn=document.createElement('button');toggleSearchBtn.id='toggleSearchBtn';toggleSearchBtn.setAttribute('aria-expanded','false');toggleSearchBtn.setAttribute('aria-controls','searchInput');toggleSearchBtn.setAttribute('aria-label','הצג או הסתר שדה חיפוש');toggleSearchBtn.textContent='?';const collapseBtn=document.createElement('button');collapseBtn.id='collapseBtn';collapseBtn.setAttribute('aria-expanded','true');collapseBtn.setAttribute('aria-controls','floatingMenuList');collapseBtn.setAttribute('aria-label','הצג/הסתר תפריט');collapseBtn.textContent='-';const closeBtn=document.createElement('button');closeBtn.id='closeBtn';closeBtn.setAttribute('aria-label','סגור תפריט');closeBtn.textContent='×';controls.appendChild(collapseBtn);controls.appendChild(closeBtn);header.appendChild(title);header.appendChild(controls);const searchInput=document.createElement('input');searchInput.id='searchInput';searchInput.type='search';searchInput.placeholder='חפש שאלות...';searchInput.setAttribute('aria-label','חיפוש שאלות');const listContainer=document.createElement('div');listContainer.id='floatingMenuList';listContainer.setAttribute('role','list');listContainer.setAttribute('tabindex','0');listContainer.setAttribute('aria-live','polite');listContainer.setAttribute('aria-relevant','additions removals');menu.appendChild(header);menu.appendChild(searchInput);menu.appendChild(listContainer);document.body.appendChild(menu);function isHebrewChar(c){return/[\u0590-\u05FF]/.test(c);}function hasClassOrParentHasClass(el,c){while(el){if(el.classList&&el.classList.contains(c))return true;el=el.parentElement;}return false;}function getQuestions(){const qs=document.querySelectorAll('.whitespace-pre-wrap');const questions=[];qs.forEach((q,i)=>{const len=27;if(hasClassOrParentHasClass(q,'text-page-header'))return;let text=q.textContent.trim().replace(/\s+/g,' ');if(text.length>len)text=text.slice(0,len)+'…';questions.push({el:q,text,index:i,fullText:q.textContent.trim()});});return questions;}let previousQuestionsJSON=null;function updateList(){const questions=getQuestions();const currentQuestionsJSON=JSON.stringify(questions.map(q=>q.fullText));if(currentQuestionsJSON===previousQuestionsJSON)return;previousQuestionsJSON=currentQuestionsJSON;const searchTerm=searchInput.value.trim().toLowerCase();listContainer.innerHTML='';const filtered=questions.filter(q=>q.fullText.toLowerCase().includes(searchTerm));listContainer.classList.toggle('scrollable',filtered.length>10);if(filtered.length===0){const noResultDiv=document.createElement('div');noResultDiv.textContent='לא נמצאו שאלות';noResultDiv.style.textAlign='center';noResultDiv.style.opacity='0.7';listContainer.appendChild(noResultDiv);return;}filtered.forEach(({el,text,index,fullText})=>{const item=document.createElement('div');item.setAttribute('role','listitem');item.setAttribute('tabindex','-1');item.textContent=text||`שאלה ${index+1}`;item.title=fullText;if(text&&isHebrewChar(text[0])){item.style.textAlign='right';item.style.direction='rtl';}else{item.style.textAlign='left';item.style.direction='ltr';}item.addEventListener('click',e=>{e.preventDefault();el.scrollIntoView({behavior:'smooth',block:'center'});const origBG=el.style.backgroundColor;el.style.backgroundColor='yellow';setTimeout(()=>{el.style.backgroundColor=origBG||'';},1000);});item.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();item.click();}});listContainer.appendChild(item);});}closeBtn.addEventListener('click',()=>{menu.style.display='none';});collapseBtn.addEventListener('click',()=>{const isCollapsed=menu.classList.toggle('collapsed');collapseBtn.textContent=isCollapsed?'+':'-';collapseBtn.setAttribute('aria-expanded',String(!isCollapsed));});toggleSearchBtn.addEventListener('click',()=>{const visible=searchInput.classList.toggle('visible');toggleSearchBtn.setAttribute('aria-expanded',String(visible));if(visible){searchInput.focus();}else{searchInput.value='';updateList();}});let isDragging=false,dragStartX,dragStartY,menuStartX,menuStartY;header.addEventListener('mousedown',e=>{isDragging=true;dragStartX=e.clientX;dragStartY=e.clientY;const rect=menu.getBoundingClientRect();menuStartX=rect.left;menuStartY=rect.top;e.preventDefault();});window.addEventListener('mousemove',e=>{if(!isDragging)return;let newX=menuStartX+(e.clientX-dragStartX);let newY=menuStartY+(e.clientY-dragStartY);const maxX=window.innerWidth-menu.offsetWidth-10;const maxY=window.innerHeight-menu.offsetHeight-10;if(newX>maxX)newX=maxX;if(newX<0 newx="0;if(newY">maxY)newY=maxY;if(newY<0 auto="" menu.style.left="newX+" menu.style.top="newY+" mouseup="" newy="0;menu.style.right=" px="" window.addeventlistener="">{isDragging=false;});searchInput.addEventListener('input',()=>{updateList();});listContainer.addEventListener('keydown',e=>{const focusableItems=Array.from(listContainer.querySelectorAll('[role=listitem]'));if(focusableItems.length===0)return;let currentIndex=focusableItems.indexOf(document.activeElement);if(currentIndex===-1){if(e.key==='ArrowDown'||e.key==='ArrowUp'){e.preventDefault();focusableItems[0].focus();}return;}if(e.key==='ArrowDown'){e.preventDefault();const nextIndex=(currentIndex+1)%focusableItems.length;focusableItems[nextIndex].focus();}else if(e.key==='ArrowUp'){e.preventDefault();const prevIndex=(currentIndex-1+focusableItems.length)%focusableItems.length;focusableItems[prevIndex].focus();}});const questionsContainer=document.body;const observer=new MutationObserver(mutationsList=>{let shouldUpdate=false;for(const mutation of mutationsList){if(mutation.type==='childList'||mutation.type==='characterData'||mutation.type==='subtree'){shouldUpdate=true;break;}}if(shouldUpdate){updateList();}});observer.observe(questionsContainer,{childList:true,subtree:true,characterData:true});updateList();})();

  
  1. לחץ כאן כדי להעתיק את הקוד
  2. לחץ ctrl+d
  3. שנה את שם הסימניה, ובמקום כתובת, הדבק את הטקסט שהעתקת בסעיף 1


אין תגובות:

הוסף רשומת תגובה