Repository: erkserkserks/h264ify-firefox Branch: master Commit: 1427d222f592 Files: 5 Total size: 8.3 KB Directory structure: gitextract_lw3wu6xw/ ├── README.md ├── data/ │ ├── content_script.js │ └── inject.js ├── index.js └── package.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ # h264ify-firefox ![](https://raw.githubusercontent.com/erkserkserks/h264ify-firefox/master/noncode/screenshot_video.png) # About h264ify is a Firefox/Chrome extension that makes YouTube stream H.264 videos instead of VP8/VP9 videos. Try h264ify if YouTube videos stutter, take up too much CPU, eat battery life, or make your laptop hot. By default, YouTube streams VP8/VP9 encoded video. However, this can cause problems with less powerful machines because VP8/VP9 is not typically hardware accelerated. In contrast, H.264 is commonly hardware accelerated by GPUs, which usually means smoother video playback and reduced CPU usage. # Requirements Firefox Looking for the Chrome version? See: https://github.com/erkserkserks/h264ify # Installation Install from here: https://addons.mozilla.org/firefox/addon/h264ify/ If all goes well, when you visit https://www.youtube.com/html5, you should see this: ![](https://raw.githubusercontent.com/erkserkserks/h264ify-firefox/master/noncode/screenshot_support.png) Note: The current version of Firefox (35) doesn't support MSE, but when support arrives, h264ify will also block VP9. ================================================ FILE: data/content_script.js ================================================ /** * The MIT License (MIT) * * Copyright (c) 2015 erkserkserks * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ // This content script runs in an isolated environment and cannot modify any // javascript variables on the youtube page. Thus, we have to inject another // script into the DOM using a script tag. // Set defaults for options stored in localStorage if (localStorage['h264ify-enable'] === undefined) { localStorage['h264ify-enable'] = true; } if (localStorage['h264ify-block_60fps'] === undefined) { localStorage['h264ify-block_60fps'] = false; } // Cache extension preferences in localStorage. // This is needed because port.on is async and we want to // load the injection script immediately. self.port.on('prefs', function(prefs) { console.log('port on prefs') localStorage['h264ify-enable'] = prefs['enable']; localStorage['h264ify-block_60fps'] = prefs['block_60fps']; }); // Create script elem which will be injected into the page var script = document.createElement('script'); script.type = 'text/javascript'; // Use textContent instead of src to run inject.js synchronously script.textContent = self.options.injectjsText; var html = document.documentElement; // Inject js into the page html.insertBefore(script, html.firstChild); // Clean up script.remove() ================================================ FILE: data/inject.js ================================================ /** * The MIT License (MIT) * * Copyright (c) 2015 erkserkserks * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ (function () { if (localStorage['h264ify-enable'] === 'false') { return; } // return a custom MIME type checker that can defer to the original function function makeModifiedMimeTypeChecker(origFunc) { return function (type) { if (type === undefined) return ''; var disallowed_types = ['webm', 'vp8', 'vp9']; // If video type is in disallowed_types, say we don't support them for (var i = 0; i < disallowed_types.length; i++) { if (type.indexOf(disallowed_types[i]) != -1) return ''; } if (localStorage['h264ify-block_60fps'] === 'true') { var match = /framerate=(\d+)/.exec(type); if (match && match[1] > 30) return ''; } // Otherwise, ask the browser return origFunc(type); }; } // Override video element canPlayType() function var videoElem = document.createElement('video'); var origCanPlayType = videoElem.canPlayType.bind(videoElem); videoElem.__proto__.canPlayType = makeModifiedMimeTypeChecker(origCanPlayType); // Override media source extension isTypeSupported() function var mse = window.MediaSource; // Check for MSE support before use - some versions of FF don't support MSE if (mse === undefined) return; var origIsTypeSupported = mse.isTypeSupported.bind(mse); mse.isTypeSupported = makeModifiedMimeTypeChecker(origIsTypeSupported); })(); ================================================ FILE: index.js ================================================ /** * The MIT License (MIT) * * Copyright (c) 2015 erkserkserks * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ var data = require('sdk/self').data; var pageMod = require('sdk/page-mod'); pageMod.PageMod({ include: '*.youtube.com', contentScriptWhen: 'start', contentScriptFile: data.url('content_script.js'), contentScriptOptions: {'injectjsText' : data.load('inject.js')}, onAttach: function(worker) { worker.port.emit('prefs', require('sdk/simple-prefs').prefs); function onPrefChange(prefName) { worker.port.emit('prefs', require('sdk/simple-prefs').prefs); } require('sdk/simple-prefs').on('', onPrefChange); } }); ================================================ FILE: package.json ================================================ { "name": "h264ify", "description": "Makes YouTube stream H.264 videos instead of VP8/VP9 videos", "version": "1.0.5", "author": "erkserkserks", "engines": { "firefox": ">= 38.0a1", "fennec": ">= 38.0a1" }, "homepage": "https://github.com/erkserkserks/h264ify-firefox", "icon": "icon.png", "id": "jid1-TSgSxBhncsPBWQ@jetpack", "license": "MIT", "permissions": { "multiprocess": true, "private-browsing": true }, "preferences": [ { "name": "enable", "title": "Enable h264ify", "type": "bool", "value": true }, { "name": "block_60fps", "title": "Block 60fps", "type": "bool", "value": false } ], "title": "h264ify" }