Create list of links based on all open tabs

Well… I couldn’t help myself. Here’s some hacky code to produce this list. You may need to update it to filter out things you don’t want.

Save it as a Templater template.

<%* 
const dv = app.plugins.plugins.dataview.api; 

let tabHtmlElements = document.getElementsByClassName("workspace-tab-header")

let tabText = Array.from(tabHtmlElements)
	.map((tab) => (tab.textContent.trim()))
	.filter((name) => {
		// Filter out non-note tabs...
		
		let stardardTabNames = ["Files", "Search", "Starred", "Tags"]
		let isStandardTab = stardardTabNames.includes(name)
		
		let pluginTabNames = ["Advanced Tables", "Commander"] 
		let isPlugin = pluginTabNames.includes(name)

		let standardTabPrefixes = [
			"Outline of ", 
			"Backlinks for ",
			"Graph of "
		]
		let hasPrefix = standardTabPrefixes.some((element) => name.startsWith(element))

		let isBlank = name === "" 

		let shouldKeep = !isStandardTab 
			&& !isPlugin
			&& !hasPrefix
			&& !isBlank
			
		return shouldKeep;
	})

let uniqueTabs = [...new Set(tabText)];
let tabHeadingLinks = uniqueTabs.map( (item) => dv.fileLink(item))

tabHeadingLinks.map((tabLink) => (tR += tabLink + "\n"))
%>

Here’s a screenshot of it working…

3 Likes