youtube_ex

enhanced youtube

  1. // ==UserScript==
  2. // @name youtube_ex
  3. // @namespace http://userscripts.org/users/
  4. // @include https://www.youtube.com/*
  5. // @version 0.2
  6. // @grant none
  7. // @description enhanced youtube
  8. // ==/UserScript==
  9.  
  10. //====== common ========
  11.  
  12. function parseQueryStringToDictionary(queryString)
  13. {
  14. var dictionary = {};
  15.  
  16. var pos=queryString.indexOf('?');
  17. if (pos>=0)
  18. {
  19. queryString = queryString.substr(pos+1);
  20. }
  21.  
  22. var parts = queryString.split('&');
  23.  
  24. for(var i = 0; i < parts.length; i++)
  25. {
  26. var keyValuePair = parts[i].split('=');
  27. var key = keyValuePair[0];
  28. var value = keyValuePair[1];
  29.  
  30. value = decodeURIComponent(value);
  31. value = value.replace(/\+/g, ' ');
  32.  
  33. dictionary[key] = value;
  34. }
  35.  
  36. return dictionary;
  37. }
  38.  
  39.  
  40. var obv_cfg={attributes: false, childList: true, characterData: false};
  41.  
  42. function observer_factory(callback, isforeach=true)
  43. {
  44. var cb=isforeach ? function(mutations) {mutations.forEach(callback);} : callback;
  45. return new MutationObserver(cb);
  46. }
  47.  
  48. function simpleRemoveElement(sel)
  49. {
  50. var sep=sel.indexOf("##");
  51. var selector=sep>=0 ? sel.substr(sep+2) : sel;
  52. var node=document.querySelector(selector);
  53. if (node) node.parentNode.removeChild(node);
  54. }
  55.  
  56. function killElementAttribute(attrname)
  57. {
  58. var nodes=document.querySelectorAll('['+attrname+']');
  59. for (var i=0;i<nodes.length;i++)
  60. {
  61. nodes[i].removeAttribute(attrname);
  62. }
  63. }
  64.  
  65. //======= end of common =========
  66.  
  67. function trackless()
  68. {
  69. observer_factory(function (stub) {
  70. killElementAttribute("data-sessionlink");
  71. killElementAttribute("data-visibility-tracking");
  72. },false).observe(document.body, obv_cfg);
  73. }
  74.  
  75.  
  76. trackless();
  77.  
  78. function norecommend()
  79. {
  80. Array.prototype.slice.call(document.querySelectorAll("span.view-count")).filter(function (node){
  81. return /Recommended for you/i.test(node.innerHTML);
  82. }).forEach(function (node){
  83. var pnode=node.parentNode;
  84. while (pnode.tagName.toLowerCase()!="a" || Array.prototype.slice.call(pnode.classList).indexOf("content-link")<0){
  85. if (pnode==document.body) return;
  86. pnode=pnode.parentNode;
  87. }
  88. var recommend_link=pnode.href;
  89. while (pnode.tagName.toLowerCase()!="li" || Array.prototype.slice.call(pnode.classList).indexOf("video-list-item")<0){
  90. if (pnode==document.body) return;
  91. pnode=pnode.parentNode;
  92. }
  93. pnode.parentNode.removeChild(pnode);
  94. var vid=parseQueryStringToDictionary(recommend_link).v;
  95. //Array.prototype.slice.call(document.querySelectorAll('a#ytp-suggestion-set[href*="'+vid+'"]'));
  96. });
  97. }
  98.  
  99. norecommend();