Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         YoutubeFixes
  3. // @namespace    http://tampermonkey.net/
  4. // @description  Fixes some YouTube annoyances.
  5. // @version      1.0
  6. // @author       Naboum
  7. // @match        https://www.youtube.com/*
  8. // @require      https://gist.github.com/raw/2625891/waitForKeyElements.js
  9. // @require      https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
  10. // @require      https://code.jquery.com/ui/1.12.1/jquery-ui.js
  11. // @require      https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js
  12. // @grant        none
  13. // ==/UserScript==
  14.  
  15. function cssElement(url) {
  16.     var link = document.createElement("link");
  17.     link.href = url;
  18.     link.rel = "stylesheet";
  19.     link.type = "text/css";
  20.     return link;
  21. }
  22.  
  23. $(document).ready(function() {
  24.         if(!$('input[type="checkbox"]').prop("checked")){
  25.             alert("Checkbox is not checked.");
  26.             $('input[type="checkbox"]').click();
  27.         }
  28.     var currentState = getFirstState();
  29.  
  30.     waitForKeyElements ("ytd-guide-entry-renderer#expander-item.style-scope.ytd-guide-collapsible-entry-renderer", clickMore);
  31.     waitForKeyElements ("div#create.style-scope.ytd-comments-header-renderer", manageFirstMargin);
  32.     waitForKeyElements ("#sections > ytd-guide-section-renderer:nth-child(2) > h3", subscribingsListReady);
  33.  
  34.     // $(".ytp-miniplayer-scrim").click()
  35.     // $(".ytp-miniplayer-button.ytp-button").click()
  36.  
  37.     $("button.ytp-size-button.ytp-button").click(function() {
  38.         manageMargin(currentState);
  39.         if (currentState === "1") currentState = "0";
  40.         else if (currentState === "0") currentState = "1";
  41.     });
  42.  
  43.     $("#guide-button").click(function() {
  44.         if ($("app-drawer#guide")[0].hasAttribute("opened")) {
  45.             setTimeout(function() {
  46.                 $("#input-subs-autocomplete").focus();
  47.             }, 50);
  48.         }
  49.     });
  50.  
  51.     $("#endpoint.yt-simple-endpoint.style-scope.ytd-guide-entry-renderer").mouseup(function(e) {
  52.         switch(e.which) {
  53.             case 1: //left click
  54.             case 2: //middle click
  55.                 $("#input-subs-autocomplete").val('').trigger('change');
  56.                 break;
  57.             case 3: //right Click
  58.                 break;
  59.         }
  60.         return false;
  61.     });
  62.  
  63.     function getFirstState() {
  64.         var firstState = $.cookie("wide");
  65.         if (typeof firstState === "undefined") {
  66.             var buttonText = $("button.ytp-size-button.ytp-button").attr("title");
  67.             if (buttonText === "Mode cinéma") return "0";
  68.             else return "1";
  69.         }
  70.         else return firstState;
  71.         return "undefined";
  72.     }
  73.  
  74.     function manageFirstMargin() {
  75.         if (currentState === "0") $("div#create.style-scope.ytd-comments-header-renderer").css("margin-right", "0px");
  76.         else if (currentState === "1") $("div#create.style-scope.ytd-comments-header-renderer").css("margin-right", "22px");
  77.     }
  78.  
  79.     function manageMargin(currentState) {
  80.         if (currentState === "1") $("div#create.style-scope.ytd-comments-header-renderer").css("margin-right", "0px");
  81.         else if (currentState === "0") $("div#create.style-scope.ytd-comments-header-renderer").css("margin-right", "22px");
  82.     }
  83.  
  84.     function clickMore(jNode) {
  85.         jNode.click();
  86.     }
  87.  
  88.     function subscribingsListReady(jNode) {
  89.         var html = `
  90.             <class id="input-container">
  91.                 <span class="input-icon"></span>
  92.                 <input id="input-subs-autocomplete" type="search" placeholder="Search">
  93.             </class>
  94.         `;
  95.         var style = `
  96.             <style>
  97.                 /* Autocompletion input */
  98.                 #input-subs-autocomplete {
  99.                     background: #444;
  100.                     color: #d7d7d7;
  101.                     border-radius: 5px;
  102.                     border: 0;
  103.                     margin: 2px 0px 10px 24px;
  104.                     padding: 8px 10px 8px 35px;
  105.                     width: 200px; /* or 57 with 200 in :focus */
  106.                     -webkit-transition: all 0.5s ease 0s;
  107.                     -moz-transition: all 0.5s ease 0s;
  108.                     -o-transition: all 0.5s ease 0s;
  109.                     transition: all 0.5s ease 0s;
  110.                 }
  111.                 #input-subs-autocomplete:focus {
  112.                     outline: none;
  113.                     background:#ccc;
  114.                     color: #6a6f75;
  115.                     /* width: 150px; */
  116.                 }
  117.                 #input-container {
  118.                     position: relative;
  119.                 }
  120.                 .input-icon {
  121.                     background: url(https://static.senscritique.com/img/layout/sprite.png?201710121789416) -128px -136px no-repeat;
  122.                     height: 15px;
  123.                     width: 15px;
  124.                     left: 35px;
  125.                     position: absolute;
  126.                     margin-top: 10px;
  127.                 }
  128.                 .sub-hidden {
  129.                     display: none;
  130.                 }
  131.             </style>
  132.         `;
  133.  
  134.         $("#sections > ytd-guide-section-renderer:nth-child(2) > h3").append(html);
  135.         $("head").append(style);
  136.  
  137.         var subContainer = $("#sections > ytd-guide-section-renderer:nth-child(2) > #items");
  138.         var subList = {};
  139.         var arr1 = subContainer.children("ytd-guide-entry-renderer");
  140.         var arr2 = subContainer.find("ytd-guide-collapsible-entry-renderer > #expanded > #expandable-items > ytd-guide-entry-renderer:not(:last-child)");
  141.         var arr3 = $.merge(arr1, arr2);
  142.  
  143.         $.each(arr3, function(key, value) {
  144.             var subName = $(value).find("#endpoint").attr("title");
  145.             subList[subName] = $(value);
  146.         });
  147.  
  148.         $("#input-subs-autocomplete").on("change paste keyup search", function() {
  149.             var currentInputValue = $(this).val();
  150.             currentInputValue = currentInputValue.normalize('NFD').replace(/[\u0300-\u036f]/g, "").toLowerCase();
  151.             $.each(subList, function(key, value) {
  152.                 var sanitizedSubName = key.normalize('NFD').replace(/[\u0300-\u036f]/g, "").toLowerCase();
  153.                 var imgParent = $(value).find("yt-img-shadow");
  154.                 var imgElement = $(value).find("#img");
  155.                 $(value)[sanitizedSubName.indexOf(currentInputValue) > -1 ? 'show' : 'hide' ]();
  156.                 if($(value).is(":visible")) {
  157.                     if($(imgParent).hasClass("empty")) {
  158.                         $(imgParent).removeClass("empty");
  159.                     }
  160.                     if($(imgElement).attr("src") == null) {
  161.                         $(imgElement).error(function() {
  162.                             $(imgElement).attr("src", "");
  163.                         }).attr("src", "");
  164.                     }
  165.                 }
  166.             });
  167.         });
  168.     }
  169. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement