yt-normal-thumbnails/index.ts

59 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2020-11-15 01:22:11 +03:00
// ==UserScript==
// @name YouTube Normal Thumbnails
// @namespace http://greasyfork.org
2021-11-18 16:16:24 +03:00
// @version 0.7.1
2020-11-15 01:22:11 +03:00
// @description Restores normal thumbnails size
// @author NeoCortex
2021-11-18 16:16:24 +03:00
// @license MIT
2020-11-15 01:22:11 +03:00
// @match *://www.youtube.com/*
2020-11-15 13:03:47 +03:00
// @match *://youtube.com/*
2021-11-18 16:16:24 +03:00
// @run-at document-start
2020-11-15 01:22:11 +03:00
// @grant none
// ==/UserScript==
(function () {
2021-11-18 16:16:24 +03:00
const styles = `
2020-11-15 01:22:11 +03:00
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;
}
2021-11-18 16:16:24 +03:00
ytd-video-renderer[use-prominent-thumbs] ytd-thumbnail.ytd-video-renderer {
min-width: 120px !important;
max-width: 240px !important;
}
2021-11-18 16:16:24 +03:00
`.trim()
2020-11-15 01:22:11 +03:00
class YoutubeThumbnailsFixer {
constructor() {
2021-11-18 16:16:24 +03:00
this.replaceMathMin()
document.addEventListener("DOMContentLoaded", () => this.installStyle(styles))
2020-11-15 01:22:11 +03:00
}
2021-11-18 16:16:24 +03:00
private replaceMathMin(): void {
const origMathMin = Math.min
function modifiedMathMin () {
if (/calcElementsPerRow/img.test(Error().stack || '')) {
return origMathMin.apply(Math, (arguments as unknown) as Array<number>) + 1
2020-11-15 01:22:11 +03:00
}
2021-11-18 16:16:24 +03:00
return origMathMin.apply(Math, (arguments as unknown) as Array<number>)
2020-11-15 01:22:11 +03:00
}
2021-11-18 16:16:24 +03:00
Math.min = modifiedMathMin
2020-11-15 01:22:11 +03:00
}
private installStyle(contents: string): void {
2021-11-18 16:16:24 +03:00
let style = document.createElement('style')
style.innerHTML = contents
document.body.appendChild(style)
2020-11-15 01:22:11 +03:00
}
}
2021-11-18 16:16:24 +03:00
new YoutubeThumbnailsFixer()
2020-11-15 13:03:47 +03:00
})();