It is currently March 29th, 2024, 7:53 am

So... anyone here decent with Javascript?

Topics unrelated to Rainmeter.
User avatar
JpsCrazy
Posts: 667
Joined: April 18th, 2010, 2:16 pm
Location: NY, USA

So... anyone here decent with Javascript?

Post by JpsCrazy »

I'm trying to edit some codes I found online:

Code: Select all

<script type="text/javascript">
if ( window.addEventListener ) {  
  var state = 0, konami = [38,38,40,40,37,39,37,39,66,65];  
  window.addEventListener("keydown", function(e) {  
    if ( e.keyCode == konami[state] ) state++;  
    else state = 0;  
    if ( state == 10 )  
		alert("You have entered the KONAMI CODE!  You now have 30 lives.  Kinda.")
    }, true);  
}  
</script>
Yepp. That's right.
You press Up Up Down Down Left Right Left Right A B on your keyboard (aka, the Konami Code (or Contra Code)) and there's a message box that says that.
Well. I'd rather it do something fancier.
Such music playing... (http://outlawperformance.com/ or http://geek.thinkunique.org/) (Perform the Konami Code)

If you have any ideas and can provide working codes (or can show me how to do the music one) please let me know.
This would be wonderful.
The codes I looked for playing music seemed way to complicated for me, and frankly, I can't read javascript...
Last edited by JpsCrazy on January 21st, 2011, 7:57 am, edited 1 time in total.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: So... anyone here decent with Java?

Post by poiru »

For future reference, Java is not JavaScript :)
User avatar
JpsCrazy
Posts: 667
Joined: April 18th, 2010, 2:16 pm
Location: NY, USA

Re: So... anyone here decent with Java?

Post by JpsCrazy »

I... totally knew that.
Just gonna go change that typo that I was completely aware of...
(Note to self: Don't make assumptions)
User avatar
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am
Location: Montreal, QC, Canada

Re: So... anyone here decent with Javascript?

Post by Alex2539 »

The part you're going to want to change is the line that says: alert("You have entered the KONAMI CODE! You now have 30 lives. Kinda."). Ideally you would replace that with a call to another function that would do the whole "playing music" bit. Both of the site you link to actually load a separate page that has music set to play.

The second site does it like this:

Somewhere on the page is the following line:

Code: Select all

<iframe style="position:absolute; z-index:1; top:0; left:0; border-style:none; background-color:transparent;" frameborder="0" allowtransparency="true" scrolling="no" name="konami" id="konami" width="100%" height="0" src=""></iframe>
That sets up an invisible iframe that will hold the music-playing one. Then in the javascript, add this to the top:

Code: Select all

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var bShowing=false;
function showKonami() {
    if(bShowing) return;
    var oFrame = isInternetExplorer ? document.all.konami : document.getElementById('konami');
    oFrame.setAttribute('height',30);
    oFrame.contentWindow.location.replace("http://geek.thinkunique.org/wp-content/themes/blue-pix/music.html");
    bShowing=true;
}
Replace the URL there with the one to whatever page you will use. For them, the page is simply a flash-based music player that starts as soon as the page is loaded. Then all you need to do is call that function instead of the alert in the listener.
ImageImageImageImage