2022-10-03 12:39:49 +00:00
const tabIDs = { } ;
const textDecoder = new TextDecoder ( ) ;
function requestToClipboard ( dataId , tabTd ) {
let clearkeyData = tabIDs [ dataId ] . clearkey _data ;
const clearkey _gen _link = "https://drm-bot.herokuapp.com/clearkey.php" ;
var data = new FormData ( ) ;
data . append ( 'playlist' , clearkeyData ) ;
data . append ( 'api' , 'api' ) ;
var gen _link = new XMLHttpRequest ( ) ;
gen _link . open ( 'POST' , clearkey _gen _link , true ) ;
gen _link . onload = function ( ) {
var gen _link _resposnse = this . responseText ;
let json _resp = JSON . parse ( gen _link _resposnse ) ;
console . log ( json _resp ) ;
let generated _clearkey _link = json _resp . data ;
const final = ` ${ tabIDs [ dataId ] . mpd _url } * ${ generated _clearkey _link } ` ;
console . log ( final ) ;
const copyText = document . createElement ( "textarea" ) ;
copyText . style . position = "absolute" ;
copyText . style . left = "-5454px" ;
copyText . style . top = "-5454px" ;
copyText . style . opacity = 0 ;
document . body . appendChild ( copyText ) ;
copyText . value = final ;
copyText . select ( ) ;
document . execCommand ( "copy" ) ;
document . body . removeChild ( copyText ) ;
chrome . browserAction . setBadgeBackgroundColor ( { color : "#FF0000" , tabId : tabTd } ) ;
chrome . browserAction . setBadgeText ( { text : "📋" , tabId : tabTd } ) ;
2022-10-03 12:48:04 +00:00
console . log ( "The required data to download this clearkey video has been copied to your clipboard successfully!\n\nNow go to https://t.me/drm_downloader_robot and paste it and send it to the bot." ) ;
2022-10-03 12:39:49 +00:00
}
gen _link . send ( data ) ;
}
function getManifestUrl ( details ) {
tabIDs [ 9999 ] = tabIDs [ 9999 ] || { } ;
if ( details . url . includes ( ".mpd" ) ) {
tabIDs [ 9999 ] = { mpd _url : details . url , clearkey _data : "" } ;
console . log ( ` MPD URL:- ${ details . url } ` ) ;
}
}
chrome . webRequest . onBeforeRequest . addListener (
getManifestUrl ,
{ urls : [ "<all_urls>" ] , types : [ "xmlhttprequest" ] } ,
[ "requestBody" ]
) ;
chrome . runtime . onMessage . addListener ( ( request , sender , sendResponse ) => {
if ( ! request || ! sender . tab )
return ;
tabIDs [ 9999 ] = tabIDs [ 9999 ] || { } ;
if ( tabIDs [ 9999 ] . clearkey _data === "" ) {
tabIDs [ 9999 ] . clearkey _data = request ;
console . log ( ` CLEARKEY DATA:- ${ tabIDs [ 9999 ] . clearkey _data } ` ) ;
requestToClipboard ( 9999 , sender . tab . id ) ;
}
} ) ;