Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. window.CustomYoutube = window.CustomYoutube || {};
  2.  
  3. CustomYoutube = (function() {
  4. const selectors = {
  5. RecoverHeading: '#RecoverHeading',
  6. RecoverEmail: '#RecoverEmail',
  7. LoginHeading: '#LoginHeading'
  8. };
  9.  
  10. function _isSearchPage(){
  11. return /search/.test(window.location.href);
  12. }
  13.  
  14. function copyToClipboard(text) {
  15. if (window.clipboardData && window.clipboardData.setData) {
  16. // IE specific code path to prevent textarea being shown while dialog is visible.
  17. return clipboardData.setData("Text", text);
  18.  
  19. } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
  20. var textarea = document.createElement("textarea");
  21. textarea.textContent = text;
  22. textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge.
  23. document.body.appendChild(textarea);
  24. textarea.select();
  25. try {
  26. return document.execCommand("copy"); // Security exception may be thrown by some browsers.
  27. } catch (ex) {
  28. console.warn("Copy to clipboard failed.", ex);
  29. return false;
  30. } finally {
  31. document.body.removeChild(textarea);
  32. }
  33. }
  34. }
  35.  
  36. function numberToEnglish( n ) {
  37.  
  38. var string = n.toString(), units, tens, scales, start, end, chunks, chunksLen, chunk, ints, i, word, words, and = 'and';
  39.  
  40. /* Remove spaces and commas */
  41. string = string.replace(/[, ]/g,"");
  42.  
  43. /* Is number zero? */
  44. if( parseInt( string ) === 0 ) {
  45. return 'zero';
  46. }
  47.  
  48. /* Array of units as words */
  49. units = [ '', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen' ];
  50.  
  51. /* Array of tens as words */
  52. tens = [ '', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety' ];
  53.  
  54. /* Array of scales as words */
  55. scales = [ '', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quatttuor-decillion', 'quindecillion', 'sexdecillion', 'septen-decillion', 'octodecillion', 'novemdecillion', 'vigintillion', 'centillion' ];
  56.  
  57. /* Split user arguemnt into 3 digit chunks from right to left */
  58. start = string.length;
  59. chunks = [];
  60. while( start > 0 ) {
  61. end = start;
  62. chunks.push( string.slice( ( start = Math.max( 0, start - 3 ) ), end ) );
  63. }
  64.  
  65. /* Check if function has enough scale words to be able to stringify the user argument */
  66. chunksLen = chunks.length;
  67. if( chunksLen > scales.length ) {
  68. return '';
  69. }
  70.  
  71. /* Stringify each integer in each chunk */
  72. words = [];
  73. for( i = 0; i < chunksLen; i++ ) {
  74.  
  75. chunk = parseInt( chunks[i] );
  76.  
  77. if( chunk ) {
  78.  
  79. /* Split chunk into array of individual integers */
  80. ints = chunks[i].split( '' ).reverse().map( parseFloat );
  81.  
  82. /* If tens integer is 1, i.e. 10, then add 10 to units integer */
  83. if( ints[1] === 1 ) {
  84. ints[0] += 10;
  85. }
  86.  
  87. /* Add scale word if chunk is not zero and array item exists */
  88. if( ( word = scales[i] ) ) {
  89. words.push( word );
  90. }
  91.  
  92. /* Add unit word if array item exists */
  93. if( ( word = units[ ints[0] ] ) ) {
  94. words.push( word );
  95. }
  96.  
  97. /* Add tens word if array item exists */
  98. if( ( word = tens[ ints[1] ] ) ) {
  99. words.push( word );
  100. }
  101.  
  102. /* Add 'and' string after units or tens integer if: */
  103. if( ints[0] || ints[1] ) {
  104.  
  105. /* Chunk has a hundreds integer or chunk is the first of multiple chunks */
  106. if( ints[2] || (i + 1) > chunksLen ) {
  107. words.push( and );
  108. }
  109.  
  110.  
  111. }
  112.  
  113. /* Add hundreds word if array item exists */
  114. if( ( word = units[ ints[2] ] ) ) {
  115. words.push( word + ' hundred' );
  116. }
  117.  
  118. }
  119.  
  120. }
  121.  
  122. return words.reverse().join( ' ' );
  123.  
  124. }
  125.  
  126. String.prototype.replaceAll = function(obj) {
  127. let finalString = '';
  128. let word = this;
  129. for (let each of word){
  130. for (const o in obj){
  131. const value = obj[o];
  132. if (each == o){
  133. each = value;
  134. }
  135. }
  136. finalString += each;
  137. }
  138.  
  139. return finalString;
  140. };
  141.  
  142. function getAboutLinkAtSearchPage(){
  143. var users = document.querySelectorAll('#main-link[href]');
  144. var getAboutPage = (url) => `https://www.youtube.com${url}/about`
  145. var aboutPages = [];
  146.  
  147. for (let each of users){
  148. let url = each.getAttribute('href');
  149. let subs = each.querySelector('#subscribers').textContent;
  150. let channelName = each.querySelector('#text.ytd-channel-name').textContent;
  151. let subsEnglish;
  152.  
  153. const formatUrl = (() => {
  154. url = getAboutPage(url);
  155. })();
  156.  
  157. const formatChannelName = (() => {
  158. channelName = channelName.trim();
  159. })();
  160.  
  161. const formatSubs = (() => {
  162. subs = subs.replace('mil','000');
  163. subs = subs.replaceAll({'M':'0000', ',':'', ' ':''});
  164. subs = subs.replace(/\D/g,'');
  165. })();
  166.  
  167. const formatSubsEnglish = (() => {
  168. subsEnglish = numberToEnglish(subs);
  169. })();
  170.  
  171. aboutPages.push({
  172. channelName,
  173. url,
  174. subs,
  175. subsEnglish
  176. });
  177. }
  178.  
  179. console.table(aboutPages);
  180. copyToClipboard([...aboutPages].map(e=>e.url).join('\n'));
  181.  
  182. }
  183.  
  184.  
  185.  
  186.  
  187. return {
  188. init: function() {
  189. document.addEventListener("DOMContentLoaded", function() {
  190.  
  191. if (_isSearchPage()){
  192.  
  193. }
  194.  
  195. });
  196. },
  197. getAboutLinkAtSearchPage
  198. };
  199. })();
  200.  
  201.  
  202. CustomYoutube.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement