Featured Link javascript

The Gear is deprecated, use the Help forum or CG Wiki.
Locked
User avatar
Faub
The Establishment (Moderator)
The Establishment (Moderator)
Posts: 3698
Joined: Tue May 20, 2003 2:53 pm
Location: Missouri, USA
Contact:

Featured Link javascript

Post by Faub »

This seemed like a fun exercise and I was hyper distracted today so I just made it. The idea is to put a link on the page A new link will be displayed each day, cycling through the list.

This piece goes in the <head> section of the HTML. (note, the sites in these links are from my links page. I basically just copied and pasted down the list.)

Code: Select all

<script type="text/javascript">
<!--
function featuredLink() {
	//	      J  F  M  A  M   J   J   A   S   O   N   D
	var daysinmonth = new Array( 0, 31,59,90,120,151,181,212,243,273,304,334,365 );
	var link = new Array( 
		"http://yeahduff.keenspace.com/",
		"http://alexandilia.keenspace.com/",
		"http://orion.keenspace.com/",
		"http://entity.keenspace.com/",
		"http://brokenglass.keenspace.com/",
		"http://cortland.keenspace.com/",
		"http://pele.keenspace.com/",
		"http://thedevilspanties.keenspace.com/",
		"http://www.digitalwar.co.uk/",
		"http://endofthings.keenspace.com/",
		"http://flatwood.keenspace.com/",
		"http://mercuryhat.keenspace.com/",
		"http://ifthenelse.keenspace.com/",
		"http://www.thejaded.co.uk/",
		"http://kageroumanga.keenspace.com/",
		"http://km.keenspace.com/",
		"http://mixedmyth.keenspace.com/",
		"http://morningstar.keenspace.com/",
		"http://nahast.keenspace.com/",
		"http://nekkoandjoruba.keenspace.com/",
		"http://nishichi27.keenspace.com/",
		"http://pointless.keenspace.com/",
		"http://www.reasonedcognition.com/",
		"http://spools.keenspace.com/",
		"http://nowhere.keenspace.com/",
		"http://roughies.keenspace.com/",
		"http://therules.keenspace.com/",
		"http://ju-lian.keenspace.com/",
		"http://saturnalia.keenspace.com/",
		"http://shifters.keenspace.com/",
		"http://oosterwijk.keenspace.com/",
		"http://gunsnstuff.keenspace.com/",
		"http://npc.keenspace.com/",
		"http://vagrantvivian.keenspace.com/"
	);
	var names = new Array(
		"8:1",
		"Alex & Ilia",
		"Beyond Reality",
		"Blue Zombie",
		"Broken Glass",
		"Cortland",
		"Deity Permit",
		"The Devil's Panties",
		"Digital War",
		"The End of Things",
		"Flatwood",
		"Gunmetal Annie",
		"If-Then-Else",
		"The Jaded",
		"Kagerou",
		"Kurenai Mashin",
		"Mixed Myth",
		"Morningstar",
		"Nahast: Lands of Strife",
		"Nekko and Jaruba",
		"Nishichi27",
		"Pointless",
		"Reasoned Cognition",
		"Retrogressive Indexing and Filing",
		"Road From Nowhere",
		"Roughies",
		"The Rules",
		"Rules of Make Believe",
		"Saturnalia",
		"Shifters",
		"Star Bored",
		"Swords are Cool",
		"Tales of the Questor",
		"Vagrant Vivian"
	);
	var today = new Date();
	var month, date_str;
	index = ( daysinmonth[ today.getMonth() ] + today.getDate() )% names.length;
	return "<a href=\"" + link[ index ] + "\">" + names[ index ] + "</a>";
}
//-->
</script>
It would be better to put it in a separate .js file and include it with

Code: Select all

<link rel="script" type="text/javascript" href="featured.js" />
but that's up to you.

Now, in the <body> section of your HTML, wherever you want to put it include:

Code: Select all

<script type="text/javascript">
<!--
document.write( featuredLink());
//-->
</script>
That's all there is.

User avatar
Cortland
Cartoon Hero
Posts: 1202
Joined: Thu Apr 15, 2004 11:52 am
Location: Bellevue, Neb.
Contact:

Post by Cortland »

YAY! :D What a cool idea. I think I'll try this out. Thanks, Faub!
Image Image

User avatar
Phalanx
The Establishment (Moderator)
The Establishment (Moderator)
Posts: 3737
Joined: Thu Mar 06, 2003 11:46 am
Location: Superglued to the forum by Yeahduff
Contact:

Post by Phalanx »

That's pretty nifty!

I whipped out something like this day/week comic javascript linker for Gear:

Code: Select all

var d = new Date()
theDay=d.getDay()
document.write("<ul>")
switch (theDay)
{
    case 1:
        document.write("<li><a href=http://www.countyoursheep.com/>Count Your Sheep</a></li><li><a href=http://dimbulbcomics.keenspace.com/>Crooked Halo</a></li><li><a href=http://www.pvponline.com/>PvP</a></li><li><a href=http://www.schlockmercenary.com/>Schlock Mercenary</a></li><li><a href=http://www.gpf-comics.com/>General Protection Fault</a></li><li><a href=http://www.rpgworldcomic.com/>RPG World</a></li><li><a href=http://www.reallifecomics.com/>Real Life </a></li><li><a href=http://www.wanderingones.com/>The Wandering Ones</a></li><li><a href=http://www.clanofthecats.com/>Clan of the Cats</a></li><li><a href=http://www.megatokyo.com/>MegaTokyo</a></li><li><a href=http://alexandilia.keenspace.com/>Alex and Ilia</a></li><li><a href=http://www.graphicsmash.com/series.php?name=gsg&view=>Gun Street Girl</a></li><li><a href=http://www.graphicsmash.com/series.php?name=sorcerer&view=current>Sorcerer of Fortune</a></li><li><a href=http://www.girlamatic.com/series.php?name=moo&view=>The Wisdom of Moo</a></li><li><a href=http://www.pennyandaggie.com/>Penny and Aggie</a></li><li><a href=http://www.moderntales.com/series.php?name=athena&view=current>Athena Voltaire</a></li><li><a href=http://thenoob.keenspace.com/>The Noob</a></li><li><a href=http://lint.keenspace.com/>LinT</a></li><li><a href=http://www.graphicsmash.com/series.php?name=littlewhiteknight&view=>Little White Knight</a></li><li><a href=http://flatwood.keenspace.com/>Flatwood</a></li><li><a href=http://www.frozenreality.co.uk/comic/bunny/>Bunny</a></li><li><a href=http://teoandsara.keenspace.com/>Teo and Sara</a></li><li><a href=http://www.spellsandwhistles.net/index.php>Spells & Whistles</a></li><li><a href=http://nahast.keenspace.com/>Nahast: Lands of Strife</a></li><li><a href=http://www.twolumps.net/>Two Lumps</a></li><li><a href=http://www.graphicsmash.com/series.php?name=replacements&view=>The Replacements</a></li><li><a href=http://www.terinu.net/comic.php>Terinu</a></li><li><a href=http://longestsojourn.keenspace.com/>The Longest Sojourn</a></li>")
    break
    
    case 2:
        document.write("<li><a href=http://faub.keenspace.com/>Fallen Angels Used Books</a></li><li><a href=http://www.pvponline.com/>PvP</a></li><li><a href=http://www.schlockmercenary.com/>Schlock Mercenary</a></li><li><a href=http://tonjasteele.keenspace.com/>Tonja Steele</a></li><li><a href=http://www.gpf-comics.com/>General Protection Fault</a></li><li><a href=http://www.reallifecomics.com/>Real Life</a></li><li><a href=http://yeahduff.keenspace.com/>Eight to One</a></li><li><a href=http://www.graphicsmash.com/series.php?name=digger&view=>Digger</a></li><li><a href=http://www.girlamatic.com/series.php?name=jupiter&view=>Jupiter</a></li><li><a href=http://www.tentative.net/s&s/>Sand & Stone</a></li><li><a href=http://www.graphicsmash.com/series.php?name=recklesslife&view=>Reckless Life</a></li><li><a href=http://www.frozenreality.co.uk/comic/bunny/>Bunny</a></li>")     
    break
        
    case 3:
		document.write("<li><a href=http://www.countyoursheep.com/>Count Your Sheep</a></li><li><a href=http://dimbulbcomics.keenspace.com/>Crooked Halo</a></li><li><a href=http://killroyandtina.com/>Killroy and Tina!</a></li><li><a href=http://www.pvponline.com/>PvP</a></li><li><a href=http://www.schlockmercenary.com/>Schlock Mercenary</a></li><li><a href=http://www.gpf-comics.com/>General Protection Fault</a></li><li><a href=http://www.reallifecomics.com/>Real Life </a></li><li><a href=http://www.wanderingones.com/>The Wandering Ones</a></li><li><a href=http://www.clanofthecats.com/>Clan of the Cats</a></li><li><a href=http://www.megatokyo.com/>MegaTokyo</a></li><li><a href=http://isahn.keenspace.com/>Night and Day</a></li><li><a href=http://www.graphicsmash.com/series.php?name=gsg&view=>Gun Street Girl</a></li><li><a href=http://www.girlamatic.com/series.php?name=moo&view=>The Wisdom of Moo</a></li><li><a href=http://www.pennyandaggie.com/>Penny and Aggie</a></li><li><a href=http://flatwood.keenspace.com/>Flatwood</a></li><li><a href=http://magellan.keenspace.com/>Magellan</a></li><li><a href=http://www.frozenreality.co.uk/comic/bunny/>Bunny</a></li><li><a href=http://teoandsara.keenspace.com/>Teo and Sara</a></li><li><a href=http://oosterwijk.keenspace.com/>Star Bored</a></li><li><a href=http://www.twolumps.net/>Two Lumps</a></li><li><a href=http://www.terinu.net/comic.php>Terinu</a></li><li><a href=http://longestsojourn.keenspace.com/>The Longest Sojourn</a></li>")
    break
	
	
    case 4:
    document.write("<li><a href=http://www.pvponline.com/>PvP</a></li><li><a href=http://www.schlockmercenary.com/>Schlock Mercenary</a></li><li><a href=http://tonjasteele.keenspace.com/>Tonja Steele</a></li><li><a href=http://www.gpf-comics.com/>General Protection Fault</a></li><li><a href=http://www.reallifecomics.com/>Real Life </a></li><li><a href=http://www.graphicsmash.com/series.php?name=digger&view=>Digger</a></li><li><a href=http://www.girlamatic.com/series.php?name=jupiter&view=>Jupiter</a></li><li><a href=http://thenoob.keenspace.com/>The Noob</a></li><li><a href=http://lint.keenspace.com/>LinT</a></li><li><a href=http://www.graphicsmash.com/series.php?name=recklesslife&view=>Reckless Life</a></li><li><a href=http://www.icarusfalls.com/wicked/>No Rest For The Wicked</a></li><li><a href=http://www.frozenreality.co.uk/comic/bunny/>Bunny</a></li>")
	break	
	
	case 5:
		document.write("<li><a href=http://www.countyoursheep.com/>Count Your Sheep</a></li><li><a href=http://dimbulbcomics.keenspace.com/>Crooked Halo</a></li><li><a href=http://www.pvponline.com/>PvP</a></li><li><a href=http://www.schlockmercenary.com/>Schlock Mercenary</a></li><li><a href=http://www.gpf-comics.com/>General Protection Fault</a></li><li><a href=http://zebragirl.keenspot.com/>Zebra Girl</a></li><li><a href=http://www.reallifecomics.com/>Real Life</a></li><li><a href=http://www.wanderingones.com/>The Wandering Ones</a></li><li><a href=http://www.clanofthecats.com/>Clan of the Cats</a></li><li><a href=http://yeahduff.keenspace.com/>Eight To One</a></li><li><a href=http://www.megatokyo.com/>MegaTokyo</a></li><li><a href=http://faub.keenspace.com/>Fallen Angels Used Books</a></li><li><a href=http://www.graphicsmash.com/series.php?name=gsg&view=>Gun Street Girl</a></li><li><a href=http://www.girlamatic.com/series.php?name=moo&view=>The Wisdom of Moo</a></li><li><a href=http://www.pennyandaggie.com/>Penny and Aggie</a></li><li><a href=http://flatwood.keenspace.com/>Flatwood</a></li><li><a href=http://www.frozenreality.co.uk/comic/bunny/>Bunny</a></li><li><a href=http://www.vigilanteho.com/>Vigilante, Ho!</a></li><li><a href=http://teoandsara.keenspace.com/>Teo and Sara</a></li><li><a href=http://www.graphicsmash.com/series.php?name=johnnysaturn&view=current&ID=31464&seq=11587>Johnny Saturn</a></li><li><a href=http://www.twolumps.net/>Two Lumps</a></li><li><a href=http://www.terinu.net/comic.php>Terinu</a></li><li><a href=http://longestsojourn.keenspace.com/>The Longest Sojourn</a></li>")
	break
	
	case 6:
		document.write("<li><a href=http://killroyandtina.com/>Killroy and Tina!</a></li><li><a href=http://www.pvponline.com/>PvP</a></li><li><a href=http://www.tentative.net/s&s/>Sand & Stone</a></li><li><a href=http://www.schlockmercenary.com/>Schlock Mercenary</a></li><li><a href=http://www.gpf-comics.com/>General Protection Fault</a></li><li><a href=http://www.graphicsmash.com/series.php?name=rip&view=>Rip & Teri</a></li><li><a href=http://www.frozenreality.co.uk/comic/bunny/>Bunny</a></li>")
	break
	
	case 0:
		document.write("<li><a href=http://www.pvponline.com/>PvP</a></li><li><a href=http://www.schlockmercenary.com/>Schlock Mercenary</a></li><li><a href=http://www.gpf-comics.com/>General Protection Fault</a></li><li><a href=http://isahn.keenspace.com/>Night and Day</a></li><li><a href=http://www.girlamatic.com/series.php?name=spades&view=current>Girlamatic.com</a></li><li><a href=http://magellan.keenspace.com/>Magellan</a></li><li><a href=http://www.frozenreality.co.uk/comic/bunny/>Bunny</a></li><li><a href=http://bleedman.snafu-comics.com/>PowerPuff Girls Doujinshi</a></li><li><a href=http://oosterwijk.keenspace.com/>Star Bored</a></li><li><a href=http://www.thejaded.co.uk/>The Jaded</a></li>")
	break
	default:
		document.write("I'm really looking forward to this weekend!")
}
document.write("<li><br>Fresh from <a href=http://webcomicfinds.blogspot.com>Ping<a/> <a href=http://thejaded.co.uk/>Teo's</a> <a href=http://longestsojourn.keenspace.com>Bookmarks</a>!</li></ul>")

