YT Trending Phone Number Removal Tool

Removes Phone Numbers from YouTube Trending Page video descriptions

  1. // ==UserScript==
  2. // @name YT Trending Phone Number Removal Tool
  3. // @namespace https://greasyfork.org/en/scripts/394084-yt-trending-phone-number-removal-tool
  4. // @version 1.1
  5. // @description Removes Phone Numbers from YouTube Trending Page video descriptions
  6. // @author TheBerzzeker
  7. // @match *://www.youtube.com/feed/trending*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function loadDescriptions(){
  12.  
  13. var description_elements = document.getElementsByTagName("yt-formatted-string");
  14.  
  15. for ( var i=0;i<description_elements.length;++i){
  16. GetPhoneNumber(description_elements[i]);
  17. }
  18.  
  19. }
  20.  
  21. function GetPhoneNumber(description_el){
  22.  
  23. var description = description_el.innerHTML;
  24. var phone_vals = ["07","+4","+40","0 7","0.7","0-7"];
  25. var modified = false;
  26.  
  27. for(var i=0;i<phone_vals.length;++i){
  28. if(!description.includes(phone_vals[i])) continue;
  29.  
  30. var index = description.indexOf(phone_vals[i]);
  31.  
  32. HashNumbers(description_el,index);
  33.  
  34. modified =true;
  35.  
  36. }
  37.  
  38.  
  39. if(modified) GetPhoneNumber(description_el);
  40.  
  41. }
  42.  
  43. function HashNumbers(description_el,index){
  44.  
  45. var description = description_el.innerHTML;
  46.  
  47. console.log(description);
  48. console.log(index);
  49.  
  50. var beginning=0,ending = description.length;
  51.  
  52. console.log(beginning);
  53. console.log(ending);
  54.  
  55. for(var i=index;i>=0;--i){
  56. if(description[i]>='a' && description[i]<='z') {beginning = i+1;break;}
  57. if(description[i]>='A' && description[i]<='Z') {beginning = i+1;break;}
  58. }
  59.  
  60. for(i=index;i<description.length;++i){
  61. if(description[i]>='a' && description[i]<='z') {ending = i;break;}
  62. if(description[i]>='A' && description[i]<='Z') {ending = i;break;}
  63. }
  64.  
  65. var a_str = description.substring(0,beginning);
  66. var b_str = description.substr(ending);
  67.  
  68. var middle = ". ";
  69. /*
  70. for(i = beginning;i<ending;++i){
  71. middle+="*";
  72. }
  73. */
  74.  
  75.  
  76. description_el.innerHTML=a_str+middle+b_str;
  77.  
  78. }
  79.  
  80. loadDescriptions();