JavaScript Snippets

From Compilenix Wiki
Jump to: navigation, search

Youtube

Get video urls out of a playlist, while playing

var ol = document.getElementById("watch-appbar-playlist").children[0].children[1].children[0];
var end = false;
var out = "";
var i = 0;
while (!end) {
    try {
        out += "https://www.youtube.com/watch?v=" + ol.children[i].getAttribute("data-video-id") + "\r\n";
    } catch (ex) {
        end = true;
    }
    i++;
}
console.log(out);

Get video urls out of a playlist

var table = document.getElementById("pl-video-table");
var out = "";
for (var i = 0, row; row = table.rows[i]; i++) {
   out += "https://www.youtube.com/watch?v=" + row.getAttribute("data-video-id") + "\r\n";
}
console.log(out);

XING

Haves

Get your "haves":

var i = 0;
var content = "";
while (document.getElementById("have-" + i)) {
    content += '\n' + document.getElementById("have-" + i++).value;
}
console.log(content);

Edit it, and set it back with:

document.getElementById("have-0").value = "have 1,have 2,"

Wants

See Haves; replace "have-" with "want-"