Skip to content

Instantly share code, notes, and snippets.

@spencerpogo
Last active May 1, 2024 05:19
Show Gist options
  • Save spencerpogo/cc04082a57030f245ff1e6171cccf59f to your computer and use it in GitHub Desktop.
Save spencerpogo/cc04082a57030f245ff1e6171cccf59f to your computer and use it in GitHub Desktop.
Firefox query YouTube tabs

How to use

  1. Have devtools.chrome.enabled enabled in your about:config
  2. Press Ctrl + Shift + J to open the browser console
  3. Run snippet.js in the resulting console
  4. The result will be a list of [title, videoId] tuples
  5. You can use this no-dependency, synchronous script to export the result to a CSV Using clipboard to enter it makes the console lag, so you can fetch then eval it:
    eval(await (await fetch("https://raw.githubusercontent.com/adaltas/node-csv/master/packages/csv-stringify/dist/iife/sync.js")).text())
    then use it like so:
    copy(csv_stringify_sync.stringify(records))
    the copy() function will grab the result to your clipboard

What does the snippet do?

  1. Go through all your tabs (gBrowser.tabs)
  2. Filter out YouTube tabs by running an overcomplicated RegEx I found on Stack Overflow on the tab's URL, which is found in tabObject.linkedBrowser.currentURI.displaySpec. This also extracts the video ID regardless of URL format.
  3. Remove notification count (like (1) title) from the title found in tabObject.label
  4. Remove the trailing - YouTube from the end of the title
gBrowser.tabs.map(t => [t, /^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(?:-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|live\/|v\/)?)([\w\-]+)(\S+)?$/gm.exec(t?.linkedBrowser?.currentURI?.displaySpec)]).filter(([t, m]) => m !== null).map(([t, m]) => [t.label.replace(/^\(\d+\) (.+)$/gm, "$1").replace(/ - YouTube$/gm, ""), m[5]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment