Chrome Extension (JavaSript) Help

PirateNinjaPirateNinja Icrontian
edited July 2010 in Internet & Media
Hi everyone,
I don't bode well with Java but I am trying to modify an extension for Chrome that causes videos in YouTube to autoloop and expand the view stats are of a video.
I've got it so far, but the problem is it is done in a way where a custom button is created and it must be clicked.

What I need is for this script to execute when the page loads instead of when the button is clicked. I've tried various things like window.onload with no luck.

In short, I suck at javascript. Can someone tell me how to execute this when the page loads instead of when a button is clicked?

I'll paypal $10 for the fixed code to the first who can provide it:
var m=/youtube\.com\/watch\?v=[^&]+/i.exec(location.href);if(m.length>0){var l=document.createElement("button");l.setAttribute("title","Loop this!");l.setAttribute("type","button");l.setAttribute("class","master-sprite yt-uix-button yt-uix-tooltip");l.id="loop";l.setAttribute("onclick","if(typeof(lv)=='undefined'){window.lv=false;window['msc']=function(ns){if(lv&&ns==0)window.setTimeout('movie_player.playVideo()',1000);};movie_player.addEventListener('onStateChange','msc');if (window['watch-next-list-autoplay'] && window['watch-next-list-autoplay'].getAttribute('class').search('autoplay-on')!=-1) yt.www.watch.queue.handleToggleAutoplay(window['watch-next-list-autoplay']);yt.www.watch.watch5.handleToggleStats(window['watch-views']);}lv=!lv;if(lv)loop.style.background='#DDD -webkit-gradient(linear, 0% 0%, 0% 100%, from(#CCC), to(#EEE))';else loop.style.background='#DDD -webkit-gradient(linear, 0% 0%, 0% 100%, from(white), to(#EEE))';return false;");var lI=document.createElement("img");lI.src=chrome.extension.getURL("loop.png");lI.style.backgroundImage="url(this.src)";var ws=document.createTextNode(" ");var lt=document.createElement("span");lt.setAttribute("class","yt-uix-button-content");lt.innerHTML="Loop";l.appendChild(lI);l.appendChild(ws);l.appendChild(lt);document.getElementById("watch-actions-left").appendChild(l);}

Comments

Sign In or Register to comment.