如何立即取消订阅所有Youtube频道?

时间:2018-02-19 21:22:54

标签: youtube automation

在过去的10年里,我订阅了超过300个Youtube频道,现在我必须清理我的Youtube,一个接一个地取消订阅需要一些时间,有没有办法一次取消订阅所有的cannels?

12 个答案:

答案 0 :(得分:17)

步骤1:转到https://www.youtube.com/feed/channels并滚动到页面底部,将所有项目填充到屏幕上。

步骤2:右键单击页面上的任意位置,然后单击" Inspect Element" (或者只是"检查"),然后点击"控制台",然后复制粘贴下面的脚本,然后点击 return

第3步:

var i = 0;

var myVar = setInterval(myTimer, 3000);

function myTimer () {

    var els = document.getElementById("grid-container").getElementsByClassName("ytd-expanded-shelf-contents-renderer");

    if (i < els.length) {

        els[i].querySelector("[aria-label^='Unsubscribe from']").click();

        setTimeout(function () {

            var unSubBtn = document.getElementById("confirm-button").click();

        }, 2000);

        setTimeout(function () {

            els[i].parentNode.removeChild(els[i]);

        }, 2000);

    }

    i++;

    console.log(i + " unsubscribed by YOGIE");

    console.log(els.length + " remaining");

}

第4步:坐下来看魔术!

享受!!

注意: 如果脚本停在某处,请刷新页面并再次执行所有四个步骤。

答案 1 :(得分:7)

Youtube频道取消订阅者(2020年4月发布)

  • 访问链接:https://www.youtube.com/feed/channels
  • F12
  • 在控制台中插入以下代码
function youtubeUnsubscriber() {
    var count = document.querySelectorAll("ytd-channel-renderer:not(.ytd-item-section-renderer)").length;
    var randomDelay = 500;

    if(count == 0) return false;

    function unsubscribeVisible(randomDelay) {

        if (count == 0) {
            window.scrollTo(0,document.body.scrollHeight);
            setTimeout(function() {
                youtubeUnsubscriber();
            }, 10000)
        }

        unsubscribeButton = document.querySelector('.ytd-subscribe-button-renderer');
        unsubscribeButton.click();

        setTimeout(function () {
            document.getElementById("confirm-button").click()
            count--;
            console.log("Remaining: ", count);

            setTimeout(function () {
                unsubscribedElement = document.querySelector("ytd-channel-renderer");
                unsubscribedElement.parentNode.removeChild(unsubscribedElement);
                unsubscribeVisible(randomDelay)
            }, randomDelay);
        }, randomDelay);
    }

    unsubscribeVisible(randomDelay);
}

youtubeUnsubscriber();

参考文献

答案 2 :(得分:2)

更新其他人提供的答案(因为最新的更新对我不起作用)

var i = 0;
var count = document.querySelectorAll("ytd-channel-renderer:not(.ytd-item-section-renderer)");

myTimer();

function myTimer () {	
    if (count == 0) return;

    el = document.querySelector('.ytd-subscribe-button-renderer');
    el.click();

    setTimeout(function () {
        var unSubBtn = document.getElementById("confirm-button").click();
        i++;
        count--;

        console.log(i + " unsubscribed");
        console.log(count + " remaining");

        setTimeout(function () {
            el = document.querySelector("ytd-channel-renderer");
            el.parentNode.removeChild(el);

            myTimer();
        }, 250);
    }, 250);
}

对我来说,这很成功。

答案 3 :(得分:1)

最有效的值:

(复制上面所有内容,包括最后一个)

var i = 0;

var myVar = setInterval(myTimer, 200);

function myTimer () {

    var els = document.getElementById("grid-container").getElementsByClassName("ytd-expanded-shelf-contents-renderer");

    if (i < els.length) {

        els[i].querySelector('[aria-label="Unsubscribe from this channel."]').click();

        setTimeout(function () {

            var unSubBtn = document.getElementById("confirm-button").click();

        }, 500);

        setTimeout(function () {

            els[i].parentNode.removeChild(els[i]);

        }, 1000);
    }

    i++;

    console.log(i + " unsubscribed by YOGIE");
    console.log(els.length + " remaining");
}

答案 4 :(得分:1)

https://gist.github.com/itsazzad/c1d86c5db86258ca129554a7b9ed92a7

明智地使用 DELAY 常量;考虑您的净速度。

// Go to the following link in your YouTube: https://www.youtube.com/feed/channels
// Scroll the page all the way down until you reach the very last subscribed channel in your list
const DELAY = 100;
const delay = ms => new Promise(res => setTimeout(res, ms));
const list = document.querySelectorAll("#grid-container > ytd-channel-renderer");
for (const sub of list) {
  await delay(DELAY);
  sub.querySelector("#subscribe-button > ytd-subscribe-button-renderer > paper-button").click();
  await delay(DELAY);
  document.querySelector("#confirm-button > a").addEventListener('click', async event => {
    await delay(DELAY);
    console.log(sub.querySelector("#text").innerText);
    await delay(DELAY);
  });
  await delay(DELAY);
  document.querySelector("#confirm-button > a").click()
  await delay(DELAY);
}

答案 5 :(得分:0)

这是最佳答案的一点补充: 您还可以使用jscompress [dot] com来压缩脚本,然后在脚本的开头添加 javascript:并将其添加到书签中-您可以从那里运行它-以防万一使用控制台或类似的工具不舒服。祝好运! :)

P.S 我没有足够的代表意见要评论,因此,无需告诉我我知道如果可能的话应该做的事情。

答案 6 :(得分:0)

更新Prashant Pimpale答案。刚才做了。

转到https://www.youtube.com/feed/channels,然后在控制台中复制/粘贴以下内容:

var i = 0;

var myVar = setInterval(myTimer, 200);

function myTimer () {

    var els = document.getElementById("contents").getElementsByClassName("ytd-subscribe-button-renderer");

    if (i < els.length) {

        els[i].querySelector('.ytd-subscribe-button-renderer').click();

        setTimeout(function () {

            var unSubBtn = document.getElementById("confirm-button").click();

        }, 500);

        setTimeout(function () {

            els[i].parentNode.removeChild(els[i]);

        }, 1000);
    }

    i++;

    console.log(i + " unsubscribed");
    console.log(els.length + " remaining");
}

答案 7 :(得分:0)

嗯,希望我先用Google搜索一下,然后再发布自己的。我对asyncawait感到很开心。尝试取消订阅的过程中,屏幕上出现了一些难看的闪烁,但这做得很好。

此脚本一次性捕获所有频道的一个前提条件是“耗尽”页面中的滚动器,即,继续滚动直到到达频道列表的末尾。正如其他人所述,转到YouTube Channels,打开开发人员控制台并粘贴以下脚本。

我已经在相关部分发表了评论,以防万一这最终成为某人的学习经历;)

/** 
 * Youtube bulk unsubsribe fn.
 * Wrapping this in an IIFE for browser compatibility.
 */
(async function iife() {
  // This is the time delay after which the "unsubscribe" button is "clicked"; Tweak to your liking!
  var UNSUBSCRIBE_DELAY_TIME = 2000

/**
 * Delay runner. Wraps `setTimeout` so it can be `await`ed on. 
 * @param {Function} fn 
 * @param {number} delay 
 */
  var runAfterDelay = (fn, delay) => new Promise((resolve, reject) => {
    setTimeout(() => {
      fn()
      resolve()
    }, delay)
  })



  // Get the channel list; this can be considered a row in the page.
  var channels = Array.from(document.getElementsByTagName(`ytd-channel-renderer`))
  console.log(`${channels.length} channels found.`)

  var ctr = 0
  for (const channel of channels) {
    // Get the subsribe button and trigger a "click"
    channel.querySelector(`[aria-label^='Unsubscribe from']`).click()
    await runAfterDelay(() => {
      // Get the dialog container...
      document.getElementsByTagName(`yt-confirm-dialog-renderer`)[0]
        // and find the confirm button...
        .querySelector(`#confirm-button`)
        // and "trigger" the click!
        .click()
      console.log(`Unsubsribed ${ctr + 1}/${channels.length}`)
      ctr++
    }, UNSUBSCRIBE_DELAY_TIME)
  }
})()

答案 8 :(得分:0)

如果有人正在寻找可行的解决方案,那么以下脚本对我有用:

转到https://www.youtube.com/subscription_manager并运行

M$colname = factor(M$colname, levels = c(level1,level2,...), labels = c(label1, label2,...))

参考:https://www.reddit.com/r/youtube/comments/ad3jv5/mass_unsubscribe_script/

答案 9 :(得分:0)

  1. 转到https://www.youtube.com/feed/channels
  2. 一直向下滚动,直到看到最后一个订阅的频道。
  3. 打开javascript控制台,粘贴以下代码,然后按Enter
let btns = document.querySelectorAll('paper-button > yt-formatted-string');

for (let i = 0; i < btns.length; i += 1) {
    if (btns[i].innerText.toLowerCase() === 'subscribed') {
        btns[i].click();
        document.getElementById('confirm-button').click();
    }
}

注意:对我来说,这种方法在Firefox上有效。 Chrome浏览器发出警告,页面无响应。于2020年10月20日为拥有956个订阅频道的帐户工作。

答案 10 :(得分:0)

我的解决方案,我认为是最新的,但事情总是在变化......

var unsubBtns = document.querySelectorAll(' div:nth-child(2) > div:nth-child(2) > div:nth-child(2) > ytd-subscribe-button-renderer:nth-child(1) > paper-button:nth-child(1)');

var i = 0; 

var interV = setInterval(function(){
   unsubBtns[i].click();
   i++;
   document.querySelector('yt-formatted-string.style-blue-text').click()
}, 1000);

答案 11 :(得分:0)

扩展 Jani 的回答,这个有一个 DOM 进度计数器。绝对没有 jQuery。

(function() {
    var i = 0;
    var ytdElem = document.querySelector("ytd-page-manager ytd-browse.ytd-page-manager");
    ytdElem.innerHTML = '<div style="font: 11pt arial; background: yellow; color: white" id="ytdjsds"></div>' + ytdElem.innerHTML;
    var element = document.getElementById("ytdjsds");
    var count = document.querySelectorAll("ytd-channel-renderer:not(.ytd-item-section-renderer)").length;
    if (count == 0) {
        element.innerHTML = "No subscriptions were found on your account.";
        return;
    }
    element.innerHTML = `Deleting subscription 1 of ${count}`;
    function myTimer() {
        if (count == 0) {
            element.innerHTML = `Successfully deleted subscriptions`;
            return;
        }
        element.innerHTML = `Deleting subscription ${i + 1} of ${count}`;
        el = document.querySelector('.ytd-subscribe-button-renderer');
        el.click();
        document.getElementById("confirm-button").style.display = "none";
        setTimeout(function() {
            var unSubBtn = document.getElementById("confirm-button").click();
            i++;
            setTimeout(function() {
                el = document.querySelector("ytd-channel-renderer");
                el.parentNode.removeChild(el);
                myTimer();
            }, 250);
        }, 250);
    }
    myTimer();
})();