Commits

Mathias Panzenböck committed af1dc35

initial commit

Comments (0)

Files changed (4)

+"use strict";
+
+function play_hook (src) {
+	return function () {
+		// unbreak player:
+		this.autoplay = true;
+		this.preload = "auto";
+		this.src = src;
+		delete this.play;
+		this.play();
+
+		// don't ask me why this is needed,
+		// it just won't work without it:
+		try {
+			// but sometimes there is no Mg(!?!)
+			// and then it works without it (whaaa?)
+			yt.player.Mg.stopVideo();
+			yt.player.Mg.playVideo();
+		}
+		catch (e) {
+			console.error(e);
+		}
+	};
+}
+
+function videoblock () {
+	var videos = document.querySelectorAll('video');
+	// don't do anything unless HTML5 video is used
+	if (videos.length === 0) return;
+	if (window.gYouTubePlayerReady) {
+		try {
+			yt.player.Mg.stopVideo();
+		}
+		catch (e) {
+			console.error(e);
+		}
+	}
+	else {
+		var f = window.onYouTubePlayerReady;
+		window.onYouTubePlayerReady = function () {
+			window.gYouTubePlayerReady = true;
+			try {
+				yt.player.Mg.stopVideo();
+			}
+			finally {
+				if (f) f();
+			}
+		};
+	}
+	var player = document.getElementById("watch-player");
+	if (player) {
+		var handler = function () {
+			try {
+				var videos = this.querySelectorAll('video');
+				for (var i = 0; i < videos.length; ++ i) {
+					videos[i].play();
+				}
+			}
+			finally {
+				this.removeEventListener("click", handler, false);
+			}
+		};
+		player.addEventListener("click", handler, false);
+	}
+	for (var i = 0; i < videos.length; ++ i) {
+		var video = videos[i];
+		var src = video.src;
+		// "break" video:
+		video.autoplay = false;
+		video.preload = "none";
+		if (!video.paused) {
+			video.pause();
+		}
+		video.src = "about:blank";
+		video.play = play_hook(src);
+	}
+}
+
+videoblock();

src/manifest.json

+{
+	"name": "Block HTML5 YouTube Videos",
+	"description": "Stops loading HTML5 videos so you can open multiple tabs without killing your network bandwith.",
+	"version": "1.0.1",
+	"content_scripts": [{
+		"matches": [
+			"http://*.youtube.com/*",
+			"https://*.youtube.com/*"
+		],
+		"js": ["content.js"],
+		"all_frames": true
+	}]
+}

videoblock.png

Added
New image
Added
New image
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="64"
+   height="64"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.48.1 r9760"
+   sodipodi:docname="New document 1">
+  <defs
+     id="defs4">
+    <inkscape:path-effect
+       effect="spiro"
+       id="path-effect3783"
+       is_visible="true" />
+    <inkscape:path-effect
+       effect="spiro"
+       id="path-effect3779"
+       is_visible="true" />
+    <inkscape:path-effect
+       effect="spiro"
+       id="path-effect3775"
+       is_visible="true" />
+    <inkscape:path-effect
+       effect="skeletal"
+       id="path-effect3771"
+       is_visible="true"
+       pattern="M 0,0 0,10 10,5 z"
+       copytype="single_stretched"
+       prop_scale="1"
+       scale_y_rel="false"
+       spacing="0"
+       normal_offset="0"
+       tang_offset="0"
+       prop_units="false"
+       vertical_pattern="false"
+       fuse_tolerance="0" />
+    <inkscape:path-effect
+       effect="spiro"
+       id="path-effect3769"
+       is_visible="true" />
+    <inkscape:path-effect
+       effect="skeletal"
+       id="path-effect2997"
+       is_visible="true"
+       pattern="M 0,0 0,10 10,5 z"
+       copytype="single_stretched"
+       prop_scale="1"
+       scale_y_rel="false"
+       spacing="0"
+       normal_offset="0"
+       tang_offset="0"
+       prop_units="false"
+       vertical_pattern="false"
+       fuse_tolerance="0" />
+    <inkscape:path-effect
+       effect="spiro"
+       id="path-effect2995"
+       is_visible="true" />
+    <inkscape:path-effect
+       effect="skeletal"
+       id="path-effect2991"
+       is_visible="true"
+       pattern="M 0,0 0,10 10,5 z"
+       copytype="single_stretched"
+       prop_scale="1"
+       scale_y_rel="false"
+       spacing="0"
+       normal_offset="0"
+       tang_offset="0"
+       prop_units="false"
+       vertical_pattern="false"
+       fuse_tolerance="0" />
+    <inkscape:path-effect
+       effect="spiro"
+       id="path-effect2989"
+       is_visible="true" />
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="7.9195959"
+     inkscape:cx="31.617091"
+     inkscape:cy="31.725121"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="true"
+     inkscape:window-width="768"
+     inkscape:window-height="836"
+     inkscape:window-x="1096"
+     inkscape:window-y="98"
+     inkscape:window-maximized="0">
+    <inkscape:grid
+       type="xygrid"
+       id="grid2985"
+       empspacing="5"
+       visible="true"
+       enabled="true"
+       snapvisiblegridlinesonly="true"
+       spacingx="8px"
+       spacingy="8px" />
+  </sodipodi:namedview>
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title></dc:title>
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(0,-988.36218)">
+    <path
+       style="fill:#000000;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
+       d="M 8,8 8,56 56,32 8,8"
+       id="path3777"
+       inkscape:path-effect="#path-effect3779"
+       inkscape:original-d="M 8,8 8,56 56,32 8,8 z"
+       inkscape:connector-curvature="0"
+       transform="translate(0,988.36218)" />
+    <path
+       style="fill:#ff0000;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
+       d="M 40,8 16,56 24,56 48,8 40,8"
+       id="path3781"
+       inkscape:path-effect="#path-effect3783"
+       inkscape:original-d="M 40,8 16,56 24,56 48,8 z"
+       inkscape:connector-curvature="0"
+       transform="translate(0,988.36218)" />
+  </g>
+</svg>