Tab Sets - Save as regular bookmars

179 views
Skip to first unread message

santisg

unread,
Dec 16, 2019, 8:28:28 AM12/16/19
to Pinboard
Hi everyone,

I found a way to save all opened tabs as regular bookmarks, not as tab sets.

Basically what I've done is download the source code of the official "Pinboard Tools" chrome extension and add some code to the "popup.js" and "popup.html" files.

There are two new options: "Save tabs current window" and "Save tabs all windows".

Both options prompts the user for tags and then saves all tabs as regular Pinboard bookmarks with the tags provided by the user.

This link has helped me a lot leading with chrome extensions since it was my first time with them:

@maciej if you are still alive would you be so kind to add them to the official extension? I'm too lazy to create a new one :)

Here is the code of "popup.js":

var BASE_URL = 'https://pinboard.in';

document.addEventListener('DOMContentLoaded', function() {
      
    var link = document.getElementById('save_tabs_current_window');
    link.addEventListener('click', function() {
        save_tabs_current_window();
    });

    link = document.getElementById('save_tabs_all_windows');
    link.addEventListener('click', function() {
        save_tabs_all_windows();
    });
});

function save_tabs_current_window()
{
var tag = prompt("Enter tags (optional)");
if (tag != null) 
{
chrome.tabs.getAllInWindow(null, function(ctabs)
{
for (var j = 0; j < ctabs.length; j++) 
{
var t = ctabs[j];
if (t.url) 
{
var dest_url = BASE_URL + "/add?";
dest_url += "url=" + encodeURIComponent(t.url);
dest_url += '&title=' + encodeURIComponent(t.title);
dest_url += '&tags=' + encodeURIComponent(tag);
dest_url += '&later=yes&noui=yes&jump=close';
var http = new XMLHttpRequest();
http.open('POST', dest_url, true);
http.send();
}
}
});
}
}

function save_tabs_all_windows()
{
var tag = prompt("Enter tags (optional)");
if (tag != null) 
{
chrome.runtime.sendMessage("get_windows", function(w)
{
var chromewins = w.windows;
for (var i = 0; i < chromewins.length; i++) 
{
var ctabs = chromewins[i].tabs;
for (var j = 0; j < ctabs.length; j++) 
{
var t = ctabs[j];
if (t.url) 
{
var dest_url = BASE_URL + "/add?";
dest_url += "url=" + encodeURIComponent(t.url);
dest_url += '&title=' + encodeURIComponent(t.title);
dest_url += '&tags=' + encodeURIComponent(tag);
dest_url += '&later=yes&noui=yes&jump=close';
var http = new XMLHttpRequest();
http.open('POST', dest_url, true);
http.send();
}
}
}   
});
}
}
Reply all
Reply to author
Forward
0 new messages