Duclv

Auto Insert Ads

Jul 17th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Play Ads Live Streaming
  3. // @namespace    duclvz
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        https://www.youtube.com/live*
  8. // @grant        unsafeWindow
  9. // ==/UserScript==
  10.  
  11. unsafeWindow.playAds = null;
  12. unsafeWindow.timeOut = null;
  13. unsafeWindow.countdown = null;
  14. unsafeWindow.startAuto = null;
  15. unsafeWindow.stopAuto = null;
  16. unsafeWindow.timer = null;
  17. unsafeWindow.countAds = 0;
  18. (function() {
  19.     'use strict';
  20.  
  21.     unsafeWindow.startAuto = function() {
  22.         var minutes, seconds;
  23.         unsafeWindow.playAds();
  24.         document.querySelector('#autoAds').setAttribute('onclick', 'stopAuto()');
  25.         document.querySelector('#autoAds').setAttribute('class', 'yt-uix-button yt-uix-button-size-default yt-uix-button-default yt-uix-button-destructive');
  26.         document.querySelector('#autoButton').textContent = 'Stop';
  27.         unsafeWindow.countdown = setInterval(function() {
  28.             minutes = parseInt(unsafeWindow.timer / 60, 10);
  29.             seconds = parseInt(unsafeWindow.timer % 60, 10);
  30.             minutes = minutes < 10 ? "0" + minutes : minutes;
  31.             seconds = seconds < 10 ? "0" + seconds : seconds;
  32.             document.querySelector('#autoTimer').textContent = minutes + ":" + seconds;
  33.             if (--unsafeWindow.timer < 0) {
  34.                 unsafeWindow.timer = 0;
  35.             }
  36.         }, 1000);
  37.     };
  38.     unsafeWindow.stopAuto = function() {
  39.         unsafeWindow.timer = 0;
  40.         clearInterval(unsafeWindow.countdown);
  41.         clearTimeout(unsafeWindow.timeOut);
  42.         document.querySelector('#autoAds').setAttribute('onclick', 'startAuto(document.querySelector("#autoTimer"))');
  43.         document.querySelector('#autoAds').setAttribute('class', 'yt-uix-button yt-uix-button-size-default yt-uix-button-default');
  44.         document.querySelector('#autoButton').textContent = 'Auto';
  45.     };
  46.     var div = document.createElement('div');
  47.     div.innerHTML = '<button id="autoAds" onclick="startAuto()" type="button" class="yt-uix-button yt-uix-button-size-default yt-uix-button-default"><span id="autoButton" class="yt-uix-button-content">Auto</span> | <span id="countAds">0</span> | <span id="autoTimer"></span><button>';
  48.     if (window.location.href.indexOf("live_dashboard") > -1) {
  49.         document.querySelector('div.dashboard-control.player-controls-buttons').insertBefore(div.firstChild, document.querySelector('div.dashboard-control.player-controls-buttons').childNodes[0]);
  50.     }
  51.     if (window.location.href.indexOf("live_event_analytics") > -1) {
  52.         document.querySelector('#live-rtd-analytics-mode-content').insertBefore(div.firstChild,document.querySelector('#live-rtd-analytics-mode-content').childNodes[2]);
  53.     }
  54.     unsafeWindow.playAds = function() {
  55.         var current = null;
  56.         if (window.location.href.indexOf("live_dashboard") > -1) {
  57.             document.querySelector('div.yt-uix-hovercard.play-ad-button-hovercard > button').click();
  58.             console.log('Played Ads');
  59.             document.querySelector('#countAds').textContent = ++unsafeWindow.countAds;
  60.             current = parseInt(document.querySelector('div.metric-count-viewership.analytics-summary-metric-header-number').innerHTML);
  61.         }
  62.         if (window.location.href.indexOf("live_event_analytics") > -1) {
  63.             document.querySelector('button#submit-ad-button').click();
  64.             console.log('Inserted Ads');
  65.             document.querySelector('#countAds').textContent = ++unsafeWindow.countAds;
  66.             current = parseInt(document.querySelector('#live-rtd-info-button-current-streams-content').innerHTML);
  67.         }
  68.         if (current > 70) {
  69.             unsafeWindow.timeOut = setTimeout(playAds, 180000);
  70.             unsafeWindow.timer = 180;
  71.         }
  72.         else if (current > 0) {
  73.             unsafeWindow.timeOut = setTimeout(playAds, 180000 * 70 / current);
  74.             unsafeWindow.timer = 180 * 70 / current;
  75.         }
  76.     };
  77. })();
Advertisement
Add Comment
Please, Sign In to add comment