Skip to content

Instantly share code, notes, and snippets.

@zoubingwu
Last active September 28, 2023 18:09
Show Gist options
  • Save zoubingwu/a374e532c9f7d9817c7546e8b72f78c2 to your computer and use it in GitHub Desktop.
Save zoubingwu/a374e532c9f7d9817c7546e8b72f78c2 to your computer and use it in GitHub Desktop.
jabletv m3u8 getter
// ==UserScript==
// @name jabletv m3u8 getter
// @namespace http://tampermonkey.net/
// @version 0.1
// @description copy m3u8 url on jabletv
// @author You
// @match https://jable.tv/videos/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=jable.tv
// @grant none
// ==/UserScript==
;(function () {
const container = document.querySelector('.info-header > .header-left > h6')
const copyIconSvg = document.createElement('div')
copyIconSvg.style.cursor = 'pointer'
copyIconSvg.style.marginLeft = '8px'
copyIconSvg.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copy" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M8 8m0 2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2z"></path>
<path d="M16 8v-2a2 2 0 0 0 -2 -2h-8a2 2 0 0 0 -2 2v8a2 2 0 0 0 2 2h2"></path>
</svg>`
copyIconSvg.addEventListener('click', () => {
const m3U8Url = findInlineScriptTagsAndSearchForM3U8Url()
console.log('found m3U8Url: ', m3U8Url)
const cover = findCover()
const { title, code } = findTitle()
if (m3U8Url) {
navigator.clipboard.writeText(JSON.stringify({ url: m3U8Url, cover, title, code }))
console.log('copied!')
copyIconSvg.style.color = 'green'
} else {
copyIconSvg.style.color = 'red'
}
setTimeout(() => {
copyIconSvg.style.color = ''
}, 2000)
})
// Append the SVG element to the DOM.
container.appendChild(copyIconSvg)
function findInlineScriptTagsAndSearchForM3U8Url() {
// Get all the inline script tags.
const scriptTags = document.querySelectorAll('script')
// Loop through all the script tags and search for a URL that ends with `.m3u8`.
for (const scriptTag of scriptTags) {
const scriptText = scriptTag.textContent
const m3U8UrlMatch = scriptText.match(/https?:\/\/[^\/]+\/.+\.m3u8/)
if (m3U8UrlMatch) {
// Return the URL that ends with `.m3u8`.
return m3U8UrlMatch[0]
}
}
// If no URL that ends with `.m3u8` is found, return `null`.
return null
}
function findCover() {
const ogtag = document.querySelector('meta[property="og:image"]')
if (ogtag && ogtag.content && ogtag.content.endsWith('.jpg')) {
return ogtag.content
}
}
function findTitle() {
const ogtag = document.querySelector('meta[property="og:title"]')
if (ogtag && ogtag.content) {
return { title: ogtag.content, code: ogtag.content.split(' ').at(0) }
}
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment