Discussions » Creation Requests

need help: add button on youtube channel page to visit socialblade stats

§
Posted: 2022-01-25
Edited: 2022-01-25

When on YouTube click button to search for channel links on SocialBlade. This is what I have so far, but no button appears in bottom right corner that I can click to visit socialblade stats

  1. Visit YouTube channel
  2. Bottom right link button
  3. Click and it redirects in new tab https://socialblade.com/youtube/c/***/videos/highestrated
// ==UserScript==
// @name             YouTube to SocialBlade
// @description      When on YouTube click button to search for channel links on SocialBlade
// @license          MIT
// @include          https://www.youtube.com/c/*
// @include          https://www.youtube.com/channel/*
// @version          0.1
// @grant            none
// @icon             https://www.google.com/s2/favicons?domain=socialblade.com
// ==/UserScript==

(function() {
    'use strict';

    getChannelId();

    if (channelId) {

        let div = document.createElement('div');
        div.innerHTML = '<a id="socialbladeSearchButton">SocialBlade</a>';

        div.style.display = "inline-block";
        div.style.position = "fixed";
        div.style.right = "2%";
        div.style.bottom = "2%";
        div.style.zIndex = '9999';

        document.body.append(div);

        let icon = document.getElementById('socialbladeSearchButton');

        icon.style.background = 'white';
        icon.style.color = 'blue';
        icon.style.fontWeight = '800';
        icon.style.padding = '5px';
        icon.style.border = 'solid 2px black';
        icon.style.textDecoration = 'none';
        icon.style.fontSize = '14px';

        icon.href = 'https://socialblade.com/youtube/channel/' + channelId;
        icon.target = '_blank';
    }

    var channelId;

    function getChannelId() {
        let x = window.location.pathname;
        let arr = x.split('/');

        for (let i = 0; i < arr.length; i++){
            if (arr[i].substring(0,2) === 'channel' || arr[i].substring(0,2) === 'CHANNEL') {
                channelId = arr[i];
            }
        }
    }

})();
§
Posted: 2022-01-25

Call your function after you declared the function.
channelId is just a string, it is not true or false, and you are not checking for anything, your if condition is very wrong. Why would you need a if condition for that in the first place? I would just get rid of it and of your whole function and for loop.

You don't need any of that I think.

Call your function after you declared the function.
channelId is just a string, it is not true or false, and you are not checking for anything, your if condition is very wrong. Why would you need a if condition for that in the first place? I would just get rid of it and of your whole function and for loop.

You don't need any of that I think.

I'm still new at all this, would you mind sharing an updated snippet that is working? If not, no worries.

Thanks for your help.

§
Posted: 2022-01-26
Edited: 2022-01-26

// ==UserScript==
// @name YouTube to SocialBlade
// @description When on YouTube click button to search for channel links on SocialBlade
// @license MIT
// @include https://www.youtube.com/c/*
// @include https://www.youtube.com/channel/*
// @version 0.1
// @grant none
// @icon https://www.google.com/s2/favicons?domain=socialblade.com
// ==/UserScript==

(function() {
'use strict';
let div = document.createElement('div');
let channelId = location.pathname.split('/')[1]; //Change [1] to the right number
div.innerHTML = 'SocialBlade';

div.style.display = "inline-block";
div.style.position = "fixed";
div.style.right = "2%";
div.style.bottom = "2%";
div.style.zIndex = '9999';

document.body.append(div);

let icon = document.getElementById('socialbladeSearchButton');

icon.style.background = 'white';
icon.style.color = 'blue';
icon.style.fontWeight = '800';
icon.style.padding = '5px';
icon.style.border = 'solid 2px black';
icon.style.textDecoration = 'none';
icon.style.fontSize = '14px';

icon.href = 'https://socialblade.com/youtube/channel/' + channelId;
icon.target = '_blank';
})();

Post reply

Sign in to post a reply.