So, I have some code that should do four things:
- remove the “.mp4” extension from every title
- change my video category
- put the same description in all of the videos
- put the same keywords in all of the videos
Note: All of this would be done on the YouTube upload page. I’m using Greasemonkey in Mozilla Firefox.
I wrote this, but my question is: how do I change the HTML title in the actual HTML page to the new title (which is a Javascript variable)?
This is my code:
function remove_mp4()
{
var title = document.getElementsByName("title").value;
var new_title = title.replace(title.match(".mp4"), "");
}
function add_description()
{
var description = document.getElementsByName("description").value;
var new_description = "Subscribe."
}
function add_keywords()
{
var keywords = document.getElementsByName("keywords").value;
var new_keywords = prompt("Enter keywords.", "");
}
function change_category()
{
var category = document.getElementsByName("category").value;
var new_category = "<option value="27">Education</option>"
}
remove_mp4();
add_description();
add_keywords();
change_category();
Note: If you see any mistakes in the JavaScript code, please let me know.
Note 2: If you wonder why I stored the current HTML values in variables, that’s because I think I will have to use them in order to replace HTML values (I may be wrong).
I assume that your question is only about the title changing, and not about the rest; also, I assume you mean changing all elements in the document that have “title” as
nameattribute, and not the document title.In that case, you could indeed use
document.getElementsByName("title").To handle the
name="title"elements, you could do:For the
name="description"element, use this: (assuming there’s only onename="description"element on the page, or you want the first one)I wasn’t really sure about the keywords (I haven’t got a YouTube page in front of me right now), so this assumes it’s a text field/area just like the description:
Again, based on your question which just sets the
.valueof the category thingy:At the last one, though, note that I changed the
"27"into'27': you can’t put double quotes inside a double-quoted string assuming they’re handled just like any other character 🙂Did this help a little more? 🙂