API
https://developers.google.com/youtube/v3/docs/subs...
Вот как реализована у vkmix (но там не через ajax, а делают так будто пользователь нажимает кнопки ):
subscribe: function subscribe() {
var _selectors2;
var selectors = (_selectors2 = {}, (0, _defineProperty3.default)(_selectors2, PREF_NEW, function () {
return {
done: (0, _jquery2.default)('#subscribe-button paper-button.ytd-subscribe-button-renderer').attr('subscribed') !== undefined,
scroll: (0, _jquery2.default)('#contents'),
loaded: '#comments',
subscribe: (0, _jquery2.default)('#subscribe-button > ytd-subscribe-button-renderer > paper-button')
};
}), (0, _defineProperty3.default)(_selectors2, PREF_OLD, function () {
var selector = '.branded-page-v2-col-container';
return {
done: (0, _jquery2.default)('.yt-uix-button-subscribed-branded.yt-uix-subscription-button').attr('data-is-subscribed') !== undefined,
scroll: (0, _jquery2.default)(selector),
loaded: selector,
subscribe: (0, _jquery2.default)('.yt-uix-button-subscribe-branded.yt-uix-subscription-button')
};
}), _selectors2),
selector = selectors[PREF]();
var i = 0,
cycle = {
checkDone: function checkDone() {
if (selector.done) {
worker.done();
} else {
this.scrollContents();
}
},
scrollContents: function scrollContents() {
var _this2 = this;
(0, _jquery2.default)('html, body').animate({
scrollTop: selector.scroll.offset().top
}, TIMEOUT_CHANNEL.SCROLL).promise().then(function () {
interval = setInterval(_this2.contentsLoaded, TIMEOUT_SCROLL_BACK);
});
},
contentsLoaded: function contentsLoaded() {
i++;
if ((0, _jquery2.default)(selector.loaded).length) {
clearInterval(interval);
(0, _jquery2.default)('html, body').animate({
scrollTop: 0
}, TIMEOUT_SCROLL_BACK).promise().then(function () {
setTimeout(cycle.subscribe, TIMEOUT_CHANNEL.TOTAL - TIMEOUT_CHANNEL.SCROLL - TIMEOUT_SCROLL_BACK * 2);
});
} else if (i >= 1000 / TIMEOUT_SCROLL_BACK * 30) {
clearInterval(interval);
worker.ignored();
}
},
subscribe: function subscribe() {
selector.subscribe.click();
setTimeout(worker.done, 3500);
}
};
}