Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Bucky's Web Browser 0.3

bucky Barkley
Registered User
Join date: 15 May 2006
Posts: 200
08-22-2006 18:56
This is a dialog and chat driven web page launcher. It feels much
like my radio (multiple dialog screens, search).

- easy configuration
- dialogs with extended web page descriptions, prev & next pages
- chat commands (launch page, list current chunk, list all, prev & next chunks)

Two files:
Web page launcher
urls

You'll see more of this UI in my upcoming texture chooser ;-)

Create an object. Toss the script into the object. Toss the sample url
file into the object as "urls". Salt to taste. Send me questions and comments.

chat commands on channel 33:

>>, next - next chunk of sites
<<, prev - prev chunk of sites
ls, list - list current chunk of sites (as in, capturing to chat history)
la, listall - list all sites
s - seach

sample search: "/33 s apple"

CODE

// -- Bucky's Web Browser 0.3
// Bucky.Barkley@gmail.com - August 2006

// which notecard would you like to use?
string notecard = "urls";

integer chatChannel = 33;
integer dialogChannel = 34;

string HELP_MSG = "touch for web dialog, or use ch 33 to get web pages (example \"/33 3\")";

list allLocations;
list allLocationDesc;
list theLocations;

key avKey;

integer linenum = 0;
integer curLocationOffset = 0;
integer locationChunk = 6;
integer curLocationEnd = 5;
integer totalLocations = 0;
integer dialogActive = 0;
integer curIdx = -1;
string dispLocationStr = "";

string NEXT_MSG = "Next >>";
string PREV_MSG = "<< Prev";
string LIST_MSG = "List";

string CUR_SET = "c";
string ALL_SET = "a";

list cmdNextChunk = [">>", "next", "Next", NEXT_MSG];
list cmdPrevChunk = ["<<", "prev", "Prev", PREV_MSG];
list cmdLsCur = ["ls", "list", LIST_MSG];
list cmdLsAll = ["la", "listall"];
list cmdSearch = ["s", "search"];

string newLocation;
string newDesc;

//-----------------------

reset_wb() {
llSetText("starting web browser ....",
<1,0,0>, 1.0 );
llListen(chatChannel, "", "", "");
curLocationOffset = 0;
curLocationEnd = 5;
linenum = 0;
dialogActive = 0;
allLocations = [];
allLocationDesc = [];
totalLocations = 0;
curIdx = -1;
dispLocationStr = "";
llGetNotecardLine(notecard, linenum);
}

add_location(string line) {
list words = llParseString2List(line, [" ", " ", "="], []);
if (llGetListLength(words) < 2) {
return;
}
string location = llList2String(words, llGetListLength(words) - 1);
string locationDesc = "";
integer i;

for (i = 0; i<llGetListLength(words) - 1; i++) {
if (llStringLength(location) > 0) {
locationDesc += " ";
}
locationDesc += llList2String(words, i);
}

allLocations += [location];
allLocationDesc += [locationDesc];
}


curLocations() {
theLocations = [PREV_MSG, LIST_MSG, NEXT_MSG];

integer i;
dispLocationStr = "";

for (i = curLocationOffset; i <= curLocationEnd; i++) {
if (curIdx == i) {
dispLocationStr += "*";
} else {
dispLocationStr += " ";
}
dispLocationStr += (string) (i + 1) + ") ";
dispLocationStr += llList2String(allLocationDesc, i);
dispLocationStr += "\n";

theLocations += (string)(i + 1);
}
}


doNextSet() {
curLocationOffset += locationChunk;
curLocationEnd = curLocationOffset + (locationChunk - 1);

if (curLocationOffset >= totalLocations) {
curLocationOffset = 0;
curLocationEnd = curLocationOffset + (locationChunk - 1);
}

if (curLocationEnd >= totalLocations) {
curLocationEnd = totalLocations - 1;
}
}


doPrevSet() {
if (curLocationOffset > 1 && ((curLocationOffset - locationChunk) < 1)) {
curLocationOffset = 0;
} else {
curLocationOffset -= locationChunk;
}

curLocationEnd = curLocationOffset + (locationChunk - 1);

if (curLocationEnd >= totalLocations) {
curLocationEnd = totalLocations - 1;
}

if (curLocationOffset < 0) {
curLocationEnd = totalLocations - 1;
curLocationOffset = totalLocations - (locationChunk - 1);
}
}

