CodingGoogle Gears

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Mikee   
 To:  ALL
34967.10 
Something like this could be interesting for beehive...

Ignore the shoddyness of the code - i was just trying to knock something up quickly.

javascript code:
 <!DOCTYPE html>
<html>
<head>
<title>Page</title>
 
<script type="text/javascript"  src="../gears_init.js"></script>
<script>
 
var db;
function initDatabase() {
  if (window.google && google.gears) {
    try {
      db = google.gears.factory.create('beta.database');
      if (db) {
        db.open('database-usernames');
        db.execute('create table if not exists Usernames (Username varchar(255),DisplayName varchar(255), Timestamp int)');
        db.execute('create unique index if not exists username_unique_1 on Usernames (Username)');
      }
    } catch (ex) {}
  }
}
function parsePage(){
	initDatabase();
    if (db) {
		var regex = /openProfile.*\>(.*?)\s*(\((.*)\))?<\/a\>/gi;
		var matches = document.body.innerHTML.match();
		while((m = regex.exec(document.body.innerHTML)) != null){
			var displayname = m[1];
			var username = (m[3]!=null?m[3]:m[1]).toUpperCase();
			db.execute('insert or ignore into Usernames values (?, ?, ?)', [username, displayname, new Date().getTime()]);
		}
  	}
}
function autoComplete (e){
  if (db){
  	if( e == null ) e = window.event
   	if( e.keyCode == 16 )
   		return;
  	  var box = document.getElementById('namebox');
      var boxvalue = box.value;
   	  if ( e.keyCode == 8)
   	   return;
 
   	  if (boxvalue.length > 0){
		  var rs = db.execute('select * from Usernames where Username like ? order by Username asc limit 0,1', [boxvalue+'%']);
		  while (rs.isValidRow()) {
			var returnval = rs.field(0);
			box.value = returnval;
			if( box.createTextRange )
			{
				hRange = hElement.createTextRange()
				hRange.findText( returnval.substr(boxvalue.length) )
				hRange.select()
			}else{
				box.setSelectionRange( boxvalue.length, returnval.length)
			}
 
			rs.next();
		  }
		  rs.close();
	  }
  }
}
</script>
 
</head>
 
<body onload="parsePage();">
<span class="posttofrom"><a href="user_profile.php?webtag=DEFAULT&amp;uid=95" target="_blank" onclick="return openProfile(95, 'DEFAULT')">Mouse</a></span>
<span class="posttofrom"><a href="user_profile.php?webtag=DEFAULT&amp;uid=19" target="_blank" onclick="return openProfile(19, 'DEFAULT')">Matt</a></span>
<a href="user_profile.php?webtag=DEFAULT&amp;uid=27" target="_blank" onclick="return openProfile(27, 'DEFAULT')">Mikee</a></span>
<span class="posttofrom"><a href="user_profile.php?webtag=DEFAULT&amp;uid=454" target="_blank" onclick="return openProfile(454, 'DEFAULT')">Peter (BOUGHTONP)</a></span>
<br /><br /><input type="text" id="namebox" style="width: 400px;" onkeyup="autoComplete()" />
</body>
</html>
 



It finds all the usernames on the page and puts them into a local database. Over time it could just keep collecting these..
On search boxes you could do a kind of autocomplete to automatically suggest the username they've started typing.

The way I see it, it wont matter if they don't have gears installed because it won't break any current functionality.
They're only likely to reply to someone who's post they've read, so it should always suggest the name they're trying to type.

Dunno, just an idea. quite simple way to add a tiny tweak to the functionality without any backend code.
0/0
 Reply   Quote More 

 From:  Mikee   
 To:  ALL
34967.11 

Um, posting a page of code probably doesnt illustrate the idea.

 

http://www.mikefranklin.me.uk/experiments/gears/username_collector.html

 

Imagine that was just a standard forum page. the javascript would collect the usernames and put them in its local database while you're browsing around.

 

Imagine that box is a "username" reply-to box. It could auto-complete by querying its local database - and it'd be very fast.

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mikee      
34967.12 In reply to 34967.11 
Would there be significant benefit with Gears vs a [locally cached] JSON data file?
0/0
 Reply   Quote More 

 From:  Mikee   
 To:  Peter (BOUGHTONP)     
34967.13 In reply to 34967.12 
How do you intend to locally cache this file?
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mikee      
34967.14 In reply to 34967.13 
By ensuring the server sends correct headers, and letting the browser handle the rest...
0/0
 Reply   Quote More 

 From:  Mikee   
 To:  Peter (BOUGHTONP)     
34967.15 In reply to 34967.14 

So you'd have to download the json of all the forum members usernames in one request?

 

That'd be pretty slow. Then doing a search through the json data every time someone presses a key would also be slow and intensive. That technique would also mean having to write server side code.

0/0
 Reply   Quote More 

 From:  Mikee   
 To:  ALL
34967.16 

You could extend this idea by indexing any viewed threads against thread id's, then have a quick search to quickly jump to threads you've previously viewed by quickly typing part of the name of it.

 

I'm pretty sure sqlite allows fulltext searching.

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Mikee      
34967.17 In reply to 34967.15 
If there are 500 members with 32 character usernames, that's 15KB of data - not slow to download.

Whether it's slow+intensive to use that with JSON vs SQLite is my question really - is there enough benefit from SQLite to make it a feature that can only be utilised by people who have installed extra software?
0/0
 Reply   Quote More 

 From:  Mikee   
 To:  Peter (BOUGHTONP)     
34967.18 In reply to 34967.17 

Mmm. Well I was thinking of it as a small enhancement which is pretty quick and inexpensive to implement.

 

Dunno. Was just a suggestion :) Could be nice to enhance things with gears here and there.. such as the multiple file selector and whatnot.

0/0
 Reply   Quote More 

Reply to All    
 

1–18

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats