<>(function main(Global) {
var CONSTANTS = {
PLAYER_DOM: 'object[data],embed[src],iframe[src]',
PLAYERS: [
{
find: /^http:\/\/static\.youku\.com\/.*?q?(player|loader)(_[^.]+)?\.swf/,
replace: 'http://player.opengg.me/loader.swf'
},
{
find: /^http:\/\/js\.tudouui\.com\/.*?\/TudouVideoPlayer_Homer_[^.]*?.swf/,
replace: 'http://player.opengg.me/TudouVideoPlayer_Homer_238.swf'
},
{
find: /^http:\/\/player\.youku\.com\/player\.php\//,
replace: 'http://player.opengg.me/player.php/'
},
{
find: /^http:\/\/dp\.tudou\.com\/nplayer[^.]*?\.swf|http:\/\/js\.tudouui\.com\/doupao\/nplayer[^.]*?\.swf/,
replace: 'http://player.opengg.me/nplayer.swf'
},
{
find: /^http:\/\/www.tudou.com\/(([a-z]|programs)\/.*)/,
replace: 'http://player.opengg.me/td.php/$1'
}
],
SHARE_DOM: '#panel_share input,input#copyInput.txt',
SHARES: [
{
find: /http:\/\/player\.youku\.com\/player\.php\//,
replace: 'http://player.opengg.me/player.php/'
},
{
find: /http:\/\/www.tudou.com\/(.*v\.swf)/,
replace: 'http://player.opengg.me/td.php/$1'
}
],
TIPS_HOLDER: '#miniheader,#gTop',
TIPS: '
',
STYLE: '.playBox_thx #player.player,.playBox_thx #player.player object{min-height:' + Math.max(Global.innerHeight * 0.6, 580) + 'px !important}.tips_container{position:absolute;top:3em;padding:1em 2em;right:50px;color:green;opacity:0.4;background:#ddd;z-index:999999}.tips_container:hover{opacity:0.8}.tips_container .tips_toggleWide{color:red;cursor:pointer;display:none}',
NODEINSERTED_HACK: '@-moz-keyframes nodeInserted{from{opacity:0.99;}to{opacity:1;}}@-webkit-keyframes nodeInserted{from{opacity:0.99;}to{opacity:1;}}@-o-keyframes nodeInserted{from{opacity:0.99;}to{opacity:1;}}@keyframes nodeInserted{from{opacity:0.99;}to{opacity:1;}}embed,object{animation-duration:.001s;-ms-animation-duration:.001s;-moz-animation-duration:.001s;-webkit-animation-duration:.001s;-o-animation-duration:.001s;animation-name:nodeInserted;-ms-animation-name:nodeInserted;-moz-animation-name:nodeInserted;-webkit-animation-name:nodeInserted;-o-animation-name:nodeInserted;}',
TOGGLE_BTN: '.tips_container .tips_toggleWide'
};
var DONE = [];
var UTIL = {
addCss: function (str) {
var style = document.createElement('style');
style.textContent = str;
document.head.appendChild(style);
},
procFlash: function (elem) {
if (DONE.indexOf(elem) !== -1) {
return;
}
if (this.reloadFlash(elem)) {
DONE.push(elem);
}
},
reloadFlash: function (elem) {
var attrs = ['data', 'src'];
var players = CONSTANTS.PLAYERS;
var reloaded = false;
UTIL.forEach(attrs, function (attr) {
UTIL.forEach(players, function (player) {
var find = player.find;
var replace = player.replace;
var value = elem[attr];
if (value && find.test(value)) {
var nextSibling = elem.nextSibling;
var parentNode = elem.parentNode;
var clone = elem.cloneNode(true);
clone[attr] = value.replace(find, replace);
parentNode.removeChild(elem);
parentNode.insertBefore(clone, nextSibling);
//Baidu tieba shit.
if(getComputedStyle(clone).display==='none'){
clone.style.display='block';
}
reloaded = true;
}
});
});
return reloaded;
},
forEach: function (arr, callback) {
if (this.isArrayLike(arr)) {
if (Array.prototype.forEach) {
Array.prototype.forEach.call(arr, callback);
} else {
var i = 0;
for (i = 0; i < arr.length; ++i) {
callback.call(arr[i], arr[i]);
}
}
}
},
isArrayLike: function (obj) {
if (typeof obj !== 'object') {
return false;
}
var types = ['Array', 'NodeList', 'HTMLCollection'];
var i = 0;
for (i = 0; i < types.length; ++i) {
if (Object.prototype.toString.call(obj).indexOf(types[i]) !== -1) {
return true;
}
}
return false;
}
};
var STORE;
(function(){
var isStorage = true;
if(!Global.localStorage){
isStorage = false;
}else{
try{
var key = String(Math.random());
localStorage.setItem(key,'test');
if(localStorage.getItem(key)!=='test'){
throw 'not equal';
}
localStorage.removeItem(key);
}catch(e){
isStorage=false;
}
}
STORE = {
getItem: function(key){
if(isStorage){
return localStorage.getItem(key);
}
},
setItem: function(key, value){
if(isStorage){
localStorage.setItem(key, value);
}
}
};
})();
function init() {
function onDOMNodeInsertedHandler(e) {
var target = e.target;
if (target.nodeType === 1 && /OBJECT|EMBED|IFRAME/ig.test(target.nodeName)) {
UTIL.procFlash(target);
}
}
function onAnimationStartHandler(e) {
if (e.animationName === 'nodeInserted') {
var target = e.target;
if (target.nodeType === 1 && /OBJECT|EMBED|IFRAME/ig.test(target.nodeName)) {
UTIL.procFlash(target);
}
}
}
function animationNotSupported(){
var style = document.createElement('div').style;
var arr = ['animation', 'MozAnimation', 'webkitAnimation', 'OAnimation'];
for(var i =0;i