// ==UserScript== // @name M3u8 // @description 解析 或 破解 vip影视 的时候,使用的 《在线播放器》 和 《在线VIP解析接口》 和 《第三方影视野鸡网站》 全局通用 拦截和过滤 (解析资源/采集资源) 的 插播广告切片 个人自用脚本 // @version 20241221 // @author 江小白 // @match https://v.68sou.com/ // @include /\/\?id=[a-zA-Z\d]+?$/ // @include /\/[pP]lay(?:\/|\?id=\d)/ // @include /(?:lay|ideo).*?\.html/ // @include /^https?:\/\/(?:movie\.douban\.com\/subject|m\.douban\.com\/movie)\// // @include /^https?:\/\/.+?(?typeof arg === 'string' ? arg : arg instanceof Request ? arg.url : String(arg); const matchM3u = url=>{ spbfurl = url; const matchedItem = itemsHandle.find(item=>item.reUrl.test(url) && !mp4wz.test(url) && !flvwz.test(url) && !tswz.test(url) && !playsharewz.test(url) && !ggbmd.test(url)); itemsHandleby.forEach(byItem=>byItem.reUrl.test(url) && byItem.reAds.forEach(newReAd=>matchedItem.reAds.find(ad=>ad.source === newReAd.source && ad.flags === newReAd.flags) || matchedItem.reAds.push(newReAd))); return matchedItem; } ; const M3umatch = text=>{ try { if (!text || !new RegExp(tyad5,'i').test(text) || !tyad107.test(text)) { return true; } else { return false; } } catch (e) { return false; } } ; const M3umatchu3M = (array,regExp)=>{ return array.some(function(item) { return item.toString() === regExp.toString(); }); } ; const m3u8text = (text)=>{ try { const regex = /^[a-z\d]{20,}/i; const extensionRegex = new RegExp(tyad5,'i'); const lines = text.split('\n'); let count = 0; for (let line of lines) { const trimmedLine = line.trim(); if (extensionRegex.test(trimmedLine)) { const match = trimmedLine.match(extensionRegex); if (match) { const extension = match[0]; const fileName = trimmedLine.slice(0, -extension.length); if (!regex.test(fileName)) { return false; } } } if (/0{2,}\d+$/.test(trimmedLine)) { count++; if (count >= 20) { return false; } } } return true; } catch (e) { return false; } } ; const deleteAbnormalTs = (text,jxbgza,jxbgzb,jxbgzc,jxbgzd,jxbgze)=>{ try { if (!shouldStopExecution) { if (text) { if (!tyad107.test(text)) { return text; } else { if (ggljbmd.test(text)) { shouldStopExecution = true; return text; } else { if (ggljdmb.test(text)) { if (new RegExp(tyad1022,'i').test(text)) { if (!new RegExp(tyad5 + '\\?','i').test(text)) { if (new RegExp(tyad5 + hhzz,'i').test(text)) { if (!jxbgzd) { jxbgzd = /^\s*?(?:[a-z]+?(?:\s*?-\s*?)?)?\d+?\s*?$/i; } else if (jxbgzd == '空') { jxbgzd = /^\s*?空\s*?$/; } try { const rgtya = tyad1015 , rgtyb = jxbgza + tyad1016 , regex = '(?<=' + rgtya + ')(' + jxbgzb + ')(?=' + rgtyb + ')' , regexx = new RegExp(regex,'gi') , tsPaths = text.match(new RegExp('(?:(?<=' + tyad1015 + '))?' + bhhzz + '+?(?=' + tyad1016 + ')','gi')) , matches = text.match(regexx) , paths = {}; if (!jxbgze || jxbgze == '空' || (Number.isInteger(Number(jxbgze)) && tsPaths && tsPaths.length < jxbgze)) { for (let i = 0; i < matches.length; i++) { const path = matches[i]; if (!paths[path]) { paths[path] = []; } paths[path].push(path); } let maxCount = 0 , maxPath = ''; for (const path in paths) { if (paths[path].length > maxCount) { maxCount = paths[path].length; maxPath = path; } } for (const path in paths) { if (path !== maxPath) { paths[path].forEach(p=>{ if (!jxbgzd.test(p)) { text = text.replace(new RegExp(rgtya + p + rgtyb,'gi'), (match)=>{ try { if (!dypd.test(打印)) { try { console.log(logysa + "广告资源" + logysb + jxbgzc + logysd + regexx + logyse + "%c" + match.replace(new RegExp(tyad1023,'gi'), tsLink=>{ if (!tsLink.startsWith('http')) { if (m3u8gglj) { return new URL(tsLink,m3u8gglj).href; } else { return tsLink; } } else { return tsLink; } } ), logysf, logysg, logysh, logysg, logysi); } catch (e) { try { console.log(logysa + "广告资源" + logysb + jxbgzc + logysd + regexx + logyse + "%c" + match, logysf, logysg, logysh, logysg, logysi); } catch (e) {} } } } catch (e) {} try { if (!ggtspd) { ggtspd = true; } } catch (e) {} return ''; } ); } } ); } } } } catch (e) {} } } } return text; } else { return text; } } } } else { return text; } } else { return text; } } catch (e) { return text; } } ; const pruner = (text,item)=>{ try { if (!shouldStopExecution) { if (text) { if (!tyad107.test(text)) { return text; } else { if (ggljbmd.test(text)) { shouldStopExecution = true; return text; } else { try { if ((!(new RegExp(itemsdpgza,'i').test(text) && ggljdmb.test(text))) && !new RegExp(tyad1014 + tyad1021,'i').test(text)) { gggzdp = true; } else { try { itemsHandle.forEach(item=>{ item.reAds = item.reAds.filter(re=>re.source !== itemsdpgza); } ); } catch (e) {} gggzdp = false; } } catch (e) { gggzdp = false; } if (ggljdmb.test(text) || !!gggzdp) { try { if (!gggzpd) { gggzpd = true; try { if (new RegExp(itemspdgza,'i').test(text) && new RegExp(itemstygza1,'i').test(text)) { itemsHandle.forEach(item=>{ item.reAds = item.reAds.filter(re=>re.source !== itemstygza1); } ); } } catch (e) {} try { if (!(new RegExp(itemspdgza,'i').test(text) && new RegExp(itemstygza,'i').test(text))) { itemsHandle.forEach(item=>{ item.reAds = item.reAds.filter(re=>re.source !== itemstygza); } ); } } catch (e) {} if (!dypd.test(打印)) { console.table(itemsPaichu); console.table(itemsHandle); console.log("播放链接:" + spbfurl); } } } catch (e) {} let modifiedText; try { if (itemsPaichu.some(regex=>regex.test(text))) { try { if (!M3umatchu3M(itemsHandle[0].reAds, itemstygza5)) { itemsHandle[0].reAds.push(itemstygza5); } } catch (e) {} modifiedText = text; } else { if (new RegExp(tyadb + bhhzz + '+?\\.(?:' + ggzlhx + ')\\?' + tyad1017,'i').test(text)) { modifiedText = text; } else { if (m3u8text(text)) { modifiedText = text; } else { try { if (text.match(itemstygza2)) { const matchessc = text.match(itemstygza3); if (matchessc) { try { if (!dypd.test(打印)) { console.log(logysa + "资源广告" + logysc + itemstygza3 + logyse, logysf, logysg, logysh, logysg); matchessc.forEach(match=>{ console.log(match); } ); } } catch (e) {} modifiedText = text.replace(itemstygza3, ''); } else { modifiedText = deleteAbnormalTs(text, '[^\\.]+?', '(?:' + bhhzz + '+\\\/|\\b)', '路径'); } } else { modifiedText = deleteAbnormalTs(text, '[^\\.]+?', '(?:' + bhhzz + '+\\\/|\\b)', '路径'); } } catch (e) { modifiedText = text; } try { if (!text.match(itemstygza4)) { modifiedText = deleteAbnormalTs(modifiedText, '(?:\\d+?|[a-z]+?)', '\\w+?(?:[^\\d]\\d{2})?', '名称'); } } catch (e) {} try { modifiedText = deleteAbnormalTs(modifiedText, '\\d+?', '\\w+(?=\\d{3})', '名称', '空', 100); } catch (e) {} try { modifiedText = deleteAbnormalTs(modifiedText, '\\d+?', '\\w+(?=\\d{4})', '名称', '空'); } catch (e) {} try { modifiedText = deleteAbnormalTs(modifiedText, '\\d+?', '[^0]\\d+[^0]0{2,}\\d0', '名称', /(?<=[^0]0{3,})\d+$/); } catch (e) {} } } } } catch (e) { modifiedText = text; } for (const reAd of item.reAds) { const matches = modifiedText.match(reAd); if (matches) { matches.forEach(match=>{ try { if (!dypd.test(打印)) { try { console.log(logysa + "资源广告" + logysc + reAd + logyse + "%c" + match.replace(new RegExp(tyad1023,'gi'), tsLink=>{ if (!tsLink.startsWith('http')) { if (m3u8gglj) { return new URL(tsLink,m3u8gglj).href; } else { return tsLink; } } else { return tsLink; } } ), logysf, logysg, logysh, logysg, logysi); } catch (e) { try { console.log(logysa + "资源广告" + logysc + reAd + logyse + "%c" + match, logysf, logysg, logysh, logysg, logysi); } catch (e) {} } } } catch (e) {} } ); try { if (!ggtspd) { ggtspd = true; } } catch (e) {} } modifiedText = modifiedText.replace(reAd, ""); } if (modifiedText.length < text.length) { return modifiedText; } return text; } else { return text; } } } } else { return text; } } else { return text; } } catch (e) { return text; } } ; const prunerm3u8 = (text)=>{ try { if (!shouldStopExecution) { if (text) { if (!tyad107.test(text)) { return text; } else { if (ggljbmd.test(text)) { shouldStopExecution = true; return text; } else { if (!shouldStopExecution) { const extensionRegex = new RegExp(tyad2,'i'); const lines = text.split('\n'); let discontinuityCount = 0; const filteredLines = lines.filter(line=>{ if (extensionRegex.test(line)) { discontinuityCount++; return false; } return true; } ); const result = filteredLines.join('\n'); try { if (discontinuityCount > 1) { if (!dypd.test(打印)) { console.log(logysa + logysj + "-已经发现] ✂" + '已删除《' + discontinuityCount + '》个' + tyad2 + logysj, logysf); } } } catch (e) {} return result; } else { return text; } } } } else { return text; } } else { return text; } } catch (e) { return text; } } ; const realFetch = self.fetch; self.fetch = new Proxy(self.fetch,{ apply(target, thisArg, args) { const item = matchM3u(urlFromArg(args[0])); if (!item) { return Reflect.apply(target, thisArg, args); } if (!shouldStopExecution) { return realFetch(...args).then(realResponse=>realResponse.text().then(text=>{ const modifiedText = pruner(text, item); try { if (M3umatch(modifiedText)) { return realResponse; } } catch (e) {} return new Response(modifiedText,{ status: realResponse.status, statusText: realResponse.statusText, headers: realResponse.headers }); } )); } else { return Reflect.apply(target, thisArg, args); } } }); self.XMLHttpRequest.prototype.open = new Proxy(self.XMLHttpRequest.prototype.open,{ apply: async(target,thisArg,args)=>{ try { if (!shouldStopExecution) { urlFromArgBy = urlFromArg(args[1]); const item = matchM3u(urlFromArgBy); if (item) { if (ggljbmd.test(urlFromArgBy) || !!shouldStopExecution) { shouldStopExecution = true; return Reflect.apply(target, thisArg, args); } else { m3u8gglj = urlFromArgBy; try { if (wzm3u8.test(m3u8gglj) && !mp4wz.test(m3u8gglj) && !flvwz.test(m3u8gglj) && !tswz.test(m3u8gglj) && !playsharewz.test(m3u8gglj)) { m3u8bflj = m3u8gglj; } } catch (e) {} thisArg.addEventListener('readystatechange', async function() { if (thisArg.readyState !== 4) { return; } const type = thisArg.responseType; if (type !== '' && type !== 'text') { return; } const textin = thisArg.responseText; try { if (M3umatch(textin)) { return; } } catch (e) {} const textout = pruner(textin, item); try { if (M3umatch(textout)) { return; } } catch (e) {} try { textout = prunerm3u8(textout); } catch (e) {} if (textout !== textin) { Reflect.defineProperty(thisArg, 'response', { value: textout }); Reflect.defineProperty(thisArg, 'responseText', { value: textout }); } }); return Reflect.apply(target, thisArg, args); } } else { return Reflect.apply(target, thisArg, args); } } else { return Reflect.apply(target, thisArg, args); } } catch (e) { return Reflect.apply(target, thisArg, args); } } }); } } catch (e) {} } } catch (e) {} } )();