Last active
November 12, 2016 08:07
-
-
Save piouc/f51d431c936ad727d339a02d7f886380 to your computer and use it in GitHub Desktop.
noFlashNicoVideo
This file contains hidden or 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
(() => { | |
// Remove flash player notify | |
const notifyOverlay = document.querySelector('.notify_update_flash_player') | |
if(notifyOverlay){ | |
document.body.removeChild(notifyOverlay) | |
} | |
const videoID = JSON.parse(document.getElementById('watchAPIDataContainer').innerHTML).flashvars.videoId | |
const playerContainer = document.getElementById('playerContainerWrapper') | |
removeAllChild(playerContainer) | |
fetch(`http://flapi.nicovideo.jp/api/getflv?v=${videoID}`, { | |
mode: 'cors', | |
credentials: 'include' | |
}).then(res => res.text()).then(res => { | |
const video = document.createElement('video') | |
Object.assign(video, { | |
src: decodeURIComponent(res.match(/url=([^&]*)/)[1]), | |
autoplay: true, | |
controls: true, | |
style: 'display: block; width: 1008px; margin: 0 auto;' | |
}) | |
playerContainer.appendChild(video) | |
}) | |
function removeAllChild(element){ | |
Array.from(element.childNodes).forEach(child => element.removeChild(child)) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment