K-Meleon

KMeleonWiki > Resources > MacroLibrary > MacroLibrary2 > del.icio.us luamacros

Submitted by: rstlne



Notes:

Macros for posting a bookmark to del.icio.us, a social bookmarks manager. The title and url are taken from the current page and the form for posting to del.icio.us will open up in a new window or tab or layer.

Hit F12 to post to del.icio.us.
Hit Shift-F12 to set the del.icio.us user name.
F12 will also prompt you for the del.icio.us user name if you haven't previously set one up.

Also accessible from the document popup menu. Accelerator definitions below may be omitted if not needed.

This is a luamacros version of the original del.icio.us macros. The luamacros plugin is required. This plugin can be found in K-MeleonCCF 0.04 Beta3 and later.

The main advantages to using this luamacros version are:

  • Lua code is easier to read and maintain.
  • The code should be able to handle weird characters in the web page title and URL better.


Save as delicious.lua:

-- Lua Macros for bookmarking a page with del.icio.us

local depref = "kmeleon.general.deliciousUser"

local function EE(str)
    return encode(EncodeUTF8(str))
end

local function GotoNew(hwnd, url)
    NavigateTo(url, OPEN_NEW, hwnd)
end

function SetDelicious(hwnd)
    local username = prompt(hwnd, "Set del.icio.us username to: ",
        "del.icio.us setup") or ""
    if username ~= "" then
        setpref(TYPE_STRING, depref, username)
    end
    return username
end

local function RunDelicious(hwnd, username)
    local title, url = GetDocInfo(hwnd)
    url = url or ""
    if title == nil or title == "" then
        title = url
    end
    GotoNew(hwnd, "http://del.icio.us/" .. EE(username) .. 
        "?v=3&jump=bookmarks&url=" .. EE(url) .. "&title=" .. EE(title))
end

function Delicious(hwnd)
    local username = getpref(TYPE_STRING, depref) or ""
    if username == "" then
        username = SetDelicious(hwnd)
    end
    if username ~= "" then
        RunDelicious(hwnd, username)
    end
end


In macros.lua:

require "copyaslink"
require "google"
require "multiclip"
require "groups"
require "search"
require "search_add"
require "delicious"


In Menus:

Delicious{
 %ifplugin luamacros
 luamacros(Delicious, Post to del.icio.us)
 luamacros(SetDelicious, Setup del.icio.us user name)
 %endif
}
DocumentPopup{
 !Nav
 -
 macros(URL, Go to URL)
 macros(sendhotkey, Send this page to hotkey)
 !Save
 !Selected
 -
 !View Page
 !Fullscreen
 -
 !Delicious
}

FrameDocumentPopup{
 !Nav
 -
 macros(URL, Go to URL)
 macros(sendhotkey, Send this page to hotkey)
 !Save
 !Selected
 -
 :Frame
 -
 !View Page
 !Fullscreen
 -
 !Delicious
}


In Accelerators:

# --- del.icio.us hotkeys ---

%ifplugin luamacros
VK_F12 = luamacros(Delicious)
SHIFT VK_F12 = luamacros(SetDelicious)
%endif

# --- End del.icio.us hotkeys ---


Comments & Questions

K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.