-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyoutube.js
More file actions
75 lines (60 loc) · 1.89 KB
/
youtube.js
File metadata and controls
75 lines (60 loc) · 1.89 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
63
64
65
66
67
68
69
70
71
72
73
74
75
// ==UserScript==
// @name YouTube Desktop Feed
// @namespace r57zone userscripts youtube
// @version 1.2
// @match https://www.youtube.com/*
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
function applyExtraCSS() {
let style = document.getElementById('yt-extra-style');
if (!style) {
style = document.createElement('style');
style.id = 'yt-extra-style';
document.head.appendChild(style);
}
style.textContent =
'#content.ytd-rich-section-renderer {' +
'width: 70% !important;' +
'}';
}
function fixGrid() {
const grids = document.querySelectorAll('ytd-rich-grid-renderer');
grids.forEach(function(grid) {
grid.setAttribute('elements-per-row', '5');
grid.style.setProperty('--ytd-rich-grid-item-max-width', '320px', 'important');
grid.style.setProperty('--ytd-rich-grid-items-per-row', '5', 'important');
});
}
function fixAll() {
fixGrid();
applyExtraCSS();
}
// ждём пока появится grid
function waitForGrid() {
if (document.querySelector('ytd-rich-grid-renderer'))
fixAll();
else
setTimeout(waitForGrid, 300);
}
// после загрузки
window.addEventListener('load', function() {
setTimeout(waitForGrid, 1500);
});
// при SPA-навигации
document.addEventListener('yt-navigate-finish', function() {
setTimeout(waitForGrid, 800);
});
// при скролле
window.addEventListener('scroll', function() {
fixAll();
});
//let resizeTimer = null;
/*window.addEventListener('resize', function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
fixAll();
}, 300);
});*/
})();