This snippet generates a Markdown link list from groups of tabs saved by the OneTab Chrome extension. You must run this snippet from the Chrome Developer Tools by right-clicking the page and choosing the Inspect option or hitting the F12
key. Copy the snippet and execute it in the console. Each group will be processed to generate Markdown for the list of links. The respective generated Markdown is placed in textarea
elements next to the OneTab tab group.
[...document.querySelectorAll('.tabGroup')].forEach(it => {
(it.style && (it.style.position = 'relative'));
var groupTitle = it.querySelector('.tabGroupTitleText').innerText.trim();
var contents = '## ' + groupTitle + '\n\n';
var links = [...it.querySelectorAll('a.tabLink')];
for(var i in links) {
var link = links[i];
contents += '* [' + link.innerText.trim() + '](' + link.href + ')\n';
}
var outputBox = it.querySelector('.dump');
(!outputBox && (outputBox = document.createElement('textarea')) && it.appendChild(outputBox));
outputBox.className = 'dump';
outputBox.setAttribute('rows', '4');
outputBox.setAttribute('cols', '80');
outputBox.style.position = 'absolute';
outputBox.style.top = 0;
outputBox.style.right = 0;
outputBox.value = contents;
});
Run this snippet in the Dev Tools console on the OneTab Chrome extension's list page to create a simple block with an H2 heading and a bulleted list of the link title and destination. Click on the block to select it and automatically copy it to the clipboard. This is great for pasting to other apps like Evernote and OneNote.
function selectText(node) {
(typeof(node) == 'string') && (node = document.getElementById(node));
if (document.body.createTextRange) {
const range = document.body.createTextRange();
range.moveToElementText(node);
range.select();
} else if (window.getSelection) {
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(node);
selection.removeAllRanges();
selection.addRange(range);
} else {
console.warn("Could not select text in node: Unsupported browser.");
}
}
[...document.querySelectorAll('.tabGroup')].forEach(it => {
(it.style && (it.style.position = 'relative'));
var outputBox = it.querySelector('.dumpLinks');
(!outputBox && (outputBox = document.createElement('div')) && it.appendChild(outputBox));
outputBox.className = 'dumpLinks';
outputBox.style.overflow = 'scroll';
outputBox.style.position = 'absolute';
outputBox.style.top = 0;
outputBox.style.right = 0;
outputBox.style.width = '25%';
outputBox.style.height = '100%';
outputBox.style.borderWidth = '1px';
outputBox.style.borderColor = 'blue';
delete outputBox.onclick;
outputBox.onclick = () => { selectText(outputBox); document.execCommand('copy'); };
var groupTitle = it.querySelector('.tabGroupTitleText').innerText.trim();
var contents = '<h2>' + groupTitle + '</h2><ul>';
var links = [...it.querySelectorAll('a.tabLink')];
for(var i in links) {
var link = links[i];
contents += '<li><a href="' + link.href + '">' + link.innerText.trim() + '</a></li>\n';
}
contents += '</ul>';
outputBox.innerHTML = contents;
});