// ==UserScript== // @name YouTube: Hide Watched Videos // @namespace http://www.globexdesigns.com/ // @version 0.7 // @description Hides watched videos from your YouTube subscriptions page. // @author Evgueni Naverniouk // @grant GM_addStyle // @include http://*.youtube.com/* // @include http://youtube.com/* // @include https://*.youtube.com/* // @include https://youtube.com/* // @downloadURL none // ==/UserScript== // To submit bugs or submit revisions please see visit the repository at: // https://github.com/globexdesigns/youtube-hide-watched // You can open new issues at: // https://github.com/globexdesigns/youtube-hide-watched/issues (function (undefined) { GM_addStyle("\ .GR-WATCHED {\ display: none;\ }\ .GR-BUTTON {\ cursor: pointer;\ position: absolute;\ right: 80px;\ top: 10px;\ }\ .GR-BUTTON-CHECKBOX {\ pointer-events: none;\ }\ "); // =========================================================== var findWatchedElements = function () { var bars = document.getElementsByClassName('resume-playback-progress-bar'); var watched = []; for (var i = 0, l = bars.length; i < l; i++) { var bar = bars[i]; if (bar.style.width && parseInt(bar.style.width, 10) > 0) watched.push(bar); } return watched; }; // =========================================================== var findParentByClass = function(el, cls) { while ((el = el.parentElement) && !el.classList.contains(cls)); return el; }; // =========================================================== var findButtonTarget = function () { return document.getElementById('browse-items-primary'); }; // =========================================================== var isButtonAlreadyThere = function () { var button = document.getElementsByClassName('GR-BUTTON'); return button && button.length; }; // =========================================================== var addClassToWatchedRows = function () { var items = findWatchedElements() || []; for (var i = 0, l = items.length; i < l; i++) { var item = items[i]; // "Subscription" section needs us to hide the "feed-item-container", // but in the "Trending" section, that class will hide everything. // So there, we need to hide the "expanded-shelf-content-item-wrapper" var row; if (window.location.href.indexOf('/feed/subscriptions') > 0) { row = findParentByClass(item, 'feed-item-container'); } else { row = findParentByClass(item, 'expanded-shelf-content-item-wrapper'); } var gridItem = findParentByClass(item, 'yt-shelf-grid-item'); // If we're in grid view, we will hide the "grid" item, // otherwise we'll hide the item row var itemToHide = gridItem ? gridItem : row; if (localStorage.GRWATCHED === 'true') { itemToHide.classList.add('GR-WATCHED'); } else { itemToHide.classList.remove('GR-WATCHED'); } } }; // =========================================================== var addCheckboxButton = function () { if (isButtonAlreadyThere()) return; // Find button target var target = findButtonTarget(); if (!target) return; // Add checkbox var checkboxContainer = document.createElement('span'); checkboxContainer.className = 'yt-uix-button-icon-wrapper'; var checkbox = document.createElement('input'); checkbox.checked = localStorage.GRWATCHED === 'true' ? 'checked' : null; checkbox.className = 'GR-BUTTON-CHECKBOX'; checkbox.type = 'checkbox'; checkboxContainer.appendChild(checkbox); // Add label text var textnode = document.createTextNode("Hide Watched"); // Create