diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4c4ffc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.zip diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b83614 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +|

Toggle YouTube Comments


![](icons/128.png)| +|:---:| +|It's dangerous to go alone. Take this.
Collapses YouTube comments by default.| +|_Extension listens for [SPF events] which are YouTube specific.
Icon by [Gregor Cresnar]. Licensed under [CC BY 3.0]._| + + +[SPF events]: https://youtube.github.io/spfjs/documentation/events/ +[Gregor Cresnar]: http://www.flaticon.com/authors/gregor-cresnar +[CC BY 3.0]: http://creativecommons.org/licenses/by/3.0/ "Creative Commons Attribution 3.0 Unported" diff --git a/bundle.sh b/bundle.sh new file mode 100755 index 0000000..f913501 --- /dev/null +++ b/bundle.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +zip -9 -r $(date +%F)-toggle-youtube-comments.zip . -x "*.git*" "*.md" "$0" diff --git a/icons/128.png b/icons/128.png new file mode 100644 index 0000000..9ef3aef Binary files /dev/null and b/icons/128.png differ diff --git a/icons/16.png b/icons/16.png new file mode 100644 index 0000000..a6a513d Binary files /dev/null and b/icons/16.png differ diff --git a/icons/32.png b/icons/32.png new file mode 100644 index 0000000..b3f78e2 Binary files /dev/null and b/icons/32.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..c9bfb10 --- /dev/null +++ b/manifest.json @@ -0,0 +1,21 @@ +{ + "manifest_version": 2, + "name": "Toggle YouTube Comments", + "description": "Be safe. Hide YouTube comments.", + "version": "1.0.0", + + "icons": { + "16": "icons/16.png", + "32": "icons/32.png", + "128": "icons/128.png" + }, + + "content_scripts": [ + { + "matches": ["http://*.youtube.com/*", "https://*.youtube.com/*"], + "js": ["script.js"], + "css": ["youtube.css"], + "run_at": "document_start" + } + ] +} diff --git a/script.js b/script.js new file mode 100644 index 0000000..7555398 --- /dev/null +++ b/script.js @@ -0,0 +1,36 @@ +'use strict'; + +function toggleComments() { + var label = document.getElementById('toggle-comments').firstElementChild; + var comments = document.getElementById('watch-discussion'); + if (comments.classList.toggle('hide-comments')) { + label.textContent = 'Show comments'; + } else { + label.textContent = 'Hide comments'; + } +} + +function inject() { + addClass(); + addButton(); +} + +function addClass() { + document.getElementById('watch-discussion').className += ' hide-comments'; +} + +function addButton() { + var button =` + + `; + + document.getElementById('action-panel-details').innerHTML += button; + document.getElementById('toggle-comments').addEventListener('click', toggleComments); +} + +(function () { + document.addEventListener('DOMContentLoaded', inject); // Static navigation (i.e. initial page load) + document.addEventListener('spfdone', inject); // Dynamic navigation (i.e. subsequent page loads) +})(); diff --git a/youtube.css b/youtube.css new file mode 100644 index 0000000..0227ac7 --- /dev/null +++ b/youtube.css @@ -0,0 +1 @@ +.hide-comments { display: none !important }