Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.CustomYoutube = window.CustomYoutube || {};
- CustomYoutube = (function() {
- const selectors = {
- RecoverHeading: '#RecoverHeading',
- RecoverEmail: '#RecoverEmail',
- LoginHeading: '#LoginHeading'
- };
- function _isSearchPage(){
- return /search/.test(window.location.href);
- }
- function copyToClipboard(text) {
- if (window.clipboardData && window.clipboardData.setData) {
- // IE specific code path to prevent textarea being shown while dialog is visible.
- return clipboardData.setData("Text", text);
- } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
- var textarea = document.createElement("textarea");
- textarea.textContent = text;
- textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in MS Edge.
- document.body.appendChild(textarea);
- textarea.select();
- try {
- return document.execCommand("copy"); // Security exception may be thrown by some browsers.
- } catch (ex) {
- console.warn("Copy to clipboard failed.", ex);
- return false;
- } finally {
- document.body.removeChild(textarea);
- }
- }
- }
- function numberToEnglish( n ) {
- var string = n.toString(), units, tens, scales, start, end, chunks, chunksLen, chunk, ints, i, word, words, and = 'and';
- /* Remove spaces and commas */
- string = string.replace(/[, ]/g,"");
- /* Is number zero? */
- if( parseInt( string ) === 0 ) {
- return 'zero';
- }
- /* Array of units as words */
- units = [ '', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen' ];
- /* Array of tens as words */
- tens = [ '', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety' ];
- /* Array of scales as words */
- 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' ];
- /* Split user arguemnt into 3 digit chunks from right to left */
- start = string.length;
- chunks = [];
- while( start > 0 ) {
- end = start;
- chunks.push( string.slice( ( start = Math.max( 0, start - 3 ) ), end ) );
- }
- /* Check if function has enough scale words to be able to stringify the user argument */
- chunksLen = chunks.length;
- if( chunksLen > scales.length ) {
- return '';
- }
- /* Stringify each integer in each chunk */
- words = [];
- for( i = 0; i < chunksLen; i++ ) {
- chunk = parseInt( chunks[i] );
- if( chunk ) {
- /* Split chunk into array of individual integers */
- ints = chunks[i].split( '' ).reverse().map( parseFloat );
- /* If tens integer is 1, i.e. 10, then add 10 to units integer */
- if( ints[1] === 1 ) {
- ints[0] += 10;
- }
- /* Add scale word if chunk is not zero and array item exists */
- if( ( word = scales[i] ) ) {
- words.push( word );
- }
- /* Add unit word if array item exists */
- if( ( word = units[ ints[0] ] ) ) {
- words.push( word );
- }
- /* Add tens word if array item exists */
- if( ( word = tens[ ints[1] ] ) ) {
- words.push( word );
- }
- /* Add 'and' string after units or tens integer if: */
- if( ints[0] || ints[1] ) {
- /* Chunk has a hundreds integer or chunk is the first of multiple chunks */
- if( ints[2] || (i + 1) > chunksLen ) {
- words.push( and );
- }
- }
- /* Add hundreds word if array item exists */
- if( ( word = units[ ints[2] ] ) ) {
- words.push( word + ' hundred' );
- }
- }
- }
- return words.reverse().join( ' ' );
- }
- String.prototype.replaceAll = function(obj) {
- let finalString = '';
- let word = this;
- for (let each of word){
- for (const o in obj){
- const value = obj[o];
- if (each == o){
- each = value;
- }
- }
- finalString += each;
- }
- return finalString;
- };
- function getAboutLinkAtSearchPage(){
- var users = document.querySelectorAll('#main-link[href]');
- var getAboutPage = (url) => `https://www.youtube.com${url}/about`
- var aboutPages = [];
- for (let each of users){
- let url = each.getAttribute('href');
- let subs = each.querySelector('#subscribers').textContent;
- let channelName = each.querySelector('#text.ytd-channel-name').textContent;
- let subsEnglish;
- const formatUrl = (() => {
- url = getAboutPage(url);
- })();
- const formatChannelName = (() => {
- channelName = channelName.trim();
- })();
- const formatSubs = (() => {
- subs = subs.replace('mil','000');
- subs = subs.replaceAll({'M':'0000', ',':'', ' ':''});
- subs = subs.replace(/\D/g,'');
- })();
- const formatSubsEnglish = (() => {
- subsEnglish = numberToEnglish(subs);
- })();
- aboutPages.push({
- channelName,
- url,
- subs,
- subsEnglish
- });
- }
- console.table(aboutPages);
- copyToClipboard([...aboutPages].map(e=>e.url).join('\n'));
- }
- return {
- init: function() {
- document.addEventListener("DOMContentLoaded", function() {
- if (_isSearchPage()){
- }
- });
- },
- getAboutLinkAtSearchPage
- };
- })();
- CustomYoutube.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement