// ==SiteScript==
// @siteName 日本XVIDEOS学会
// @siteUrl http://j-xvideos.com/
// @author mayan
// @authorUrl
// @scriptUrl
// @description
// @date 2014/04/10
// @version 0.1
// ==/SiteScript==
function CravingSiteScript() {
this._initialize();
}
CravingSiteScript.prototype = {
_xhr: null,
_initialize: function() {},
_getXmlHttpRequest: function() {
if ( this._xhr != null ) {
return this._xhr;
}
var xhr = null;
var these = [
function() { return new XMLHttpRequest(); }
, function() { return new ActiveXObject( "Msxml2.XMLHTTP" ); }
, function() { return new ActiveXObject( "Microsoft.XMLHTTP" ); }
, function() { return new ActiveXObject( "Msxml2.XMLHTTP.4.0" ); }
];
for ( var i = 0, length = these.length; i < length; i++ ) {
var func = these[ i ];
try {
xhr = func();
break;
}
catch( e ) {}
}
this._xhr = xhr;
return this._xhr;
},
_load: function( url, data, method ) {
var req = this._getXmlHttpRequest();
var mtd = ( method == null ) ? "GET" : "POST";
req.open( mtd, url, false );
if ( mtd == "POST" ) {
req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
}
req.send( data );
return req.responseText;
},
getResponseText: function( url, data, method ) {
return this._load( url, data, method );
},
getResponseJSON: function( url, data, method ) {
var text = this._load( url, data, method );
return eval( "("+text+")" );
},
/// Math
random: function( limit ) {
return Math.floor( Math.random() * limit );
},
/// String
decodeHtml: function( str ) {
return str.replace( /&(quot|#0*34);/ig, "\"" )
.replace( /&(amp|#0*38);/ig, "&" )
.replace( /&(apos|#0*39);/ig, "'" )
.replace( /&(lt|#0*60);/ig, "<" )
.replace( /&(gt|#0*62);/ig, ">" )
.replace( /&(nbsp|#0*160);/ig, " " )
.replace( /&(frasl|#8260);/ig, "/" );
}
}
var _JXVideos = {};
_JXVideos.showMsg = true;
function isSiteUrl( url ) {
if ( url.match( /http:\/\/j-xvideos\.com\/(pc\/)?v\/\d+/ ) ) return true;
return false;
}
function getVideoDetail( url ) {
if ( typeof _JXVideos != "object" ) _JXVidoes = {};
if ( url.match( /http:\/\/j-xvideos\.com\/(pc\/)?v\/(\d+)/ ) ) {
var vid = RegExp.$2;
if ( RegExp.$1 ) var type = "pc";
else type = "mobile";
} else {
return null;
}
var craving = new CravingSiteScript();
try {
var text = craving.getResponseText( url );
} catch( e ) {
text = "";
}
if ( !text ) return null;
if ( text.match( /
]*)?>\s*(.*?)\s*<\/title\s*>/im ) ) {
var title = craving.decodeHtml( RegExp.$1 ).replace( /[\r\n\t\s]+/g," " ).replace( /\s*\|[^|]*$/,"" );
}
if ( !title ) title = "jxvideos_" + vid;
title = title.replace(/[\\\/:*?"<>|]/g, "_");
if ( text.match( /\|embedframe\|(\d+)\|/ ) ) {
try {
var xvideoid = Math.floor( parseInt( RegExp.$1,10 ) / parseInt( vid, 10 ) );
} catch( e ) {
xvideoid = undefined;
}
}
if ( typeof xvideoid != "number" ) return null;
var scriptname = "xvideos.site.js";
var dummy = "http://www.xvideos.com/video" + xvideoid + "/";
var ret = null;
var arrErr = [];
var objInc = new clsIncludeSiteScript();
if ( !objInc.isOK ) {
arrErr.push( "objInc作成失敗。" );
} else {
var objScript = objInc.includeSiteScript( scriptname );
if ( !objScript ) {
arrErr.push( scriptname + " の読み込みに失敗。" );
} else {
if ( !objScript.isSiteUrl( dummy ) ) {
arrErr.push( "URL不適合。" );
} else {
ret = objScript.getVideoDetail( dummy );
if ( !ret ) {
arrErr.push( "realUrl取得失敗。" );
} else {
ret = objInc.replaceTitle( ret, title );
}
}
}
}
if ( !ret ) {
if ( _JXVideos.showMsg ) {
var objBx = new clsMsgBox();
if ( objBx.isOK ) {
objBx.MsgBox( "取得失敗。"
+ "\ntitle= " + title
+ "\nxvideos url= " + dummy
+ ( (arrErr.length > 0)? ("\n" + arrErr.join("\n")): "" )
, "from jxvideoscom.site.js", 0 );
}
}
return null;
}
return ret;
}
function clsIncludeSiteScript() {
var code1 = "(function(){\n\n";
var code2 = "\n\nreturn {'isSiteUrl':isSiteUrl,'getVideoDetail':getVideoDetail};})()";
var cePath = "\\CravingExplorer\\site-script\\";
this.isOK = false;
//initialize
try {
var appPath = ( new ActiveXObject( "WScript.Shell" ) ).SpecialFolders( "AppData" );
this.isOK = true;
} catch( e ) {
appPath = "";
this.isOK = false;
}
function evalScript( strFullPath, strCharset ) {
try {
var objStream = new ActiveXObject( "ADODB.Stream" );
objStream.Charset = strCharset;
objStream.Open();
objStream.LoadFromFile( strFullPath );
var obj = eval( "(" + code1 + objStream.ReadText() + code2 + ")" );
objStream.Close();
} catch( e ) {
obj = null;
}
if ( !obj || typeof obj != "object" ) return null;
if ( typeof obj.isSiteUrl != "function" ) return null;
if ( typeof obj.getVideoDetail != "function" ) return null;
return obj;
}
this.includeSiteScript = function ( strFileName ) {
if ( !this.isOK ) return null;
var strFullPath = appPath + cePath + strFileName;
var objS = evalScript( strFullPath, "unicode" );
if ( !objS ) objS = evalScript( strFullPath, "utf-8" );
return objS;
};
this.replaceTitle = function ( objRtn, title ) {
var count = 0;
var safe = 300;
while ( count < safe ) {
if ( objRtn[ "videoTitle" + count ] == undefined ) break;
count++;
}
if ( count <= 1 ) {
objRtn.videoTitle0 = title;
} else {
for ( var i = 0; i < count; i++ ) {
objRtn[ "videoTitle" + i ] = title + "_" + ( (i<9)?("0"+(i+1)):(""+(i+1)) );
}
}
return objRtn;
};
}
/* msgbox */
function clsMsgBox(){
//WScript.Shell Popup
this.isOK = false;
this._objShell = null;
this._initialize = function (){
try{
this._objShell = new ActiveXObject( "WScript.Shell" );
this.isOK = true;
} catch( e ) {
this.isOK = false;
}
}
this._initialize();
this.MsgBox = function ( msg, title, btn ){
if ( btn == undefined ) btn = 1;
//btn=1の時ret: OK:1, キャンセル:2
if ( this.isOK )
return this._objShell.Popup( msg, 0, title, btn+64 );
}
}
/* msgbox */