2020-11-15 01:22:11 +03:00
|
|
|
// ==UserScript==
|
|
|
|
// @name YouTube Normal Thumbnails
|
|
|
|
// @namespace http://greasyfork.org
|
2021-07-14 22:09:31 +03:00
|
|
|
// @version 0.7.0
|
2020-11-15 01:22:11 +03:00
|
|
|
// @description Restores normal thumbnails size
|
|
|
|
// @author NeoCortex
|
|
|
|
// @match *://www.youtube.com/*
|
2020-11-15 13:03:47 +03:00
|
|
|
// @match *://youtube.com/*
|
2020-11-15 01:22:11 +03:00
|
|
|
// @run-at document-end
|
|
|
|
// @grant none
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
const perRowProperty = '--ytd-rich-grid-items-per-row';
|
|
|
|
const styleContent = `
|
|
|
|
ytd-rich-grid-video-renderer[mini-mode] #video-title.ytd-rich-grid-video-renderer {
|
|
|
|
font-size: 1.4rem;
|
|
|
|
font-weight: 500;
|
|
|
|
line-height: 1.6rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
#avatar-link.ytd-rich-grid-video-renderer {
|
|
|
|
display: none !important;
|
|
|
|
}
|
|
|
|
`.trim();
|
2021-07-14 22:09:31 +03:00
|
|
|
const commonStyles = `
|
|
|
|
ytd-video-renderer[use-prominent-thumbs] ytd-thumbnail.ytd-video-renderer {
|
|
|
|
min-width: 120px !important;
|
|
|
|
max-width: 240px !important;
|
|
|
|
}
|
|
|
|
`.trim();
|
2020-11-15 01:22:11 +03:00
|
|
|
|
|
|
|
class YoutubeThumbnailsFixer {
|
|
|
|
private oldPerRow?: number;
|
|
|
|
private observer?: MutationObserver;
|
|
|
|
private target?: HTMLElement;
|
|
|
|
private videoObserverConfig = {
|
|
|
|
attributes: true,
|
|
|
|
childList: false,
|
|
|
|
subtree: false
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.installContentObserver();
|
2021-07-14 22:09:31 +03:00
|
|
|
this.installStyle(commonStyles);
|
2020-11-15 01:22:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private installContentObserver(): void {
|
|
|
|
this.observer = new MutationObserver((mutationsList, observer) => {
|
|
|
|
this.target = document.querySelector('ytd-rich-grid-renderer') as HTMLElement;
|
|
|
|
|
|
|
|
if (null !== this.target) {
|
|
|
|
this.observer?.disconnect();
|
2021-07-14 22:09:31 +03:00
|
|
|
this.installStyle(styleContent);
|
2020-11-15 01:22:11 +03:00
|
|
|
this.updateRowsCount();
|
|
|
|
this.installVideoGridObserver();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.observer.observe(document.getElementById('content') as Node, {
|
|
|
|
attributes: false,
|
|
|
|
childList: true,
|
|
|
|
subtree: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private installVideoGridObserver(): void {
|
|
|
|
if (this.isNil(this.target)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.observer = new MutationObserver((mutationsList, observer) => {
|
|
|
|
for (let mutation of mutationsList) {
|
|
|
|
if (mutation.attributeName == 'style') {
|
|
|
|
this.observer?.disconnect();
|
|
|
|
this.updateRowsCount();
|
|
|
|
this.observer?.observe(this.target as Node, this.videoObserverConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.observer?.observe(this.target as Node, this.videoObserverConfig);
|
|
|
|
console.info(`[YouTube Normal Thumbnails] Changed to ${this.currentPerRow} thumbnails per row instead of ${this.oldPerRow}.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
private updateRowsCount(): void {
|
|
|
|
if (this.isNil(this.target)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (this.oldPerRow === undefined || this.oldPerRow == this.currentPerRow || this.oldPerRow === 0) {
|
|
|
|
this.oldPerRow = this.currentPerRow;
|
|
|
|
this.currentPerRow += 1;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(`[YouTube Normal Thumbnails] Cannot update thumbnails count: ${e}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-14 22:09:31 +03:00
|
|
|
private installStyle(contents: string): void {
|
2020-11-15 01:22:11 +03:00
|
|
|
let style = document.createElement('style');
|
2021-07-14 22:09:31 +03:00
|
|
|
style.innerHTML = contents;
|
2020-11-15 01:22:11 +03:00
|
|
|
document.body.appendChild(style);
|
|
|
|
}
|
|
|
|
|
|
|
|
private isNil(item: any): boolean {
|
|
|
|
return null === item || undefined === item;
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentPerRow(): number {
|
|
|
|
if (this.isNil(this.target)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return +(this.target as HTMLElement).style.getPropertyValue(perRowProperty);
|
|
|
|
}
|
|
|
|
|
|
|
|
set currentPerRow(value: number) {
|
|
|
|
this.target?.style.setProperty(perRowProperty, String(value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new YoutubeThumbnailsFixer();
|
2020-11-15 13:03:47 +03:00
|
|
|
})();
|