The masses of links were generated by an automatic utility that grabs links from my Safari Bookmarks and turns them into HTML, but I still need a lot of tweaking to get it to work properly.
Image
The Jaded - Action. Adventure. Danger. For Hire.
Lonely Panel - Explore. Travel. Comics.

User avatar
McDuffies
Bob was here (Moderator)
Bob was here (Moderator)
Posts: 29957
Joined: Fri Jan 01, 1999 4:00 pm
Location: Serbia
Contact:

Post by McDuffies »

Can it be donne to rottate banners too?

User avatar
AndrewTaylor
Regular Poster
Posts: 153
Joined: Tue May 18, 2004 5:46 am
Location: Leeds
Contact:

Post by AndrewTaylor »

Yes. Just replace names of things in the names array with image URLs and use

Code: Select all

return "<a href=\"" + link[ index ] + "\"><IMG SRC=\"" + names[ index ] + "\"></a>"; 
Or, better but harder to do, add an array for image URLs and use

Code: Select all

return "<a href=\"" + link[ index ] + "\"><IMG SRC=\"" + imageurls[ index ] + "\" ALT=\"" + names[ index ] + "\"></a>"; 
Edit: why oh why is bbcode off by default?
Andrew | If you are not 100% Irony-compliant, please disregard the above post.

Apathy: Join The Self-Deprecation Society

User avatar
Joel Fagin
nothos adrisor (GTC)
Posts: 6014
Joined: Mon Mar 29, 2004 1:15 am
Location: City of Lights
Contact:

Post by Joel Fagin »

For banners, an easier way would be to number the filenames, say...

Code: Select all

banner1.jpg
banner2.jpg
   :       :
banner10.jpg
...and then use this...

Code: Select all

<SCRIPT>
<!--
document.write("<IMG SRC='banner" + Math.ceil(Math.random() * 10) + ".jpg'>");
// --></SCRIPT>
- Joel Fagin
Image

User avatar
Risky
69
Posts: 3834
Joined: Tue May 04, 2004 8:41 am
Location: San Francisco
Contact:

Post by Risky »

This is looking similar to the keenelven code (and now keenime). Gotta love those rotating banners. There's also a random image code for the "avatar" images at the top of theelven.com . Would anyone be interested in seeing the code(s)? They are "pretty standard", and I think matriculated from an old gear script.

Locked