Skip to content

Instantly share code, notes, and snippets.

@bkataru
Last active March 20, 2025 20:56
Show Gist options
  • Select an option

  • Save bkataru/b0407a259b40eaa89bb4baf404ffcc3b to your computer and use it in GitHub Desktop.

Select an option

Save bkataru/b0407a259b40eaa89bb4baf404ffcc3b to your computer and use it in GitHub Desktop.
smol JS script to export OneTab links with additional useful metadata (tab count, creation timestamp, tab names), to use: go to OneTab page -> open DevTools (F12) -> open Console -> type "allow pasting" to disable XSS protection -> paste this script and press enter
let tabGroups = document.getElementsByClassName('tabGroup');
const headerTemplatizer = (tabCount, timestamp) => `
---
## ${tabCount}
> ${timestamp}
`;
const tabTemplatizer = (textContent, href) => `[${textContent}](${href})`;
function parseTabGroup(tabGroup) {
let tabGroupString = '';
const [headerElem, tabListElem] = tabGroup.children;
const [tabCount, timestamp] = headerElem.innerText.split('\n').slice(0, 2);
tabGroupString += headerTemplatizer(tabCount, timestamp);
for (let tab of tabListElem.children) {
const {textContent, href} = tab.getElementsByTagName('a')[0];
tabGroupString += tabTemplatizer(textContent, href) + '\n'
}
return tabGroupString;
}
let compiled = '';
for(let tg of tabGroups) {
const tgs = parseTabGroup(tg);
compiled += tgs;
}
console.log(compiled);
copy(compiled);
console.log("copied tab groups to clipboard ✅");
// functional version (cuz we like purity, immutability, composition, currying, and allat)
let tabGroups = document.getElementsByClassName('tabGroup');
const headerTemplatizer = (tabCount, timestamp) => `
---
## ${tabCount}
> ${timestamp}
`;
const tabTemplatizer = (textContent, href) => `[${textContent}](${href})`;
const compiled = [...document.getElementsByClassName('tabGroup')].reduce((compiledAcc, tabGroup) => {
const [headerElem, tabListElem] = tabGroup.children;
const [tabCount, timestamp] = headerElem.innerText.split('\n').slice(0, 2);
let tabGroupString = [...tabListElem.children].reduce((tabGroupStringAcc, tab) => {
const {textContent, href} = tab.getElementsByTagName('a')[0];
return tabGroupStringAcc + tabTemplatizer(textContent, href) + '\n';
}, headerTemplatizer(tabCount, timestamp));
return compiledAcc + tabGroupString;
}, '');
console.log(compiled);
copy(compiled);
console.log("copied tab groups to clipboard ✅");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment