Change font size
It is currently Sat Dec 15, 2018 2:22 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 1 post ]
Author Message
 Post subject: URL Bookmark Script
PostPosted: Wed Apr 27, 2011 3:14 pm 
OSG Elite

Joined: Wed Aug 05, 2009 1:59 am
Posts: 417
Hi all,
Something I've found on the web that could be useful, an URL Bookmark HUD.
It controls a HUD in which the user can store and access notecards containing bookmarked URLs. On touch, a dialog box offers the user up to 21 bookmarks and the option to advance to another card in Contents. Selecting a bookmark opens it in the user's default browser.

Just put the following script in a prim, add a notecard with the following information: Label | URL (See sample notecard below the script.) and attach the prim to a HUD attach-point.

{L_CODE}:
// Bookmark URLs -- Rolig Loon -- January 2010
//  Free to copy, use, modify, distribute, or sell, with attribution. Be nice, please.
//    (C)2010 (CC-BY) [ http://creativecommons.org/licenses/by/3.0 ]   
//   Rolig Loon [ https://wiki.secondlife.com/wiki/User:Rolig_Loon ] 
//  All usages must contain a plain text copy of the previous 2 lines. 

list MENU1 = [];
list MENU2 = [];
list Choice = [];
list URLs = [];
integer listener;
integer MENU_CHANNEL = 1000;
key user;
string gName;
key gQueryID;
integer gLine;
integer Lines;
integer cardNo = 0;
integer Reading = FALSE;

Dialog(key id, list menu)
{
    llListenRemove(listener);
    listener = llListen(MENU_CHANNEL, "", "", "");
    llDialog(id, "Select one bookmark below: ", menu, MENU_CHANNEL);
}

ResetLists()
{
    Choice = [];
    URLs = [];
    Lines = 0;
    gLine = 0;
    gName = llGetInventoryName(INVENTORY_NOTECARD,cardNo);
    llListenRemove(listener);
}

BuildMenu()
{
    integer i = 0;
    MENU1 = [];
    MENU2 = [];
    if (Lines <= 11)
    {
        for (; i < Lines; ++i)
        {
             MENU1 += llList2String(Choice,i);
        }
        for (i=0;i<llGetListLength(MENU1);i+=3)
        {
            MENU1 = llListInsertList(llDeleteSubList(MENU1, -3, -1), llList2List(MENU1, -3, -1), i);
        }
        MENU1 += "New Card?";
    }
    else
    {
        for (; i < 11; ++i)
        {
            MENU1 += llList2String(Choice,i);
        }
        if(Lines > 21)
        {
            Lines = 21;
        }
        for (; i < Lines; ++i)
        {
            MENU2 += llList2String(Choice,i);
        }
        MENU1 += ">>";
        for (i=0;i<llGetListLength(MENU1);i+=3)
        {
            MENU1 = llListInsertList(llDeleteSubList(MENU1, -3, -1), llList2List(MENU1, -3, -1), i);
        }
        MENU2 += "<<";
        MENU2 += "New Card?";
        for (i=0;i<llGetListLength(MENU2);i+=3)
        {
        MENU2 = llListInsertList(llDeleteSubList(MENU2, -3, -1), llList2List(MENU2, -3, -1), i);
        }
    }
    user = llDetectedKey(0);
}

