-
-
Save CrossVR/84d91994683bc2e4bafa21d9f360be6d to your computer and use it in GitHub Desktop.
Edited Zren's Crunchyroll Userscript to better display each resolution
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
// ==UserScript== | |
// @name Crunchyroll: Resize Player To Window Size | |
// @description Moves the video to the top of the website and resizes it to the screen size. | |
// @author Chris H (Zren / Shade) | |
// @icon https://crunchyroll.com/favicons/favicon-16x16.png | |
// @homepageURL http://userscripts.org/scripts/show/157272 | |
// @downloadURL http://userscripts.org/scripts/source/157272.user.js | |
// @updateURL http://userscripts.org/scripts/source/157272.meta.js | |
// @namespace http://xshade.ca | |
// @version 1.1.1 | |
// @include http*://*.crunchyroll.c*/* | |
// @include http*://crunchyroll.c*/* | |
// ==/UserScript== | |
(function() { | |
// Can't use !important with javascript element.style.___ so we need to inject CSS. | |
// http://stackoverflow.com/a/462603/947742 | |
function addNewStyle(newStyle) { | |
var styleElement = document.getElementById('styles_js'); | |
if (!styleElement) { | |
styleElement = document.createElement('style'); | |
styleElement.type = 'text/css'; | |
styleElement.id = 'styles_js'; | |
document.getElementsByTagName('head')[0].appendChild(styleElement); | |
} | |
styleElement.appendChild(document.createTextNode(newStyle)); | |
} | |
function getPosition(element) { | |
var xPosition = 0; | |
while(element) { | |
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft); | |
element = element.offsetParent; | |
} | |
return xPosition; | |
} | |
var width = 1920; | |
var height = 1080; | |
var e360p = document.querySelector('[token="showmedia.360p"]').classList.contains('selected'); | |
var e480p = document.querySelector('[token="showmedia.480p"]').classList.contains('selected'); | |
var e720p = document.querySelector('[token="showmedia.720p"]').classList.contains('selected'); | |
var e1080p = document.querySelector('[token="showmedia.1080p"]').classList.contains('selected'); | |
if (e1080p) { | |
// Do nothing because width and height already set | |
} else if (e720p) { | |
width = 1280; | |
height = 720; | |
} else if (e480p) { | |
width = 640; | |
height = 480; | |
} else if (e360p) { | |
width = 480; | |
height = 360; | |
} | |
//var style = "html, body, #showmedia_video_box, #showmedia_video_box_wide, #showmedia_video_player { width: " + width + "px; height: "+ height + "px; }"; | |
//document.getElementById('header_beta').setAttribute("style","width:2560px"); | |
setTimeout(function () { | |
var videoBox = document.getElementById('showmedia_video'); | |
var x = getPosition(videoBox) | |
if (!videoBox) return; | |
//document.body.insertBefore(videoBox, document.body.firstChild); | |
var center = x - ((window.innerWidth - width) / 2); | |
videoBox.style.marginLeft = '-' + center + 'px'; | |
videoBox.style.width = width + 'px'; | |
videoBox.style.height = height + 'px'; | |
videoBox.style.backgroundColor = '#000'; | |
var videoPlayer = document.getElementById('showmedia_video_player'); | |
if (!videoPlayer) return; | |
console.log(videoPlayer); | |
//var videoObject = videoBox.getElementsByTagName('object')[0]; | |
videoPlayer.width = width + 'px'; | |
videoPlayer.height = height + 'px'; | |
//addNewStyle(style); | |
}, 2000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment