Duker

Basic port of Opera's tab traces for Vivaldi

Nov 15th, 2026 (edited)
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.19 KB | Source Code | 0 0
  1. (function tabTraces() {
  2.    const TRACE_LENGTH = 5; // How many tabs to mark as recently visited
  3.    const THICKNESS_PX = 2; // How thick the marker is, in pixels
  4.    const TAB_LIMIT = 15;   // Only mark tabs if there are at least this many in the window
  5.  
  6.    let recentTabIDs = [];
  7.    let myWindowId = null;
  8.  
  9.    let styleElement = document.createElement('style');
  10.    document.head.appendChild(styleElement);
  11.  
  12.    async function generateStyleRulesForRecentTabs() {
  13.       let tabs = await chrome.tabs.query({ windowId: myWindowId });
  14.       if (tabs.length < TAB_LIMIT) {
  15.          styleElement.textContent = "";
  16.          return;
  17.       }
  18.  
  19.       styleElement.textContent =
  20.          recentTabIDs
  21.             .slice(1, TRACE_LENGTH + 1) //Skip first i.e active tab
  22.             .map((id, i) => {
  23.  
  24.                let alpha = (0.78 ** i).toFixed(2);
  25.  
  26.                return `#tab-${id} {
  27.                         border-bottom: ${THICKNESS_PX}px solid rgba(255, 255, 255, ${alpha}) !important;
  28.                         border-radius: var(--currentRadius) var(--currentRadius) ${THICKNESS_PX}px ${THICKNESS_PX}px !important;
  29.                      }`;
  30.             }).join('\n');
  31.    }
  32.  
  33.    function removeTabFromRecent(tabId) {
  34.       recentTabIDs = recentTabIDs.filter(id => id !== tabId);
  35.    }
  36.  
  37.    function onActivated({ tabId, windowId }) {
  38.       if (windowId !== myWindowId) return;
  39.  
  40.       removeTabFromRecent(tabId);
  41.       recentTabIDs.unshift(tabId);
  42.  
  43.       recentTabIDs = recentTabIDs.slice(0, TRACE_LENGTH + 1); //Removes traces above the limit
  44.  
  45.       generateStyleRulesForRecentTabs();
  46.    }
  47.  
  48.    function onRemoved(tabId) {
  49.       removeTabFromRecent(tabId)
  50.       generateStyleRulesForRecentTabs();
  51.    }
  52.  
  53.    function init() {
  54.       if (!document.getElementById('browser')) {
  55.          return setTimeout(init, 250);
  56.       }
  57.  
  58.       chrome.windows.getCurrent(win => {
  59.          myWindowId = win.id;
  60.          chrome.tabs.query({ active: true, windowId: myWindowId }, tabs => {
  61.             if (tabs[0]) recentTabIDs.unshift(tabs[0].id);
  62.          });
  63.  
  64.          chrome.tabs.onActivated.addListener(onActivated);
  65.          chrome.tabs.onRemoved.addListener(onRemoved);
  66.       });
  67.    }
  68.  
  69.    init();
  70. })();
Tags: vivaldi
Advertisement
Add Comment
Please, Sign In to add comment