Difference between revisions of "User talk:Rolig Loon/Bookmark URLs"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
Line 49: Line 49:
=== Script  ===
=== Script  ===


<lsl>// Bookmark URLs -- Rolig Loon -- January 2010
<source lang="lsl2">// Bookmark URLs -- Rolig Loon -- January 2010
//
//
// Controls a HUD in which the user can store and access notecards containing bookmarked URLs.
// Controls a HUD in which the user can store and access notecards containing bookmarked URLs.
Line 264: Line 264:


}
}
</lsl>
</source>

Latest revision as of 18:29, 24 January 2015

Features

  • Reads URLs and labels from a user-created notecard
 * Each card may hold up to 21 URLs. 
 * User may place an unlimited number of notecards in contents. User may advance to the next card 
   by selecting that choice from a dialog button.
  • Generates a dialog box with button labels from the notecard
  • User selects URL from a dialog button to open the in-world browser and navigate to the web site

NOTE: You cannot create or edit a notecard with a script in LSL, so you must so that operation manually.

 You may either create a notecard and then drop it in your HUD's contents, or edit an existing card by
 selecting the HUD in Edit and then Opening a card that is already in contents. 

Sample Notecard

# 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.

# Here are some sample bookmarks

Second Life | http://secondlife.com
SL Toolbox | http://wiki.secondlife.com/wiki/Basic_Resource_Toolbox
G Scholar | http://scholar.google.com/
Babelfish | http://babelfish.yahoo.com/
SLLVR wiki  | http://sites.google.com/site/sllvrwiki/index
AVL Catalog | http://sixsunflowers.wiki.zoho.com/
NY Times  | http://www.nytimes.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

# You may store up to 21 bookmarks on a single card. When you have collected more than 21 bookmarks, start a new notecard.
# You may put as many notecards in the HUD's inventory as you wish.  The HUD will load the next notecard in inventory 
#   when you select the "New Card?" button from the dialog menu.
# Suggestion: You may want to use this multi-card feature as a way to organize your bookmarks by using each notecard 
#   as a separate "folder".

Script

// Bookmark URLs -- Rolig Loon -- January 2010
//
// 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.

//  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();
        }
    }

}