動畫瘋下載器

取得動畫的m3u8網址

目前为 2022-09-25 提交的版本。查看 最新版本

// ==UserScript==
// @name        動畫瘋下載器
// @namespace   
// @description 取得動畫的m3u8網址
// @version     1.2
// @author      maple3142/XPRAMT
// @match       https://ani.gamer.com.tw/animeVideo.php?sn=*
// @connect     ani.gamer.com.tw
// @require     https://cdn.jsdelivr.net/npm/[email protected]/dist/m3u8-parser.min.js
// @require     https://unpkg.com/[email protected]/xfetch.min.js
// @require     https://unpkg.com/[email protected]/gmxhr-fetch.min.js
// @grant       GM_xmlhttpRequest
// @grant       unsafeWindow
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

(function () {
	'use strict';

	var $ = jQuery;
    const select = (DOM) => document.querySelector(DOM);

    var Name=document.title.replace(" 線上看 - 巴哈姆特動畫瘋","");

	function cvtM3U8_to_playlist(baseurl) {
	  return function (m3u8) {
	    var parser = new m3u8Parser.Parser();
	    parser.push(m3u8);
	    parser.end();
	    var pls = parser.manifest.playlists.map(function (pl) {
	      return {
	        url: new URL(pl.uri,baseurl)+'@'+Name,
	        res: pl.attributes.RESOLUTION
	      };
	    });
	    return pls;
	  };
	}

	function render(pls) {
	  pls.map(function(pl){return $('<a>').addClass('anig-tb').text(pl.res.height + 'p').on('click', function (e) {navigator.clipboard.writeText(pl.url);} ) } ).
      forEach(function(el){return m3u8container.append(el);} );
    }

	function onPlaylistUrl(playlisturl) {
	  if (playlisturl.indexOf('gamer_ad') !== -1) {
	    //is ad
	    return;
	  }

    var baseurl = playlisturl.replace(/playlist\.m3u8.*/, '');

        fetch(playlisturl).
        then(function (r) {return r.text();}).
        then(cvtM3U8_to_playlist(baseurl)).
        then(function (pls) {return window.unsafeWindow = pls;}).
        then(render);}

	var it = setInterval(function () {
	  if (typeof videojs !== 'undefined' && videojs.getPlayer('ani_video')) {
	    clearInterval(it);
	    var vid = videojs.getPlayer('ani_video');
	    unsafeWindow.ani_video = vid;
	    var fn = vid.src.bind(vid);

	    vid.src = function (src) {
	      if (!src) {
	        return fn();
	      }

	      onPlaylistUrl(typeof src === 'string' ? src : src.src);
	      fn(src);
	    };
	  }
	}, 100);

	var title_display = $('<div>').addClass('anig-tb').addClass('state').text('點擊下方複製連結');
	var m3u8container = $('<div>').addClass('anig-ct');

    //顯示按鍵
	$('.anime_name').append($('<div>').addClass('anig-ct').append(title_display)).append(m3u8container);

    //樣式
	function styleInject(css, ref) {
	  if ( ref === void 0 ) ref = {};
	  var insertAt = ref.insertAt;

	  if (!css || typeof document === 'undefined') { return; }

	  var head = document.head || document.getElementsByTagName('head')[0];
	  var style = document.createElement('style');
	  style.type = 'text/css';

	  if (insertAt === 'top') {
	    if (head.firstChild) {
	      head.insertBefore(style, head.firstChild);
	    } else {
	      head.appendChild(style);
	    }
	  } else {
	    head.appendChild(style);
	  }

	  if (style.styleSheet) {
	    style.styleSheet.cssText = css;
	  } else {
	    style.appendChild(document.createTextNode(css));
	  }
	}

	var css = ".anig-ct {\r\n\tdisplay: flex;\r\n\twidth: 100%;\r\n\tmargin: 5px;\r\n}\r\n\r\n.anig-tb {\r\n\tdisplay: inline-block;\r\n\tpadding: 5px;\r\n\tbackground: #00B4D8;\r\n\tcolor: #FFF;\r\n\tmargin-right: 5px;\r\n\tborder: 1px solid #BBB;\r\n}\r\n\r\n.tdn{\r\n\ttext-decoration: none;\r\n}\r\n";
	styleInject(css);

}());

QingJ © 2025

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