Onens.Clean.Player

Thanks to OpenGG, Harv.c, KaFan15536900

  1. // ==UserScript==
  2. // @name Onens.Clean.Player
  3. // @namespace http://onens.com/
  4. // @description Thanks to OpenGG, Harv.c, KaFan15536900
  5. // @version 2.2.1
  6. // @include http://*/*
  7. // @include https://*/*
  8. // @grant GM_xmlhttpRequest
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. if (typeof GM_xmlhttpRequest == 'undefined') {
  13. var GM_xmlhttpRequest = function(obj) {
  14. var xhr = new XMLHttpRequest();
  15. xhr.open(obj.method, obj.url, true);
  16. xhr.send();
  17. xhr.onreadystatechange = function() {
  18. xhr.readyState == 4 && typeof obj.onload == 'function' && obj.onload(xhr);
  19. };
  20. };
  21. }
  22.  
  23. Function.prototype.bind = function() {
  24. var fn = this,
  25. arg = Array.prototype.slice.call(arguments),
  26. obj = arg.shift();
  27. return function() {
  28. return fn.apply(obj, arg.concat(Array.prototype.slice.call(arguments)));
  29. };
  30. };
  31.  
  32. var OCPlayer = {
  33. host: 'http://gesion.duapp.com/player/',
  34. list: [],
  35. done: [],
  36. rule: [{ // YOUKU_COM
  37. find: /^http:\/\/static\.youku\.com(\/v[\d\.]*)?\/v\/swf\/q?(player|loader)([^\.]+)?\.swf/i,
  38. replace: 'loader.swf'
  39. }, { // YOUKU_OUT
  40. find: /^http:\/\/player\.youku\.com\/player\.php\/.*sid\/([\w=]+).*(\/v)?\.swf.*/i,
  41. replace: 'loader.swf?showAd=0&VideoIDS=$1'
  42. }, { // KU6_COM
  43. find: /^http:\/\/player\.ku6cdn\.com\/default\/.*\/\d+\/(v|player)\.swf/i,
  44. replace: 'ku6.swf'
  45. }, { // KU6_OUT
  46. find: /^http:\/\/player\.ku6\.com\/(inside|refer)\/([^\/]+)\/v\.swf.*/i,
  47. replace: 'ku6_out.swf?vid=$2'
  48. }, { // IQIYI_COM
  49. find: /^https?:\/\/www\.iqiyi\.com\/(player\/\d+\/player|common\/flashplayer\/\d+\/(main)?player_.*)\.swf/i,
  50. replace: function(el, find) {
  51. var url = 'iqiyi.swf';
  52. if (!/(^((?!baidu|61|178).)*\.iqiyi\.com|pps\.tv)/i.test(window.location.host))
  53. url = 'iqiyi_out.swf';
  54. else if (document.querySelector('span[data-flashplayerparam-flashurl]'))
  55. url = 'iqiyi5.swf';
  56.  
  57. this.Reload.bind(this, el, find, url)();
  58. }
  59. }, { // IQIYI_BILIBILI
  60. find: /^http:\/\/www\.bilibili\.tv\/iqiyi\.swf/i,
  61. replace: 'iqiyi.swf'
  62. }, { // IQIYI_PPS
  63. find: /^https?:\/\/www\.iqiyi\.com\/common\/.*\/pps[\w]+.swf/i,
  64. replace: 'iqiyi_out.swf'
  65. }, { // IQIYI_OUT
  66. find: /^http:\/\/(player|dispatcher)\.video\.i?qiyi\.com\/(.*[\?&]vid=)?([^\/&]+).*/i,
  67. replace: function(el, find) {
  68. var url = 'iqiyi_out.swf?vid=$3',
  69. match = (el.data || el.src).match(/(autoplay)=\d+/ig);
  70. if (match)
  71. url += '&' + match.join('&');
  72.  
  73. this.Reload.bind(this, el, find, url)();
  74. }
  75. }, { // TUDOU_COM
  76. find: /^http:\/\/js\.tudouui\.com\/.*PortalPlayer[^\.]*\.swf/i,
  77. replace: 'tudou.swf'
  78. }, { // TUDOU_OUT
  79. find: /^http:\/\/www\.tudou\.com\/.*(\/v\.swf)?/i,
  80. replace: function(el, find) {
  81. var isFF = /firefox/i.test(navigator.userAgent),
  82. player = el.data || el.src;
  83.  
  84. GM_xmlhttpRequest({
  85. url: isFF ? player : 'http://gesion.duapp.com/tudou.php?' + encodeURIComponent(player),
  86. method: isFF ? 'HEAD' : 'GET',
  87. onload: function(response) {
  88. var url = isFF ? response.finalUrl : response.responseText;
  89. if (url) {
  90. url = url.replace(/http:\/\/js\.tudouui\.com\/.*?\/olc_[^.]*?\.swf/i, this.host + 'olc_8.swf');
  91. url = url.replace(/http:\/\/js\.tudouui\.com\/.*?\/SocialPlayer_[^.]*?\.swf/i, this.host + 'sp.swf');
  92. this.Reload.bind(this, el, find, url)();
  93. }
  94. }.bind(this)
  95. });
  96. }
  97. }, { // LETV_COM
  98. find: /^http:\/\/.*letv[\w]*\.com\/(hz|.*\/((?!(Live|seed|Disk))(S[\w]{2,3})?(?!Live)[\w]{4}|swf))Player*\.swf/i,
  99. replace: function(el, find) {
  100. /^baidu\.hz\.letv\.com/i.test(window.location.host) || this.Reload.bind(this, el, find, 'http://gesion.duapp.com/player/letv.swf')();
  101. }
  102. }, { // LETV_COM
  103. find: /^http:\/\/.*letv[\w]*\.com\/.*\/(letv-wrapper|letvbili|lbplayer)\.swf/i,
  104. replace: 'http://gesion.duapp.com/player/letv.swf'
  105. }, { // LETV_SKIN
  106. find: /^http:\/\/.*letv[\w]*\.com\/p\/\d+\/\d+\/(?!15)\d*\/newplayer\/\d+\/S?SLetvPlayer\.swf/i,
  107. replace: 'http://player.letvcdn.com/p/201407/24/15/newplayer/1/SSLetvPlayer.swf'
  108. }, { // LETV_CLOUD
  109. find: /^http:\/\/assets\.dwstatic\.com\/video\/vpp\.swf/i,
  110. replace: 'http://yuntv.letv.com/bcloud.swf'
  111. }, { // LETV_OUT
  112. find: /^http:\/\/.*letv\.com\/player\/swfplayer\.swf(\?.*)/i,
  113. replace: 'http://gesion.duapp.com/player/letv.swf$1'
  114. }, { // PPLIVE
  115. find: /^http:\/\/player\.pplive\.cn\/ikan\/.*\/player4player2\.swf/i,
  116. replace: 'pplive.swf'
  117. }, { // PPLIVE_LIVE
  118. find: /^http:\/\/player\.pplive\.cn\/live\/.*\/player4live2\.swf/i,
  119. replace: 'pplive_live.swf'
  120. }, { // SOHU_COM
  121. find: /^http:\/\/(tv\.sohu\.com\/upload\/swf\/(p2p\/)?\d+|(\d+\.){3}\d+\/webplayer)\/Main\.swf/i,
  122. replace: 'http://gesion.duapp.com/player/sohu/sohu_live.swf'
  123. }, { // SOHU_TEST
  124. find: /^http:\/\/61\.135\.176\.223:8080\/test\/player\/(Main|PlayerShell)\.swf/i,
  125. replace: 'http://gesion.duapp.com/player/sohu/sohu_live.swf'
  126. // }, { // SOHU_OUT
  127. // find: /^http:\/\/share\.vrs\.sohu\.com\/my\/v\.swf&?/i,
  128. // replace: 'http://gesion.duapp.com/player/sohu/sohu.swf?'
  129. }],
  130.  
  131. style: 'object,embed{-webkit-animation-duration:.001s;-webkit-animation-name:playerInserted;-ms-animation-duration:.001s;-ms-animation-name:playerInserted;-o-animation-duration:.001s;-o-animation-name:playerInserted;animation-duration:.001s;animation-name:playerInserted;}@-webkit-keyframes playerInserted{from{opacity:0.99;}to{opacity:1;}}@-ms-keyframes playerInserted{from{opacity:0.99;}to{opacity:1;}}@-o-keyframes playerInserted{from{opacity:0.99;}to{opacity:1;}}@keyframes playerInserted{from{opacity:0.99;}to{opacity:1;}}',
  132.  
  133. tips_html: '<span style="color:green">Onens.Clean.Player \u5DF2\u542F\u7528</span> &nbsp; <a href="http://gesion.duapp.com/script/onens.clean.player.user.js" style="color:red" title="\u5347\u7EA7\u65B0\u7248" target="_blank">\u5347\u7EA7</a> &nbsp; <a href="http://blog.onens.com/onens-clean-player.html" style="color:blue" title="\u53CD\u9988\u95EE\u9898" target="_blank">\u53CD\u9988</a> &nbsp; <a href="http://blog.onens.com/donation" style="color:orange" title="\u6350\u52A9\u9879\u76EE" target="_blank">\u6350\u52A9</a> &nbsp; <a href="javascript:;" class="tip_close" style="color:gray" title="\u9690\u85CF\u63D0\u793A">\u9690\u85CF</a>',
  134.  
  135. tips_style: '.tips_container{font:12px Arial, Verdana;padding:0 8px;cursor:default;border:1px solid #d5d5d5;line-height:25px;opacity:.2;background:#f5f5f5;position:fixed;right:0;bottom:-1px;z-index:999999}.tips_container:hover{opacity:.8}',
  136.  
  137. Handler: function(e) {
  138. if (e.animationName != 'playerInserted')
  139. return;
  140.  
  141. var el = e.target;
  142. if (this.done.indexOf(el) != -1)
  143. return;
  144.  
  145. this.done.push(el);
  146.  
  147. var player = el.data || el.src;
  148. if (!player)
  149. return;
  150.  
  151. for (var i in this.rule) {
  152. var find = this.rule[i]['find'];
  153. if (find.test(player)) {
  154. var replace = this.rule[i]['replace'];
  155. typeof replace == 'function' ? this.list.push(replace.bind(this, el, find)) : this.Reload.bind(this, el, find, replace)();
  156. }
  157. }
  158. },
  159.  
  160. Reload: function(el, find, replace) {
  161. replace = /^https?:\/\//i.test(replace) ? replace : this.host + replace;
  162. el.data && (el.data = el.data.replace(find, replace)) || el.src && ((el.src = el.src.replace(find, replace)) && (el.style.display = 'block'));
  163. var next = el.nextSibling,
  164. node = el.parentNode,
  165. elem = el.cloneNode(true);
  166. this.done.push(elem);
  167. if (node) {
  168. node.removeChild(el);
  169. next ? node.insertBefore(elem, next) : node.appendChild(elem);
  170. }
  171. this.Tips();
  172. },
  173.  
  174. Style: function(css) {
  175. var style = document.createElement('style');
  176. style.setAttribute('type', 'text/css');
  177. style.innerHTML = css || this.style;
  178. document.getElementsByTagName('head')[0].appendChild(style);
  179. },
  180.  
  181. Timer: function() {
  182. setInterval(function() {
  183. this.list.length && this.list.shift()();
  184. }.bind(this), 100);
  185. },
  186.  
  187. Tips: function() {
  188. if (this.done.indexOf('tips') != -1)
  189. return;
  190.  
  191. this.done.push('tips');
  192.  
  193. this.Style(this.tips_style);
  194.  
  195. var div = document.createElement('div');
  196. div.className = 'tips_container';
  197. div.innerHTML = this.tips_html;
  198. div.querySelector('.tip_close').addEventListener('click', function(e) {
  199. e.stopPropagation && e.stopPropagation();
  200. e.preventDefault && e.preventDefault();
  201. div.parentNode.removeChild(div);
  202. }, false);
  203. (document.documentElement || document.body).appendChild(div);
  204. },
  205.  
  206. Init: function() {
  207. var events = ['webkitAnimationStart', 'msAnimationStart', 'oAnimationStart', 'animationstart'];
  208. for (var i in events)
  209. document.addEventListener(events[i], this.Handler.bind(this), false);
  210.  
  211. this.Style();
  212. this.Timer();
  213. }
  214. };
  215.  
  216. OCPlayer.Init();