Question

I've created a javascript bookmarklet that gets the current page's title and URL, using the following code:

//Check to see if jQuery is already loaded
if (typeof jQuery == 'undefined') {
    var jQ = document.createElement('script');
    jQ.type = 'text/javascript';
    jQ.onload=runthis;
    jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
    document.body.appendChild(jQ);
} else {
    runthis();
}

// main Javascript function
function runthis() {
    title = document.title;
    url = document.URL;
    tag = "customTag";

    alert("Added to paperclip: Page Title: "+title+" | URL: "+url);
}

I now want to take that info and add it as a bookmark on my Delicious account. How do I go about this with Javascript/jQuery? I've taken a look at the API documentation but am having trouble getting my head around it (completely new to this, and OAuth makes my head spin), and can't find any full code examples to tinker with.

Would really appreciate any help/examples.

Was it helpful?

Solution

Edit:

You may want to look at this previous question. - "I want to create a Delicious bookmarklet in Firefox that bookmarks the current page with a predefined tag."


Well, an example that does exactly what you want by using a bookmarklet in your browser's toolbar is the delicious bookmarklet. It gather information from the page, displays the info in a popup, allowing you to edit it, and then stores it to your account:

http://delicious.com/help/bookmarklets

javascript:(function(){
    f= 'http://delicious.com/save?url=' 
    + encodeURIComponent(window.location.href)
    + '&title='+encodeURIComponent(document.title)
    + '&v=5&';
    a=function(){
        if( !window.open(
            f + 'noui=1&jump=doclose',
            'deliciousuiv5',
            'location=yes,
            links=no,scrollbars=no,
            toolbar=no,width=550,height=550'))location.href=f + 'jump=yes'
    };
    if(/Firefox/.test(navigator.userAgent)){
        setTimeout(a,0)
    } else {
      a()
    }
})()

If you use your Yahoo ID to log in, you do have to use OAuth, but if you don't, you can use the V1 api like this (from this page, worked for me in Chrome):

javascript:(

    function()
    {
        location.href = 'https://user:pwd@api.del.icio.us/v1/posts/add?url=' 
            + encodeURIComponent(window.location.href)
            + '&description=' + encodeURIComponent(document.title)   
            + '&tags=obvioustesttag';
    }

)()

Make sure to search your tags for "obvioustesttag" since it doesn't show up in the chronological list immediately.

Try to create a regular login or new account if you currently use YahooID to sign in, otherwise, you'll have to deal with OAuth.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top