Greasy Fork is available in English.

取得動畫瘋 m3u8 網址

RT

Pada tanggal 11 Maret 2018. Lihat %(latest_version_link).

// ==UserScript==
// @name         取得動畫瘋 m3u8 網址
// @namespace    https://blog.maple3142.net/
// @version      0.3
// @description  RT
// @author       maple3142
// @match        https://ani.gamer.com.tw/animeVideo.php?sn=*
// @require      https://cdn.jsdelivr.net/npm/m3u8-parser@4.2.0/dist/m3u8-parser.min.js
// @grant        none
// ==/UserScript==

; (function ($) {
	'use strict'
	//in order to get videojs instance
	requirejs.config({
		baseUrl: '//i2.bahamut.com.tw',
		waitSeconds: 0,
		paths: {
			order: 'js/order'
		},
		shim: {
			viblast: {},
			vastvpaid: {
				deps: ['videojs']
			}
		}
	})
	requirejs(['order!videojs'], videojs => hookSetter(videojs.players, 'ani_video', on_ani_video))
	function hookSetter(obj, prop, cb) {
		Object.defineProperty(obj, prop, {
			set: cb
		})
	}
	function render(pls) {
		const html = pls
			.map(
				pl =>
					`<div><label for="${pl.res.height}p">${pl.res.height}P: </label><input id="${
					pl.res.height
					}p" value="${pl.url}" style="width: 500px;"></div>`
			)
			.join('')
		$('.anime_name').append(`<div id="anigamer_m3u8_warpper">${html}</div>`)
	}
	function on_ani_video(vid) {
		window.ani_video = vid //EXPOSE
		hookSetter(vid.K, 'src', on_playlisturl)
	}
	function on_playlisturl(playlisturl) {
		console.log(playlisturl)
		if (playlisturl.indexOf('gamer_ad') !== -1) {
			//is ad
			return
		}
		const baseurl = playlisturl.replace(/index\.m3u8.*/, '')
		fetch(playlisturl)
			.then(r => r.text())
			.then(m3u8 => {
				const parser = new m3u8Parser.Parser()
				parser.push(m3u8)
				parser.end()
				const pls = parser.manifest.playlists.map(pl => ({
					url: 'https:' + baseurl + pl.uri,
					res: pl.attributes.RESOLUTION
				}))
				window.M3U8_PLAYLIST = pls //EXPOSE
				return pls
			})
			.then(render)
	}

	//extra: block anti adblock alert
	const orig_alert = alert
	alert = function (t) {
		if (t.includes('由於擋廣告插件會影響播放器運作')) return
		orig_alert(t)
	}
})(jQuery)