-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYouTube Row Fixer.user.js
87 lines (76 loc) · 2.61 KB
/
YouTube Row Fixer.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// ==UserScript==
// @name YouTube Row Fixer
// @version 1.0.1
// @author sapondanaisriwan
// @description Increase the videos per row on all page.
// @match https://www.youtube.com/*
// @grant none
// @license MIT
// @run-at document-start
// @icon https://i.imgur.com/I9uDrsq.png
// @namespace https://greasyfork.org/en/users/1021085-sapondanaisriwan
// @homepageURL https://github.com/sapondanaisriwan/youtube-videos-per-row-fix
// @supportURL https://github.com/sapondanaisriwan/youtube-videos-per-row-fix/issues
// @require https://greasyfork.org/scripts/465819-api-for-customelements-in-youtube/code/API%20for%20CustomElements%20in%20YouTube.js?version=1215125
// ==/UserScript==
/*
If you want to submit a bug or request a feature please report via github issue. Since I receive so many emails, I can't reply to them all.
Contact: [email protected]
Support me: https://ko-fi.com/sapondanaisriwan
*/
"use strict";
// Thanks so much to CY Fung (https://greasyfork.org/en/users/371179-cy-fung) for helping me.
const settings = {
VIDEO_PER_ROW: 6,
SHELF_ITEM_PER_ROW: 12, // Max is 12
HIDE_PROFILE: true,
};
const target = "ytd-rich-grid-renderer";
const styles = {
hideProfile: {
id: "hide-ch-profile",
css: `
.channel-avatar.ytd-ghost-grid-renderer,
#home-page-skeleton .channel-avatar {
display: none;
}
ytd-rich-grid-media a#avatar-link {
display: none;
}
`,
},
skeletonEle: {
id: "unload-videos",
css: `
#home-page-skeleton .rich-grid-media-skeleton,
#home-page-skeleton .rich-shelf-videos .rich-grid-media-skeleton.mini-mode,
#home-page-skeleton #home-container-media .rich-grid-media-skeleton.mini-mode {
min-width: calc(100% / ${settings.VIDEO_PER_ROW} - 1.6rem);
max-width: calc(100% / ${settings.VIDEO_PER_ROW} - 1.6rem);
}
`,
},
};
// Function to remove DOM element
const removeEle = (id) => {
const ele = document.getElementById(id);
ele && ele.remove();
};
// Function to inject a style into the webpage
const injectStyle = (id, css) => {
// Remove before adding
removeEle(id);
const style = document.createElement("style");
style.type = "text/css";
style.id = id;
style.textContent = css;
document.documentElement.appendChild(style);
};
injectStyle(styles.skeletonEle.id, styles.skeletonEle.css);
settings.HIDE_PROFILE &&
injectStyle(styles.hideProfile.id, styles.hideProfile.css);
customYtElements.whenRegistered(target, (proto) => {
proto.calcElementsPerRow = (a, b) => {
return a === 194 ? settings.SHELF_ITEM_PER_ROW : settings.VIDEO_PER_ROW;
};
});