3
I own this script. What should I add to it so that when it is executed, it appears in a <div>
?
Here is the script:
// Which flash versions are needed for given format
var FLASH_VERSIONS = {
'7/0/0': [5],
'9/0/115': [18, 22, 33, 34, 35, 37, 38, 59, 78, 82, 83, 84, 85, 120, 121],
'10/1/0': [52, 53, 54, 60],
};
// Regex to extract the video format
var RE_ITAG = /&itag=([0-9]*)&/i;
function get_fmt(content) {
var fmt = new Object();
fmt.list = new Array();
fmt.stream_map = new Array();
for (var i=0; i < content.length; i++) {
var url = content[i]['url'];
if (url.search("") == -1)
continue;
var matches = RE_ITAG.exec(url);
var itag = matches[1];
var resolution = '7/0/0';
for (var possible_resolution in FLASH_VERSIONS.length) {
if (FLASH_VERSIONS[possible_resolution].indexOf(itag)) {
resolution = possible_resolution;
}
}
fmt.list.push(itag+'/'+String(content[i].width)+'x'+String(content[i].height)+'/'+resolution);
fmt.stream_map.push(itag+'|'+content[i].url.replace(/,/g, '%2C'));
}
fmt.list.reverse();
fmt.stream_map.reverse();
return fmt;
}
function get_embed(content) {
var fmt = get_fmt(content);
var flashvars = new Array();
flashvars.push('fs=1');
flashvars.push('hl=en');
flashvars.push('autoplay=1');
flashvars.push('ps=');
flashvars.push('playerapiid=uniquePlayerId');
flashvars.push('fmt_list='+encodeURIComponent(fmt.list.join()));
flashvars.push('fmt_stream_map='+encodeURIComponent(fmt.stream_map.join()));
flashvars.push('');
flashvars.push('t=1');
flashvars.push('vq=large');
flashvars.push('auth_timeout=86400000000');
var embed = document.createElement('');
embed.setAttribute("src", "");
embed.setAttribute("type", "application/x-shockwave-flash");
embed.setAttribute("allowfullscreen", "true");
embed.setAttribute("allowscriptaccess", "always");
embed.setAttribute("scale", "noScale");
embed.setAttribute("wmode", "opaque");
embed.setAttribute("flashvars", flashvars.join("&"));
embed.setAttribute("width", "100%");
embed.setAttribute("height", "100%");
return embed;
}
var ts = Math.round((new Date()).getTime() / 1000);
var script = document.createElement('script');
var hash = document.location.hash;
var id = hash.substr(1,hash.length);
var head = document.getElementsByTagName('head').item(0);
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'https://');
head.appendChild(script);
myFunction(); // Fails because it hasn't loaded from my.js yet.
window.onload = function() {
// Works most of the time but not all of the time.
// Especially if my.js injects another script that contains myFunction().
myFunction();
};
How do I load it into an html page appears inside the specific div?
Example:
<div id="script" class="#">/div>
A doubt... what has in the váriavel ts?
– MarceloBoni
Refers to this part Math.round(ts/3600 ? there will appear an embed
– Endou
I took that part out. It wasn’t for this one
– Endou
As you’ve been told here (By the way, it’s the same question, right? ), there’s no such thing as "the script appears inside a div". It depends on what the script does. It can write content somewhere or not. What script are you trying to run? Taking this example, what would be the content of
myFunction
?– bfavaretto