HTML5 on TINGSHEN

Replace Flash Player with HTML5 Player on tingshen.court.gov.cn

当前为 2020-03-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name HTML5 on TINGSHEN
  3. // @namespace https://coding.net/u/sffxzzp
  4. // @version 0.3
  5. // @description Replace Flash Player with HTML5 Player on tingshen.court.gov.cn
  6. // @author sffxzzp
  7. // @match *://tingshen.court.gov.cn/live*
  8. // @match *://tingshen.court.gov.cn/court*
  9. // @require https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.js
  10. // @require https://cdn.jsdelivr.net/npm/hls.js/dist/hls.min.js
  11. // @icon http://tingshen.court.gov.cn/static/img/favorite.ico
  12. // @connect player.videoincloud.com
  13. // @grant GM_xmlhttpRequest
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. var util = (function () {
  18. function util() {}
  19. util.xhr = function (xhrData) {
  20. return new Promise(function(resolve, reject) {
  21. if (!xhrData.xhr) {
  22. GM_xmlhttpRequest({
  23. method: xhrData.method || "get",
  24. url: xhrData.url,
  25. responseType: xhrData.type || "",
  26. timeout: 3e4,
  27. onload: function onload(res) {
  28. return resolve({ response: res, body: res.response });
  29. },
  30. onerror: reject,
  31. ontimeout: reject
  32. });
  33. } else {
  34. var xhr = new XMLHttpRequest();
  35. xhr.open(
  36. xhrData.method || "get",
  37. xhrData.url,
  38. true
  39. );
  40. if (xhrData.method === "POST") {
  41. xhr.setRequestHeader(
  42. "content-type",
  43. "application/x-www-form-urlencoded; charset=utf-8"
  44. );
  45. }
  46. if (xhrData.cookie) xhr.withCredentials = true;
  47. xhr.responseType = xhrData.responseType || "";
  48. xhr.timeout = 3e4;
  49. xhr.onload = function(ev) {
  50. var evt = ev.target;
  51. resolve({ response: evt, body: evt.response });
  52. };
  53. xhr.onerror = reject;
  54. xhr.ontimeout = reject;
  55. xhr.send(xhrData.data);
  56. }
  57. });
  58. };
  59. return util;
  60. })();
  61. var h5onCourt = (function () {
  62. function h5onCourt() {};
  63. h5onCourt.prototype.parseDOM = function (string) {
  64. var div = document.createElement('div');
  65. div.innerHTML = string;
  66. return div;
  67. }
  68. h5onCourt.prototype.addPlayer = function (url) {
  69. var h5css = document.createElement('link');
  70. h5css.rel = 'stylesheet';
  71. h5css.href = 'https://cdn.jsdelivr.net/npm/dplayer/dist/DPlayer.min.css';
  72. document.head.appendChild(h5css);
  73. var iframes = document.getElementsByTagName('iframe');
  74. var container = iframes[iframes.length-1].parentNode;
  75. container.innerHTML = '<div id="dplayer" style="width: 100%; height: 100%;"></div>';
  76. var dp = new DPlayer({
  77. container: container.children[0],
  78. video: {
  79. url: url,
  80. type: 'hls'
  81. }
  82. });
  83. }
  84. h5onCourt.prototype.run = function () {
  85. var _this = this;
  86. var iframes = document.getElementsByTagName('iframe');
  87. var extLink = iframes[iframes.length-1].getAttribute('src');
  88. util.xhr({
  89. url: extLink
  90. }).then(function (res) {
  91. var node = _this.parseDOM(res.body);
  92. var tIndex = 0;
  93. for (tIndex=0;tIndex<node.children.length;tIndex++) {
  94. if (node.children[tIndex].innerHTML.indexOf('flashvars')>-1) {
  95. break;
  96. }
  97. }
  98. var flashvars = node.children[tIndex].innerHTML;
  99. flashvars = /flashvars.file.*?=.*?encodeURIComponent\(\"(.+?)\"\)/.exec(flashvars)[1];
  100. if (flashvars.length>0) {
  101. _this.addPlayer(flashvars);
  102. }
  103. });
  104. };
  105. return h5onCourt;
  106. })();
  107. var program = new h5onCourt();
  108. program.run();
  109. })();