forked from 1gabe1/crp-iframe-player
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
229 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
chrome.webRequest.onHeadersReceived.addListener( | ||
function(details) { | ||
const newHeader = {name: 'Access-Control-Allow-Origin', value: '*'}; | ||
const responseHeaders = details.responseHeaders.concat(newHeader); | ||
return { responseHeaders }; | ||
}, | ||
{ | ||
urls: ["https://*.mateus7g.github.io/*", "https://pl.crunchyroll.com/*", "https://www.crunchyroll.com/*", "http://localhost/*"], | ||
types : ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"] | ||
}, | ||
["blocking","responseHeaders", "extraHeaders"] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,178 @@ | ||
var HTML = document.documentElement.innerHTML; | ||
const query = qry => document.body.querySelector(qry) | ||
var preservedState = null | ||
|
||
//function que pega algo dentro dentro do html. | ||
function pegaString(str, first_character, last_character) { | ||
if(str.match(first_character + "(.*)" + last_character) == null){ | ||
return null; | ||
}else{ | ||
new_str = str.match(first_character + "(.*)" + last_character)[1].trim() | ||
return(new_str) | ||
} | ||
if(str.match(first_character + "(.*)" + last_character) == null){ | ||
return null; | ||
} else { | ||
new_str = str.match(first_character + "(.*)" + last_character)[1].trim() | ||
return new_str; | ||
} | ||
} | ||
|
||
//function para remover elementos da página | ||
function remove(element, name, untilRemoved = false, callback = () => {}) { | ||
let tries = 0; | ||
if (untilRemoved) { | ||
const finishRemove = setInterval(() => { | ||
if (query(element) != null) { | ||
clearInterval(finishRemove) | ||
console.log(`[CR Premium] Removendo ${name}...`); | ||
const closeBtn = query(element + ' > .close-button') | ||
if (closeBtn) closeBtn.click() | ||
else query(element).style.display = 'none'; | ||
|
||
callback() | ||
} | ||
else if (tries > 250) clearInterval(finishRemove) | ||
else tries++ | ||
}, 20) | ||
} else if (query(element) != null) { | ||
console.log(`[CR Premium] Removendo ${name}...`); | ||
query(element).style.display = 'none'; | ||
} | ||
} | ||
|
||
//function que mudar o player para um mais simples. | ||
function importPlayer(){ | ||
console.log("[CR Premium] Removendo player da Crunchyroll..."); | ||
var elem = document.getElementById('showmedia_video_player'); | ||
elem.parentNode.removeChild(elem); | ||
|
||
console.log("[CR Premium] Pegando dados da stream..."); | ||
var video_config_media = JSON.parse(pegaString(HTML, "vilos.config.media = ", ";")); | ||
|
||
console.log("[CR Premium] Adicionando o jwplayer..."); | ||
ifrm = document.createElement("iframe"); | ||
ifrm.setAttribute("id", "frame"); | ||
ifrm.setAttribute("src", "https://mateus7g.github.io/crp-iframe-player/"); | ||
ifrm.setAttribute("width","100%"); | ||
ifrm.setAttribute("height","100%"); | ||
ifrm.setAttribute("frameborder","0"); | ||
ifrm.setAttribute("scrolling","no"); | ||
ifrm.setAttribute("allowfullscreen","allowfullscreen"); | ||
ifrm.setAttribute("allow","autoplay; encrypted-media *"); | ||
|
||
if(document.body.querySelector("#showmedia_video_box") != null){ | ||
document.body.querySelector("#showmedia_video_box").appendChild(ifrm); | ||
}else{ | ||
document.body.querySelector("#showmedia_video_box_wide").appendChild(ifrm); | ||
} | ||
|
||
//Remove Nota do topo sobre experimentar o premium | ||
if (document.body.querySelector(".freetrial-note") != null) { | ||
console.log("[CR Premium] Removendo Free Trial Note..."); | ||
document.body.querySelector(".freetrial-note").style.display = "none"; | ||
} | ||
|
||
//Remove avisos q o video nn pode ser visto | ||
if(document.body.querySelector(".showmedia-trailer-notice") != null){ | ||
console.log("[CR Premium] Removendo Trailer Notice..."); | ||
document.body.querySelector(".showmedia-trailer-notice").style.display = "none"; | ||
} | ||
|
||
//Remove sugestão de inscrever-se para o trial gratuito | ||
if(document.body.querySelector("#showmedia_free_trial_signup") != null){ | ||
console.log("[CR Premium] Removendo Free Trial Signup..."); | ||
document.body.querySelector("#showmedia_free_trial_signup").style.display = "none"; | ||
} | ||
|
||
// Simular interação do usuário para deixar em fullscreen automaticamente | ||
var element = document.getElementById("template_scroller"); | ||
if (element) element.click(); | ||
|
||
const series = document.querySelector('meta[property="og:title"]'); | ||
const up_next = document.querySelector('link[rel=next]'); | ||
chrome.storage.sync.get(['aseguir', 'cooldown'], function(items) { | ||
ifrm.onload = function(){ | ||
ifrm.contentWindow.postMessage({ | ||
'video_config_media': [JSON.stringify(video_config_media)], | ||
'lang': [pegaString(HTML, 'LOCALE = "', '",')], | ||
'series': series ? series.content : undefined, | ||
'up_next': up_next ? up_next.href : undefined, | ||
'up_next_cooldown': items.cooldown === undefined ? 5 : items.cooldown, | ||
'up_next_enable': items.aseguir === undefined ? true : items.aseguir, | ||
'version': "1.0.3" | ||
},"*"); | ||
}; | ||
}); | ||
|
||
//console.log(video_config_media); | ||
var HTML = document.documentElement.innerHTML; | ||
console.log("[CR Old] Removendo player da Crunchyroll..."); | ||
var elem = document.getElementById('showmedia_video_player'); | ||
elem.parentNode.removeChild(elem); | ||
|
||
console.log("[CR Old] Pegando dados da stream..."); | ||
var video_config_media = JSON.parse(pegaString(HTML, "vilos.config.media = ", ";")); | ||
|
||
//Remove Nota do topo sobre experimentar o premium | ||
//Remove avisos q o video nn pode ser visto | ||
//Remove sugestão de inscrever-se para o trial gratuito | ||
remove(".freetrial-note", "Free Trial Note") | ||
remove(".showmedia-trailer-notice", "Trailer Notice") | ||
remove("#showmedia_free_trial_signup", "Free Trial Signup") | ||
|
||
// Simular interação do usuário para deixar em fullscreen automaticamente | ||
var element = document.getElementById("template_scroller"); | ||
if (element) element.click(); | ||
|
||
const appendTo = query("#showmedia_video_box") || query("#showmedia_video_box_wide") | ||
const series = document.querySelector('meta[property="og:title"]'); | ||
const up_next = document.querySelector('link[rel=next]'); | ||
|
||
var message = { | ||
'video_config_media': [JSON.stringify(video_config_media)], | ||
'lang': [pegaString(HTML, 'LOCALE = "', '",')], | ||
'series': series ? series.content : undefined, | ||
'up_next': up_next ? up_next.href : undefined, | ||
} | ||
|
||
console.log("[CR Old] Adicionando o jwplayer..."); | ||
addPlayer(appendTo, message) | ||
} | ||
|
||
//renderiza player na versão beta | ||
function importBetaPlayer(ready = false) { | ||
var videoPlayer = query('.video-player'); | ||
if (!ready) { | ||
setTimeout(() => importBetaPlayer(!!videoPlayer), 100); | ||
return; | ||
} | ||
|
||
console.log("[CR Beta] Removendo player da Crunchyroll..."); | ||
remove('.video-player-placeholder', 'Video Placeholder') | ||
const appendTo = videoPlayer.parentNode; | ||
appendTo.removeChild(videoPlayer); | ||
|
||
console.log("[CR Beta] Pegando dados da stream..."); | ||
var external_lang = preservedState.localization.locale.toLowerCase() | ||
var ep_lang = preservedState.localization.locale.replace('-', '') | ||
var ep_id = preservedState.watch.id | ||
var ep = preservedState.content.byId[ep_id] | ||
if (!ep) {window.location.reload(); return;} | ||
var series_slug = ep.episode_metadata.series_slug_title | ||
var external_id = ep.external_id.substr(4) | ||
var old_url = `https://www.crunchyroll.com/${external_lang}/${series_slug}/episode-${external_id}` | ||
var up_next = document.querySelector('a.up-next-title') | ||
var playback = ep.playback | ||
|
||
var message = { | ||
'playback': playback, | ||
'old_url': old_url, | ||
'lang': ep_lang, | ||
'up_next': up_next ? up_next.href : undefined, | ||
} | ||
|
||
console.log("[CR Beta] Adicionando o jwplayer..."); | ||
console.log("[CR Beta] Antiga URL:", old_url); | ||
addPlayer(appendTo, message, true) | ||
} | ||
|
||
function addPlayer(element, playerInfo, beta = false) { | ||
console.log("[CR Premium] Adicionando o jwplayer..."); | ||
var ifrm = document.createElement("iframe"); | ||
ifrm.setAttribute("id", "frame"); | ||
ifrm.setAttribute("src", "https://mateus7g.github.io/crp-iframe-player/"); | ||
ifrm.setAttribute("width","100%"); | ||
ifrm.setAttribute("height","100%"); | ||
ifrm.setAttribute("frameborder","0"); | ||
ifrm.setAttribute("scrolling","no"); | ||
ifrm.setAttribute("allowfullscreen","allowfullscreen"); | ||
ifrm.setAttribute("allow","autoplay; encrypted-media *"); | ||
|
||
element.appendChild(ifrm) | ||
|
||
chrome.storage.sync.get(['aseguir', 'cooldown'], function(items) { | ||
ifrm.onload = function() { | ||
playerInfo['up_next_cooldown'] = items.cooldown === undefined ? 5 : items.cooldown; | ||
playerInfo['up_next_enable'] = items.aseguir === undefined ? true : items.aseguir; | ||
playerInfo['version'] = '1.1.0'; | ||
playerInfo['noproxy'] = true; | ||
playerInfo['beta'] = beta; | ||
ifrm.contentWindow.postMessage(playerInfo, "*"); | ||
}; | ||
}); | ||
} | ||
|
||
//function ao carregar pagina. | ||
function onloadfunction() { | ||
if(pegaString(HTML, "vilos.config.media = ", ";") != null){ | ||
importPlayer(); | ||
} | ||
var HTML = document.documentElement.innerHTML; | ||
if(pegaString(HTML, "vilos.config.media = ", ";") != null){ | ||
importPlayer(); // old CR | ||
} else if (preservedState != null){ | ||
importBetaPlayer(); // beta CR | ||
remove(".erc-modal-portal > .overlay > .content-wrapper", "Free Trial Modal", true, () => document.body.classList = []) | ||
registerChangeEpisode(); | ||
} | ||
} | ||
|
||
// function pra atualizar pagina quando mudar de episodio pela UI beta | ||
var isLoaded = false | ||
|
||
function registerChangeEpisode() { | ||
const epChanged = setInterval(() => { | ||
const videosWrapper = query('.videos-wrapper') | ||
if (isLoaded && !videosWrapper) { | ||
window.location.reload(); | ||
clearInterval(epChanged); | ||
} | ||
isLoaded = !!videosWrapper | ||
}, 50) | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", onloadfunction, false); | ||
document.onreadystatechange = function () { | ||
if (document.readyState === "interactive") { | ||
console.log("[CR Beta] Searching for INITIAL_STATE") | ||
var HTML = document.documentElement.innerHTML | ||
preservedState = JSON.parse(pegaString(HTML, "__INITIAL_STATE__ = ", ";")) | ||
} | ||
|
||
var crBetaStyle = document.createElement('style'); | ||
crBetaStyle.innerHTML = `.video-player-wrapper { | ||
margin-top: 2rem; | ||
margin-bottom: calc(-3vh - 7vw); | ||
height: 57.25vw !important; | ||
max-height: 82vh !important; | ||
}`; | ||
document.head.appendChild(crBetaStyle); | ||
} | ||
document.addEventListener("DOMContentLoaded", onloadfunction()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.