// ==UserScript== // @name Block Youtube Users // @namespace https://github.com/Schegge // @description Hide videos of blacklisted users/channels and comments // @icon https://raw.githubusercontent.com/Schegge/Userscripts/master/images/BYUicon.png // @version 2.4.7 // @author Schegge // @match *://*.youtube.com/* // @exclude *://*.youtube.com/embed/* // @exclude *://*.youtube.com/live_chat?* // @grant GM_getValue // @grant GM_setValue // @grant GM.getValue // @grant GM.setValue // @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js // @downloadURL none // ==/UserScript== /** DESCRIPTION - it is not case-sensitive - it hides videos of blacklisted users/channels from home, search, related, and comments - also from the playlists, but it doesn't prevent them from playing if the playlist is in autoplay - put a * in front of a word for wildcard (only in the blacklist), it will find the word no matter its position in the username (example: *news) - when you use it, but you want a channel that has that word in the name, you can put it in the whitelist (example -> blacklist: *news; whitelist: euronews (in english)) - you can choose the symbol to split the usernames (default is a comma, * and " aren't allowed, min-max 1 character) - you can choose the duration of the time interval in which the script checks for new elements on the page (default is 1000 milliseconds, min 500) - reload the page after saving to set the new interval - you can enable/disable hiding comments (after saving you have to reload the page) - you can blacklist channels by right clicking on '[x]' before the usernames (you can enable/disable it) - in any case, the [x] buttons are automatically shown when the "B" menu is open - from a direct link to youtube, it pauses the video if it's blacklisted (you can enable/disable it) - you can temporarily pause the blacklist (to reactivate it, just re-click on it or reload the page) - remember to save after any changes in the menu **/ // gm4 polyfill https://github.com/greasemonkey/gm4-polyfill if (typeof GM == 'undefined') { this.GM = {}; Object.entries({ 'GM_getValue': 'getValue', 'GM_setValue': 'setValue' }).forEach(([oldKey, newKey]) => { let old = this[oldKey]; if (old && (typeof GM[newKey] == 'undefined')) { GM[newKey] = function(...args) { return new Promise((resolve, reject) => { try { resolve(old.apply(this, args)); } catch (e) { reject(e); } }); }; } }); } (async function($) { /* VALUES */ const Values = { storageVer: '1', storageSep: ',', storageTimer: 1000, storageComment: '', storageVideo: '', storageAdd: '', storageBlacklist: [], storageWhitelist: [], menuOpen: false, menuPause: false }; // get saved values Values.storageVer = await GM.getValue('byuver', '1'); Values.storageSep = await GM.getValue('sep', ','); Values.storageTimer = await GM.getValue('timer', 1000); Values.storageComment = await GM.getValue('hidecomments', ''); Values.storageVideo = await GM.getValue('enablepause', ''); Values.storageAdd = await GM.getValue('enableadd', ''); Values.storageBlacklist = getArray(await GM.getValue('savedblocks', '')); Values.storageWhitelist = getArray(await GM.getValue('savedwhites', '')); // get array from string function getArray(string) { if (!string) return []; return string.split(Values.storageSep).map(v => v.trim()).filter(v => v.length); } const Where = { // home, related and page playlist: #metadata #text.ytd-channel-name // search video: #channel-info #text.ytd-channel-name // search channel: #channel-title.ytd-channel-renderer span.ytd-channel-renderer, #info #text.ytd-channel-name // video playlist: #byline.ytd-playlist-panel-video-renderer // comment: #author-text span.ytd-comment-renderer, #name #text.ytd-channel-name user: `#metadata #text.ytd-channel-name, #channel-info #text.ytd-channel-name, #channel-title.ytd-channel-renderer span.ytd-channel-renderer, #info #text.ytd-channel-name, #byline.ytd-playlist-panel-video-renderer${Values.storageComment ? ', #author-text span.ytd-comment-renderer, #name #text.ytd-channel-name' : ''}`, renderer: `ytd-rich-item-renderer, ytd-video-renderer, ytd-channel-renderer, ytd-playlist-renderer, ytd-movie-renderer, ytd-compact-video-renderer, ytd-compact-radio-renderer, ytd-compact-autoplay-renderer, ytd-compact-playlist-renderer, ytd-playlist-video-renderer, ytd-grid-video-renderer, ytd-grid-playlist-renderer, ytd-playlist-panel-video-renderer, ytd-secondary-search-container-renderer${Values.storageComment ? ', ytd-comment-thread-renderer' : ''}`, userVideo: '#upload-info #channel-name #text.ytd-channel-name' }; /* INTERVAL FOR BLACKLISTING */ search(); setInterval(search, Values.storageTimer); /* CSS */ $('head').append(``); /* VIDEO FIRST PAGE */ if (Values.storageVideo && /\/watch/.test(window.location.href)) { let waitUserVideo = setInterval(() => { if ($(Where.userVideo).length) { clearInterval(waitUserVideo); let username = $(Where.userVideo).text().trim(); if (ifMatch(username.toLowerCase())) { let video = $('#player video.video-stream.html5-main-video'); video.get(0).pause(); video.get(0).currentTime = 0; let pausing = setInterval(() => { if (!video.get(0).paused) { video.get(0).pause(); video.get(0).currentTime = 0; } }, 500); $('body').append($(`