home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 April
/
PCWorld_2008-04_cd.bin
/
multimedia
/
mediacoder
/
MediaCoder-0.6.0.3905.exe
/
extensions
/
_include
/
extension.js
< prev
next >
Wrap
Text File
|
2007-08-27
|
5KB
|
259 lines
/******************************************************************
* MediaCoder extension base scripts
* Distributed under GPL license
* Copyright (c) 2007 Stanley Huang <stanleyhuangyc@gmail.com>
* All rights reserved.
******************************************************************/
var xmlhttp = CreateXMLHttp();
var debug;
if (GetToken(document.location.href, "debug")) {
debug = true;
} else {
debug = false;
}
function CreateXMLHttp()
{
var newxmlhttp = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
if (!newxmlhttp) alert("XMLHttpRequest object cannot be created.");
return newxmlhttp;
}
function NewXML(rootkey)
{
var xmlDoc;
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", rootkey, null);
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
else
{
return;
}
return xmlDoc;
}
function LoadXMLFile(xmlfile)
{
var xmlDoc;
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
//xmlDoc.onload = callback;
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
//if (xmlDoc.readyState == 4) callback()
};
}
else
{
return;
}
xmlDoc.async = false;
try {
if (!xmlDoc.load(xmlfile)) return null;
}
catch (ex)
{
return null;
}
return xmlDoc;
}
function AddPrefNode(doc, path, value)
{
var i;
var tokens = path.split('.');
var node = doc.firstChild;
var newnode;
for (i = 0; i < tokens.length; i++) {
newnode = doc.createElement("node");
newnode.setAttribute("key", tokens[i]);
node = node.appendChild(newnode);
}
node.setAttribute("value", value);
}
function AddPrefElements(doc, arrayElements)
{
var i;
for (i = 0; i < arrayValues.length; i+=2) {
AddPrefNode(doc, arrayValues[i], arrayValues[i+1]);
}
}
function AddPrefValues(doc, arrayValues)
{
var i;
for (i = 0; i < arrayValues.length; i+=2) {
AddPrefNode(doc, arrayValues[i], arrayValues[i+1]);
}
}
function SetPrefValue(param, val)
{
xmlhttp.open("GET", "/prefs/set?" + param + "=" + val, false);
xmlhttp.send(null);
if (xmlhttp.responseText == "0") {
alert("Preference key '"+param+"' can't be set to '"+val+"'.");
return false;
}
return true;
}
function GetPrefValue(param)
{
xmlhttp.open("GET", "/prefs/get?path=" + param, false);
xmlhttp.send(null);
return xmlhttp.responseText;
}
function AlertConnError()
{
if (debug) alert("Error connecting to MediaCoder.");
}
function PostPrefXML(data)
{
try {
xmlhttp.open("POST", "/prefs/import", true);
xmlhttp.send(data);
}
catch (ex) {
AlertConnError();
}
}
function SendCommand(cmd)
{
try {
xmlhttp.open("GET", "/ui?cmd=" + cmd, false);
xmlhttp.send(null);
}
catch (ex) {
AlertConnError();
}
}
function PlayVideo(hwnd)
{
try {
xmlhttp.open("GET", "/ui?cmd=play " + hwnd, false);
xmlhttp.send(null);
}
catch (ex) {
AlertConnError();
}
}
function StopPlay()
{
try {
xmlhttp.open("GET", "/ui?cmd=stop_play " + hwnd, false);
xmlhttp.send(null);
}
catch (ex) {
AlertConnError();
}
}
function PlayConvertedVideo(hwnd)
{
try {
xmlhttp.open("GET", "/ui?cmd=preview " + hwnd, false);
xmlhttp.send(null);
}
catch (ex) {
AlertConnError();
}
}
function QueryString(url, async)
{
try {
xmlhttp.open("GET", url, async);
xmlhttp.send(null);
return xmlhttp.responseText;
}
catch (ex) {
AlertConnError();
return null;
}
}
function QueryInfo(info)
{
return QueryString("/mc/get?query=" + info, false);
}
function QueryPref(path, opts)
{
var node;
var requrl = "/prefs/prefs.xml?type&";
if (opts)
requrl += opts + "&";
if (path)
requrl += "path=" + path;
xmlhttp.open("GET", requrl, false);
xmlhttp.send(null);
node = xmlhttp.responseXML.firstChild;
if (!node) {
alert("Failed to retrieve preference data from MediaCoder.");
return null;
}
return getChildNode(node);
}
function AddFile(filename)
{
if (filename) {
xmlhttp.open("GET", "/queue?action=addfile&file=" + filename, false);
xmlhttp.send(null);
}
}
function SetWindowSize(width, height)
{
window.innerWidth = width;
window.innerHeight = height;
}
function OpenURL(urlstring) {
xmlhttp.open('GET', '/openurl?url=' + urlstring, false);
xmlhttp.send(null);
}
function ShowItem(id)
{
var e = document.getElementById(id);
if (e) e.style.display = "block";
}
function HideItem(id)
{
var e = document.getElementById(id);
if (e) e.style.display = "none";
}
function ValueOf(id)
{
return document.getElementById(id).value;
}
function GetToken(str, token)
{
var idx = str.indexOf(token + '=');
if (idx < 0) return null;
var argstr = str.substring(idx + token.length + 1);
idx = argstr.indexOf('&');
return idx > 0 ? argstr.substring(0, idx) : argstr;
}