Last active
August 29, 2015 14:24
-
-
Save FlandreDaisuki/17ebd5f014dee12acc23 to your computer and use it in GitHub Desktop.
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 Flanico | |
// @namespace FlandreDaisuki | |
// @description A HTML5 based niconico player | |
// @include http://www.nicovideo.jp/watch/* | |
// @match http://www.nicovideo.jp/watch/* | |
// @exclude | |
// @version 2015.07.14 | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
function queryToObject(query) { | |
var pattern = [ | |
['%', /\%25/g], | |
['&', /\%26/g], | |
['/', /\%2F/g], | |
[':', /\%3A/g], | |
['=', /\%3D/g], | |
['?', /\%3F/g] | |
]; | |
for (var i = 0; i < pattern.length; i++) { | |
query = query.replace(pattern[i][1], pattern[i][0]); | |
} | |
var retobj = {}; | |
query.split('&').forEach(function(str) { | |
var keyvalue = /(^[\w|\_]+)=(.*)/.exec(str); | |
if (/\%/.test(keyvalue[2])) { | |
keyvalue[2] = decodeURIComponent(keyvalue[2]); | |
} | |
retobj[keyvalue[1]] = keyvalue[2]; | |
}); | |
return retobj; | |
} | |
function cleanChild(elem) { | |
while(elem.children.length > 0){ | |
elem.removeChild(elem.children.item(0)); | |
} | |
} | |
window.Flanico = {}; | |
//get flv data | |
Flanico.watchAPIData = JSON.parse(document.querySelector('#watchAPIDataContainer').innerHTML); | |
Flanico.flvinfo = queryToObject(Flanico.watchAPIData.flashvars.flvInfo); | |
//set my area | |
Flanico.stage = document.createElement('div'); | |
Flanico.stage.id = 'FlanicoStage'; | |
Flanico.stage.style.height = '100%'; | |
Flanico.stage.style.width = '100%' | |
//replace flash to my area | |
cleanChild(document.querySelector('#playerAlignmentArea')); | |
document.querySelector('#playerAlignmentArea').appendChild(Flanico.stage); | |
//add just HTML5 video | |
Flanico.video = document.createElement('video'); | |
Flanico.video.innerHTML = 'HTML5 media not support'; | |
Flanico.videoSource = document.createElement('source'); | |
Flanico.videoSource_low = document.createElement('source'); | |
if ( Flanico.flvinfo.url.slice( -3 ) === 'low' ) { | |
Flanico.videoSource.src = Flanico.flvinfo.url.slice( 0, -3 ); | |
Flanico.videoSource_low.src = Flanico.flvinfo.url; | |
} else { | |
Flanico.videoSource.src = Flanico.flvinfo.url; | |
Flanico.videoSource_low.src = Flanico.flvinfo.url + 'low'; | |
} | |
Flanico.video.appendChild(Flanico.videoSource_low); | |
Flanico.video.appendChild(Flanico.videoSource); | |
Flanico.stage.appendChild(Flanico.video); | |
Flanico.video.controls = true; | |
// remove chrome notification | |
document.querySelector('.notify_update_flash_player').remove(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment