動畫瘋工具箱

取得動畫的 m3u8 網址,下載彈幕為 json,去除擋廣告的警告訊息

目前為 2018-03-11 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 動畫瘋工具箱
  3. // @namespace https://blog.maple3142.net/
  4. // @description 取得動畫的 m3u8 網址,下載彈幕為 json,去除擋廣告的警告訊息
  5. // @version 0.5
  6. // @author maple3142
  7. // @match https://ani.gamer.com.tw/animeVideo.php?sn=*
  8. // @require https://cdn.jsdelivr.net/npm/m3u8-parser@4.2.0/dist/m3u8-parser.min.js
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. function hookSetter(obj, prop, cb) {
  16. Object.defineProperty(obj, prop, {
  17. set: cb
  18. });
  19. }
  20. function cvtM3U8_to_playlist(baseurl) {
  21. return function (m3u8) {
  22. var parser = new m3u8Parser.Parser();
  23. parser.push(m3u8);
  24. parser.end();
  25. var pls = parser.manifest.playlists.map(function (pl) {
  26. return {
  27. url: 'https:' + baseurl + pl.uri,
  28. res: pl.attributes.RESOLUTION
  29. };
  30. });
  31. return pls;
  32. };
  33. }
  34.  
  35.  
  36. var $ = jQuery;
  37.  
  38. requirejs.config({
  39. baseUrl: '//i2.bahamut.com.tw',
  40. waitSeconds: 0,
  41. paths: {
  42. order: 'js/order'
  43. },
  44. shim: {
  45. viblast: {},
  46. vastvpaid: {
  47. deps: ['videojs']
  48. }
  49. }
  50. });
  51. requirejs(['order!videojs'], function (videojs) {
  52. return hookSetter(videojs.players, 'ani_video', function onAniVideo(vid) {
  53. window.ani_video = vid; //EXPOSE
  54.  
  55. hookSetter(vid.K, 'src', onPlaylistUrl);
  56. });
  57. });
  58.  
  59. function render(pls) {
  60. var html = pls.map(function (pl) {
  61. return "<div><label for=\"".concat(pl.res.height, "p\">").concat(pl.res.height, "P: </label><input id=\"").concat(pl.res.height, "p\" value=\"").concat(pl.url, "\" style=\"width: 500px;\"></div>");
  62. }).join('');
  63. $('.anime_name').append("<div id=\"anigamer_m3u8_warpper\">".concat(html, "</div>"));
  64. }
  65.  
  66. function onPlaylistUrl(playlisturl) {
  67. if (playlisturl.indexOf('gamer_ad') !== -1) {
  68. //is ad
  69. return;
  70. }
  71.  
  72. var baseurl = playlisturl.replace(/index\.m3u8.*/, '');
  73. fetch(playlisturl).then(function (r) {
  74. return r.text();
  75. }).then(cvtM3U8_to_playlist(baseurl)).then(function (pls) {
  76. return window.M3U8_PLAYLIST = pls;
  77. }) //EXPOSE
  78. .then(render);
  79. }
  80.  
  81. hookSetter(animefun, 'danmu', function (danmu) {
  82. var text = JSON.stringify(danmu);
  83. var title = $('.anime_name h1').text();
  84. $('.anime_name').append($('<a href="javascript:void(0)">把彈幕存成檔案</a>').on('click', function () {
  85. saveTextAsFile(text, "".concat(title, "_\u5F48\u5E55.json"));
  86. }));
  87. });
  88.  
  89. //extra: block anti adblock alert
  90. var orig_alert = alert;
  91.  
  92. alert = function alert(t) {
  93. if (t.includes('由於擋廣告插件會影響播放器運作')) return;
  94. orig_alert(t);
  95. };
  96.  
  97. }());

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址