default
{
    state_entry()
    {
        if (Reading)
        {
            Reading = FALSE ;
        }
        else
        {
            if (llGetInventoryNumber(INVENTORY_NOTECARD) < 1)
            {
                llOwnerSay("There's no notecard in this device.");
            }
            else
            {
                gLine = 0;
                gName = llGetInventoryName(INVENTORY_NOTECARD,cardNo);
                state reading;
            }
        }
    }

    on_rez(integer num)
    {
        llResetScript();
    }

    touch_start(integer total_number)
    {
        BuildMenu();
        Dialog(user, MENU1);
    }

    listen(integer channel, string name, key id, string message)
    {
        if (channel == MENU_CHANNEL)
        {
            llListenRemove(listener);
            if (message == ">>")
            {
                Dialog(id, MENU2);
            }
            else if (message == "<<")
            {
                Dialog(id, MENU1);
            }
            else if (message == "New Card?")
            {
                ++ cardNo;
                if(llGetInventoryNumber(INVENTORY_NOTECARD) == cardNo)
                {
                    llOwnerSay("You have sampled all notecards in inventory. Returning to card #1.");
                    cardNo = 0;
                }
                ResetLists();
                state reading ;
            }
            else
            {
                integer URLNum = llListFindList(Choice,[message]);
                if (URLNum != -1)
                {
                    string theURL = llList2String(URLs,URLNum);
                    llLoadURL(id,"This is the web page you bookmarked as \""+ message + "\".", theURL);
                }
                else
                {
                    llOwnerSay("No bookmarked URL found with the label \"" + message +"\".");
                }
            }
        }
    }

    changed (integer change) 
    {
        if (change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }
}

state reading
{
    on_rez(integer num)
    {
        llResetScript();
    }

    state_entry()
    {
        Reading = TRUE ;
        gQueryID = llGetNotecardLine(gName,gLine);
    }

    dataserver(key query_id, string data)
    {
        if (query_id == gQueryID)
        {
            if(data != EOF)
            {
                if ( llGetSubString(data, 0, 0) != "#" && llStringTrim(data, STRING_TRIM) != "" )
                {
                    Choice += llStringTrim(llGetSubString(data,0,llSubStringIndex(data,"|")-1),STRING_TRIM);
                    URLs += llStringTrim(llGetSubString(data,llSubStringIndex( data,"|")+1,-1),STRING_TRIM);
                    ++Lines;
                }
                ++gLine;
                gQueryID = llGetNotecardLine(gName, gLine);
            }
            else
            {
                state default ;
            }
        }
    }

    changed (integer change) 
    {
        if (change & CHANGED_INVENTORY)
        {
            llResetScript();
        }
    }

}


Sample notecard:
{L_CODE}:
# Sample notecard for the "Bookmark URLs" HUD

# Any blank line or a line starting with "#" is ignored. You cannot write to a notecard with a script in SL, so the only
#   way to store bookmarks is to add them to this card manually. Yes, it's annoying, but it's not difficult, especially
#   if you cut and paste the URL. 

# Each line on this card starts with a tag for a bookmark, followed by a "|" symbol, and then by the URL itself.
# Only about 12 characters of the tag will fit on a dialog button. Extra characters will not be displayed.
# A tag longer than 24 characters will generate an error message.
SLGuitarmuseum | http://www.slguitarmuseum.com
OSGrid | http://www.osgrid.org
OSGrid Downloads | http://www.osgrid.org/index.php/downloads
OSGrid Forums | http://forums.osgrid.org/
CGSpeed | http://sites.google.com/a/cgspeed.com/cgspeed/motion-capture/
DaveDub.co.uk | http://davedub.co.uk/bvhacker/
Imprudence Blog | http://blog.kokuaviewer.org/
SLLVR wiki  | http://sites.google.com/site/sllvrwiki/index
AVL Catalog | http://sixsunflowers.wiki.zoho.com/
Wikipedia | http://wikipedia.org/
SLED resources | http://simteach.com/sled/db/
SimTeach | http://www.simteach.com/wiki/index.php?title=Second_Life_Education_Wiki
Natalia | http://www.mermaiddiaries.com/2006/11/build.html
Windlight | http://secondsoigne.wordpress.com/2008/04/10/optimising-windlight-for-avatars-20/?
LSL Portal |http://wiki.secondlife.com/wiki/LSL_Portal
LSL Wiki | http://lslwiki.net/lslwiki/wakka.php?wakka=HomePage


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 1 post ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net