doListLocations(string mode) {
integer i;
integer startPos;
integer endPos;

if (mode == "a") {
startPos = 0;
endPos = totalLocations - 1;
} else {
startPos = curLocationOffset;
endPos = curLocationEnd;
}

for (i = startPos; i <= endPos; i++) {
string newLocation = llList2String(allLocations, i);
string newDesc = llList2String(allLocationDesc, i);
llSay(0, (string)(i + 1) + ": " + newDesc + " = " + newLocation);
}
}


doSearch(list theTerms) {
integer i;
string thePhrase = llToLower(llDumpList2String(theTerms, " "));
llSay(0, "the term is " + thePhrase);

for (i = 0; i < totalLocations; i++) {
string curString = llList2String(allLocations, i);
if (llSubStringIndex(llToLower(curString), thePhrase) != -1) {
string newLocation = llList2String(allLocationDesc, i);
llSay(0, (string)(i + 1) + ": " + curString + " = " + newLocation);
}
}
}

//-----------------------

default {
on_rez(integer start_param) {
reset_wb();
}

state_entry() {
reset_wb();
}

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

dataserver(key query_id, string data) {
if (data != EOF) {
add_location(data);
linenum++;

if (linenum % 3 == 0) {
llSetText("starting: \n" + (string)linenum + " locations ...",
<1,0,0>, 1.0 );
}
llGetNotecardLine(notecard, linenum);
return;
}
llListen(dialogChannel, "", NULL_KEY, "");

totalLocations = llGetListLength(allLocations);
llSay(0, HELP_MSG);
dialogActive = 1;
llSetText("", <1,0,0>, 1.0 );
}

touch_start(integer touchNumber) {
curLocations();

avKey = llDetectedKey(0);

llDialog(avKey,
dispLocationStr,
theLocations, dialogChannel);
}

listen(integer channel, string name, key id, string message) {

if (dialogActive == 0) {
llWhisper(0, " ... still loading web addresses ...");
return;
}

if (message == "") {
message = "cur";
}

avKey = id;

list words = llParseString2List(message, [" ", " ", "="], []);
list testFind = llList2List(words, 0, 0);

if (llListFindList(cmdNextChunk, testFind) != -1) {
doNextSet();
curLocations();
if (channel == chatChannel) {
doListLocations(CUR_SET);
} else {
llDialog(id, dispLocationStr, theLocations, dialogChannel);
}
return;
}

else if (llListFindList(cmdPrevChunk, testFind) != -1) {
doPrevSet();
curLocations();
if (channel == chatChannel) {
doListLocations(CUR_SET);
} else {
llDialog(id, dispLocationStr, theLocations, dialogChannel);
}
return;
}

else if (llListFindList(cmdSearch, testFind) != -1) {
doSearch(llList2List(words, 1, -1));
return;
}

else if (llListFindList(cmdLsAll, testFind) != -1) {
doListLocations(ALL_SET);
return;
}


else if (llListFindList(cmdLsCur, testFind) != -1) {
doListLocations(CUR_SET);
return;
}


else if ((integer)message > 0 && (integer)message < 256) {
curIdx = (integer)message - 1;

string newLocation = llList2String(allLocations, curIdx);
string newDesc = llList2String(allLocationDesc, curIdx);

llSay(0, "Web Page: " + message + ":");
llSay(0, newDesc + " = " + newLocation);

llLoadURL(avKey, "Go to: " + newDesc, newLocation);
}
}
}



Sample URL file, save as "urls":

CODE

CNN = http://cnn.com
Washington Post = http://www.washingtonpost.com
New York Times = http://nyt.com
Huffington Post = http://huffingtonpost.com
News.Com = http://news.com
London Times = http://www.timesonline.co.uk/global
BBC = http://www.bbc.co.uk/
The Secondlife Home Page = http://secondlife.com
Apple = http://apple.com
SomaFM - Internet Streaming Radio = http://SomaFM.com
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
08-24-2006 17:52
/15/4f/131922/1.html
_____________________
i've got nothing. ;)