From f0b78266108e9802a1ccc8e3cd845bcebd276358 Mon Sep 17 00:00:00 2001 From: Weston Siegenthaler Date: Tue, 24 Sep 2019 12:53:49 -0700 Subject: [PATCH 1/4] Removing localStorage hack which prevented h264ify from working on FF due to a conflict with tracking protection. Current versions of Chrome and Firefox seem to work just fine without it. --- src/inject/content_script.js | 42 ++++++---------------------- src/inject/inject.js | 54 +++++++++++++++--------------------- 2 files changed, 31 insertions(+), 65 deletions(-) diff --git a/src/inject/content_script.js b/src/inject/content_script.js index 6ed6aed..d1d55ee 100644 --- a/src/inject/content_script.js +++ b/src/inject/content_script.js @@ -26,39 +26,13 @@ // javascript variables on the youtube page. Thus, we have to inject another // script into the DOM. -// 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; -} -if (localStorage['h264ify-battery_only'] === undefined) { - localStorage['h264ify-battery_only'] = false; -} +chrome.storage.local.get({ enable: true, block_60fps: false, battery_only: false }, options => { + const optionsJson = JSON.stringify(options) -// Cache chrome.storage.local options in localStorage. -// This is needed because chrome.storage.local.get() is async and we want to -// load the injection script immediately. -// See https://bugs.chromium.org/p/chromium/issues/detail?id=54257 -chrome.storage.local.get({ - // Set defaults - enable: true, - block_60fps: false, - battery_only: false, - }, function(options) { - localStorage['h264ify-enable'] = options.enable; - localStorage['h264ify-block_60fps'] = options.block_60fps; - localStorage['h264ify-battery_only'] = options.battery_only; - } -); - -var injectScript = document.createElement('script'); -// Use textContent instead of src to run inject() synchronously -injectScript.textContent = inject.toString() + "inject();"; -injectScript.onload = function() { - // Remove + diff --git a/options.js b/src/options.js similarity index 59% rename from options.js rename to src/options.js index 67045df..f3d7893 100644 --- a/options.js +++ b/src/options.js @@ -1,39 +1,35 @@ // Saves options to chrome.storage function save_options() { - var enable = document.getElementById('enable').checked; - var block_60fps = document.getElementById('block_60fps').checked; - var battery_only = document.getElementById('battery_only').checked; + const enable = document.getElementById('enable').checked + const block_60fps = document.getElementById('block_60fps').checked + const battery_only = document.getElementById('battery_only').checked chrome.storage.local.set({ enable: enable, block_60fps: block_60fps, battery_only: battery_only, - }); + }) } // Restores checkbox state using the options stored in chrome.storage. function restore_options() { // Use default value enable = true and block_60fps = false - chrome.storage.local.get({ - enable: true, - block_60fps: false, - battery_only: false, - }, function(options) { - document.getElementById('enable').checked = options.enable; - document.getElementById('block_60fps').checked = options.block_60fps; - document.getElementById('battery_only').checked = options.battery_only; - }); + chrome.storage.local.get({ enable: true, block_60fps: false, battery_only: false, }, options => { + document.getElementById('enable').checked = options.enable + document.getElementById('block_60fps').checked = options.block_60fps + document.getElementById('battery_only').checked = options.battery_only + }) } // Restore saved options when extension is loaded -document.addEventListener('DOMContentLoaded', restore_options); +document.addEventListener('DOMContentLoaded', restore_options) // Save options when checkboxes are clicked -var checkboxes = document.getElementsByClassName('checkbox'); +const checkboxes = document.getElementsByClassName('checkbox') for (var i = 0; i < checkboxes.length; i++) { checkboxes[i].addEventListener('click', save_options) } // l10n for (let element of document.querySelectorAll('[data-l10n-id]')) { - element.textContent = chrome.i18n.getMessage(element.dataset.l10nId); + element.textContent = chrome.i18n.getMessage(element.dataset.l10nId) } From c65185328954c8bd05bff374b7c3b78d4222c76c Mon Sep 17 00:00:00 2001 From: Weston Siegenthaler Date: Tue, 24 Sep 2019 12:56:00 -0700 Subject: [PATCH 3/4] Simplifying source directory structure. --- manifest.json | 4 ++-- src/{inject => }/content_script.js | 0 src/{inject => }/inject.js | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{inject => }/content_script.js (100%) rename src/{inject => }/inject.js (100%) diff --git a/manifest.json b/manifest.json index 5c9c751..5001a80 100644 --- a/manifest.json +++ b/manifest.json @@ -26,8 +26,8 @@ "*://*.youtu.be/*" ], "js": [ - "src/inject/inject.js", - "src/inject/content_script.js" + "src/inject.js", + "src/content_script.js" ], "run_at": "document_start", "all_frames": true diff --git a/src/inject/content_script.js b/src/content_script.js similarity index 100% rename from src/inject/content_script.js rename to src/content_script.js diff --git a/src/inject/inject.js b/src/inject.js similarity index 100% rename from src/inject/inject.js rename to src/inject.js From 2c9b996bb9c6deed42af55350faf89e73eb16517 Mon Sep 17 00:00:00 2001 From: Weston Siegenthaler Date: Tue, 24 Sep 2019 13:11:58 -0700 Subject: [PATCH 4/4] Added installation link for Firefox, removed link to HTML5 verification page (it no longer exists), and some minor cleanup. --- README.md | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0794795..003e21c 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ - + # h264ify - - ![](https://raw.githubusercontent.com/erkserkserks/h264ify/master/noncode/yt_screenshot.png) # About @@ -16,16 +13,13 @@ By default, YouTube streams VP8/VP9 encoded video. However, this can cause probl In contrast, H.264 is commonly hardware accelerated by GPUs, which usually means smoother video playback and reduced CPU usage. # Requirements -Google Chrome - -Looking for the Firefox version? See: https://github.com/erkserkserks/h264ify-firefox +Google Chrome *or* Mozilla Firefox # Installation -Install from here: https://chrome.google.com/webstore/detail/h264ify/aleakchihdccplidncghkekgioiakgal - -Note: [You may need to enable GPU acceleration as well] (http://www.webupd8.org/2014/01/enable-hardware-acceleration-in-chrome.html) +- [Chrome Web Store](https://chrome.google.com/webstore/detail/h264ify/aleakchihdccplidncghkekgioiakgal) -If all goes well, when you visit https://www.youtube.com/html5, you should see this: -![](https://github.com/erkserkserks/h264ify/blob/master/noncode/html5_video_support.png) +- [Firefox Add-on](https://addons.mozilla.org/en-US/firefox/addon/h264ify/) +To check that it's working, right click on a YouTube video and select "Stats for nerds". Verify that the codec being used is neither 'vp08' nor 'vp09'. +Note: [You may need to enable GPU acceleration as well](http://www.webupd8.org/2014/01/enable-hardware-acceleration-in-chrome.html)