-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathytmaxthumb.js
More file actions
62 lines (51 loc) · 1.73 KB
/
Copy pathytmaxthumb.js
File metadata and controls
62 lines (51 loc) · 1.73 KB
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
var maxres = function (info) {
// var url = info['srcUrl'];
// var newTab = url;
// function containsAny(str, substrings) {
// for (var i = 0; i != substrings.length; i++) {
// var substring = substrings[i];
// if (str.indexOf(substring) != - 1) {
// return substring;
// }
// }
// return null;
// }
// var result = containsAny(url, ["/default", "/hqdefault", "/mqdefault", "/sddefault", "/hd720"]);
// var height, width = '';
// var img = new Image();
// var imgSrc = newTab;
// var brokenThumb = 0;
// $(img).load(function () {
// if(img.height == 90) {
// brokenThumb = 1;
// }
// // garbage collect img
// delete img;
// }).error(function () {
// // image could not be loaded
// alert('An error occurred: image could not be loaded. Please try again.');
// }).attr({ src: imgSrc });
// if(brokenThumb == 1) {
// newTab = newTab.replace(result, "/hq720");
// }else{
// newTab = newTab.replace(result, "/maxresdefault");
// }
// newTab = newTab.replace(/&w=([0-9]+)&h=([0-9]+)/, "&w=1920&h=1080");
var url = info['srcUrl'];
var newTab = url;
if (url.includes(".webp")) {
var vidID = /https:\/\/i.ytimg.com\/an_webp\/(.+)\/(?:.+)\.webp/.exec(url);
newTab = `https://i.ytimg.com/vi/${vidID[1]}/maxresdefault.jpg`;
} else if (url.includes(".jpg")) {
var vidID = /https:\/\/i.ytimg.com\/vi\/(.+)\/(?:.+)\.jpg/.exec(url);
newTab = `https://i.ytimg.com/vi/${vidID[1]}/maxresdefault.jpg`;
}
chrome.tabs.create({ url: newTab });
}
var patterns = ["*://*.youtube.com/*"];
chrome.contextMenus.create({
"title": "Open larger thumbnail in new tab",
"contexts": ["image"],
"documentUrlPatterns": patterns,
"onclick": maxres
});