Skip to content

Instantly share code, notes, and snippets.

@hadongsoo
Last active February 26, 2020 14:25
Show Gist options
  • Save hadongsoo/d39411b99419bb619dbd298e242adced to your computer and use it in GitHub Desktop.
Save hadongsoo/d39411b99419bb619dbd298e242adced to your computer and use it in GitHub Desktop.
youtube_recommend_filter.user.js
// ==UserScript==
// @name ytb_recommended_filter
// @namespace Violentmonkey Scripts
// @match https://www.youtube.com/
// @grant none
// @version 1.0
// @author -
// @run-at document-start
// ==/UserScript==
const TIMEOUT = 3;
const LastestHide = true;
const NoYearAgo = true;
const BlockKeywordList= [
'차단단어1',
'차단단어2',
];
setTimeout(() => {
// let titleRecommended = document.getElementById('title');
let sectionLatest = document.querySelector('ytd-rich-section-renderer.style-scope.ytd-rich-grid-renderer');
if (LastestHide && sectionLatest) sectionLatest.style.display = 'none';
let listWrapper = document.querySelector('#contents');
let listItem = listWrapper.querySelectorAll('ytd-rich-item-renderer');
let remove = () => {
listItem = listWrapper.querySelectorAll('ytd-rich-item-renderer');
let listItemlength = listItem.length;
for ( let i = 0; i < listItemlength; i++ ){
let item = listItem[i];
// hiding ? years ago
if (item.querySelector('#metadata-line')) {
let metaline = item.querySelector('#metadata-line');
if(NoYearAgo && metaline.textContent.includes('years ago')) {
// item.style.display = 'none';
item.style.opacity = '0.4';
}
}
// hiding already watched
if (item.querySelector('#overlays #progress')) {
// console.log(itemAlready.style.width);
if (item.querySelector('#overlays #progress').style.width == '100%') {
// item.style.display = 'none';
item.style.opacity = '0.4';
}
}
// hiding filtered
let BlockKeywordListLength = BlockKeywordList.length;
for ( let i = 0; i < BlockKeywordListLength; i++ ){
let eachWord = BlockKeywordList[i];
if(item.textContent.includes(eachWord)) {
// let itemTitle = item.querySelector('#video-title');
// let itemChannel = item.querySelector('#metadata #text');
console.log(item.querySelector('#video-title').textContent + ', hided');
// item.style.display = 'none';
item.style.opacity = '0.1';
// item.style.background = 'rgba(255,0,0,0.2)';
}
};
}
}
remove();
let rAF = (callback) => {
let tick = false;
return function trigger() {
if (tick) return;
tick = true;
return requestAnimationFrame(function task() {
tick = false;
return callback();
})
}
};
window.addEventListener('scroll', rAF(remove), { passive: true });
}, TIMEOUT * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment