// ==SiteScript==
// @siteName ThisAV
// @siteUrl http://www.thisav.com/
// @author mayan
// @authorUrl
// @scriptUrl
// @description
// @date 2018/07/24
// @version 0.1.4
// ==/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, "/" )
.replace( /&(hellip|#8230);/ig, "…" )
.replace( /(\d+);/g, function(a,b){return String.fromCharCode(parseInt(b,10));} )
.replace( /([0-9a-f]+);/ig, function(a,b){return String.fromCharCode(parseInt(b,16));} );
}
}
function isSiteUrl( url ) {
if ( url.match( /https?:\/\/(www\.)?thisav\.com\/video\/\d+\// ) ) return true;
return false;
}
function getVideoDetail( url ) {
url = url.replace( /^\s*http:\/\//, "https://" );
url = url.replace( /:\/\/thisav\.com/, "://www.thisav.com" );
if ( url.match( /https?:\/\/(www\.)?thisav\.com\/video\/(\d+)\// ) ) {
var vid = RegExp.$2;
} else {
return null;
}
var craving = new CravingSiteScript();
try {
var text = craving.getResponseText( url );
} catch( e ) {
text = "";
}
if ( !text ) return null;
var title = "";
if ( !title && text.match( /
\s*(.*?)\s*<\/title>/ ) ) {
title = craving.decodeHtml( RegExp.$1.replace( /\s*-[^-]*$/, "" ).replace( /\s*-[^-]*$/, "" ).replace( /\s*-[^-]*$/, "" ) );
}
if ( !title && text.match( /\s*(.*?)\s*<\/h1>/ ) ) {
title = craving.decodeHtml( RegExp.$1 );
}
if ( !title ) title = "thisav_" + ( vid || new Date().getTime() );
title = title.replace(/[\\\/:*?"<>|]/g, "_");
var realUrl = "";
//legacy
if ( text.match( /so\.addVariable\(\s*('|")file\1\s*,\s*('|")(.*?)\2\s*\)\s*;/ ) ) {
realUrl = RegExp.$3;
}
//legacy
if ( !realUrl &&
text.match( /jwplayer\s*\([^)]*\)\.setup\s*\(([\s\S]*?)\)\s*;/im ) ) {
var stup = RegExp.$1.replace( /("|')?logo\1\s*:\s*\{[^}]*\}/, "" ).replace( /("|')?related\1\s*:\s*\{[^}]*\}/, "" );
if ( stup.match( /[,{]\s*("|')?file\1\s*:\s*("|')(.*?)\2\s*[,}]/m ) ) {
realUrl = RegExp.$3;
}
if ( !realUrl &&
stup.match( /\{\s*("|')?type\1\s*:\s*("|')html5\2\s*,\s*("|')?config\3\s*:\s*\{\s*("|')?file\4\s*:\s*('|")(.*?)\5/ ) ) {
realUrl = RegExp.$6;
}
}
var arrD = [];
if ( !realUrl &&
text.match( /