-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyoutube-tv-banners.user.js
71 lines (66 loc) · 3.41 KB
/
youtube-tv-banners.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// ==UserScript==
// @name YouTube: TV-sized banner toggle
// @author Sophie Hamilton
// @description To use this script, simply click on the banner on a YouTube channel to toggle it between the TV-sized banner and the regular one. If you use AdBlock Plus you will need to add an exception rule or you will get blank images on some channels; take a look at the source code for details.
// @namespace http://theblob.org/
// @include https://www.youtube.com/*
// @include https://www.youtube.com/user/*
// @include https://www.youtube.com/channel/*
// @version 1
// @grant none
// ==/UserScript==
// PLEASE NOTE: You may encounter blank images when using this script with AdBlock Plus. To fix this, add the following exception rule to ABP:
// @@||ytimg.com^*/channels4_tv_banner.jpg?$domain=youtube.com
(function() {
var zoomcur = "data:image/vnd.microsoft.icon;base64," +
"AAACAAEAEBACAAUABQCwAAAAFgAAACgAAAAQAAAAIAAAAAEAAQAAAAAAgAAAAAAAAAAAAAAAAgAA" +
"AAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAADwAAAD/AAAA/wAAAf+AAAH/gAAB/4AAA" +
"f+AAAD/AAAA/wAAADwAAAAAAAAD//f////j////x////4///8Mf//8AP//+AH///gB///wAP//8A" +
"D///AA///wAP//+AH///gB///8A////w////";
var header = document.querySelector("#c4-header-bg-container.has-custom-banner");
var style = this.currentStyle || window.getComputedStyle(header, null);
var img = style.backgroundImage;
var firstregex = /\/w2120-[^\/]+\//;
var secondregex = /\/channels4_banner_hd\.jpg/;
var thirdregex = /=w2120-[^\/]+/;
var first = img.match(firstregex);
var second = img.match(secondregex);
var third = img.match(thirdregex)
if (header && (first || second || third)) {
header.style.cursor = "url(" + zoomcur + "), auto";
var profileimg = document.querySelector("a.channel-header-profile-image-container");
var headerlinks = document.querySelector("div#header-links");
header.addEventListener("click", function(e) {
var changed = this.getAttribute("sph-yt-userscript-bg-changed");
if (changed == "1") {
this.style.backgroundImage = "";
this.style.height = "175px";
this.removeAttribute("sph-yt-userscript-bg-changed");
// this.style.cursor = "-moz-zoom-out";
if (profileimg) { profileimg.style.display = ""; }
if (headerlinks) { headerlinks.style.display = ""; }
}
else {
if (first) {
img = img.replace(firstregex, "/w1280/"); // has a bit of a higher bandwidth cost than the web banner size, but not much. Please don't change this to w2120 as YouTube might not like it.
this.style.backgroundImage = img;
}
else if (second) {
img = img.replace(secondregex, "/channels4_tv_banner.jpg"); // unfortunately this doesn't have a lower-bandwidth version so we get the 2120px-sized one.
// var imgdiv = document.querySelector("#c4-header-bg-container .hd-banner-image");
// imgdiv.style.backgroundImage = img;
this.style.backgroundImage = img;
}
else if (third) {
img = img.replace(thirdregex, "=w1280;");
this.style.backgroundImage = img;
}
this.style.height = "478px";
// this.style.cursor = "-moz-zoom-in";
if (profileimg) { profileimg.style.display = "none"; }
if (headerlinks) { headerlinks.style.display = "none"; }
this.setAttribute("sph-yt-userscript-bg-changed", "1");
}
}, false);
}
})();