This file contains 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 Remove youtube recommended and homepage | |
// @namespace body | |
// @version 1.0 | |
// @description Remove the youtube recommended junk along with complete landing page | |
// @author Shameless copy and modified from https://github.com/jpancik/Remove-YouTube-Recommendations | |
// @include *youtube.com/* | |
// ==/UserScript== | |
function ready(fn) { | |
if (document.readyState != 'loading'){ | |
fn(); | |
} else { | |
document.addEventListener('DOMContentLoaded', fn); | |
} | |
} | |
function pluginRemoveRecommendedVideosRun() { | |
//console.log("Remove YouTube Recommendations - removing garbage."); | |
var relatedEl = document.getElementById("related"); | |
if (relatedEl != null) { | |
Array.prototype.forEach.call(relatedEl.getElementsByTagName("ytd-watch-next-secondary-results-renderer")[0].querySelector("#items").children, function(el, i) { | |
if(el.tagName === "YTD-COMPACT-VIDEO-RENDERER") { | |
var elSpan = el.querySelector("#metadata-line span"); | |
if(elSpan != null) { | |
if(!(/^.*[0-9].*$/.test(elSpan.innerText))) { | |
console.log("Remove YouTube Recommendations - Removing recommendation."); | |
el.parentNode.removeChild(el); | |
} | |
} | |
} | |
}); | |
} | |
} | |
function pluginRemoveRecommendedVideosBindToLoadMore() { | |
var target = document.getElementById("continuations"); | |
if (target) { | |
var observer = new MutationObserver(function(mutations) { | |
pluginRemoveRecommendedVideosRun(); | |
//observer.disconnect(); | |
}); | |
var config = { childList: true }; | |
observer.observe(target, config); | |
} | |
} | |
function pluginRemoveRecommendedVideosPageLoad() { | |
setTimeout(function() { | |
pluginRemoveRecommendedVideosRun(); | |
}, 1000); | |
setTimeout(function() { | |
pluginRemoveRecommendedVideosRun(); | |
}, 3000); | |
setTimeout(function() { | |
pluginRemoveRecommendedVideosBindToLoadMore(); | |
}, 2000); | |
} | |
function pluginRemoveRecommendedVideosCheckHref(checkedHref) { | |
if(window.location.href !== checkedHref) { | |
pluginRemoveRecommendedVideosPageLoad(); | |
} | |
(function (href) { | |
setTimeout(function() { | |
pluginRemoveRecommendedVideosCheckHref(href); | |
}, 500); | |
})(window.location.href); | |
} | |
function hideHomePage() { | |
var element = document.getElementById("primary"); | |
element.parentNode.removeChild(element); | |
} | |
ready(function() { | |
//console.log("Remove YouTube Recommendations - ready!"); | |
pluginRemoveRecommendedVideosPageLoad(); | |
hideHomePage(); | |
(function (href) { | |
setTimeout(function() { | |
pluginRemoveRecommendedVideosCheckHref(href); | |
}, 500); | |
})(window.location.href); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment