Last active
January 3, 2022 15:15
-
-
Save Far-Se/e8a8e4a6d85f3e9086b3965fa1245520 to your computer and use it in GitHub Desktop.
User Script for Youtube to see only videos newer than 1 month on Main Page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Youtube Fresh Videos only | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Filter Youtube Recommended to show only less then a month, with different styles for hours days and weeks. | |
// @author Your Grandma | |
// @match https://www.youtube.com/ | |
// @icon https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://youtube.com | |
// @grant none | |
// ==/UserScript== | |
document.querySelector('#contents').insertAdjacentHTML('beforebegin',` | |
<a href="/" id="toggleFresh" style="color: white;font-size: 20px;margin: 20px 0px 0px 20px;border: 1px solid #5d5d5d;padding: 5px 10px;border-radius: 10px;background: #202020;text-decoration: none;align-self: baseline;" | |
onclick="localStorage.setItem('onlyFresh', ~~(!(1*(localStorage.getItem('onlyFresh') || 0)))); window.location.reload()"> Toggle Fresh Only</a>`); | |
let mainScript = () => { | |
if(!(1*localStorage.getItem('onlyFresh')))return; | |
let texts = ['minute', 'hour', 'day', 'week','1 month', 'month', 'year', 'Streamed', 'watching']; | |
texts.forEach((text)=>{ | |
var headings = document.evaluate("//*[@id=\"metadata-line\"][contains(., '" + text + "')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (let i = 0; i < headings.snapshotLength; i++) { | |
let thisHeading = headings.snapshotItem(i); | |
if (~['month', 'year', 'Streamed', 'watching'].indexOf(text)) { | |
thisHeading.innerText = 'old'; | |
thisHeading.closest('ytd-rich-item-renderer').style.display = "none"; | |
} else { | |
thisHeading.innerText = thisHeading.innerText.replace(/\d (\w)/, c => c.toUpperCase()) | |
if (text === 'day') | |
thisHeading.closest('ytd-rich-item-renderer').setAttribute('style', 'background:rgba(0,0,0,.5) !important;box-shadow: 0px 0px 3px #ddd;'); | |
else if(text === 'week') | |
thisHeading.closest('ytd-rich-item-renderer').setAttribute('style', 'background:rgba(0,0,0,.4) !important;'); | |
else | |
thisHeading.closest('ytd-rich-item-renderer').setAttribute('style', 'background:rgba(255,255,255,.2) !important;'); | |
} | |
} | |
}); | |
document.querySelectorAll('[title^="Mix -"]').forEach(e=>e.closest('ytd-rich-item-renderer').style.display = "none"); | |
} | |
mainScript(); | |
window.onlyFresh = () => mainScript(); | |
var targetNode = document.getElementById('contents'); | |
var observer = new MutationObserver(mainScript); | |
observer.observe(targetNode, { childList: true }); |
Author
Far-Se
commented
Dec 30, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment