0

This script (for Greasemonkey) doesn't work intendedly.
I want to insert an script, and after the script loaded, replace text "Download" to Japanese word (I will use "TEST" instead.).

(function() {
    if ((document.URL.match("www.youtube.com/watch?"))||(document.URL.match("c.youtube.com/videoplayback?"))) {
    var head = document.getElementsByTagName('head')[0]; //Working
    var script = document.createElement('script'); //Working
    script.type = 'text/javascript'; //Working
    script.src = 'http://userscripts.org/scripts/source/25105.user.js'; //Working
    script.onload = 'document.getElementsByClassName("yt-uix-button-content")[0].innerHTML.replace("Download","TEST")'; //Not working.
    head.appendChild(script); //Working
};})();

What is the problem?

Flare0n
  • 85
  • 1
  • 7
  • I think you should check this post http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer – Eddie Sep 16 '13 at 08:19

1 Answers1

0

You have to make sure that the elements are already loaded. Which means, after body content is loaded you can query elements in the body. This leads to the following solution. on the BODY tag you have to add the following

<body onload="myOnloadFunc()">

then you have to create the myOnloadFunc as follows:

<script type="text/javascript>
function myOnloadFunc () {

  // in here you should place the original code you have created.

  if ((document.URL.match("www.youtube.com/watch?"))|| (document.URL.match("c.youtube.com/videoplayback?"))) {
     var head = document.getElementsByTagName('head')[0]; //Working
     var script = document.createElement('script'); //Working
     script.type = 'text/javascript'; //Working
     script.src = 'http://userscripts.org/scripts/source/25105.user.js'; //Working
     script.onload = 'document.getElementsByClassName("yt-uix-button-content")[0].innerHTML.replace("Download","TEST")'; //Not working.
     head.appendChild(script); //Working
}
</script>
Scription
  • 646
  • 3
  • 12
  • 21
  • Sorry, but I found another problem. There are many other objects which have "yt-uix-button-content" class, so I shouldn't have use [0]. – Flare0n Sep 16 '13 at 09:05