no-yandex-ads

Removes ads on *.yandex.ru

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        no-yandex-ads
// @namespace   yandex
// @description Removes ads on *.yandex.ru
// @description:ru Убирает рекламу на Яндексе
// @include     *://*.yandex.ru/*, *://yandex.ru/*
// @version     1
// @grant       none
// ==/UserScript==

var
  emptyAds = '{"ads":{"ids":[],"inquire":{"dtype":"stred","path":"0"}}}';

[].forEach.call(document.querySelectorAll(".ads"), function(ad) {
  ad.setAttribute("data-bem", emptyAds);
});

var
  target = document.querySelector('.b-page__inner');

var
  observer = new MutationObserver(function(mutations) {
    [].forEach.call(document.querySelectorAll(".ads"), function(ad) {
      var data = JSON.parse(ad.getAttribute("data-bem")).ads;
      data.ids.forEach(function(id, index) { data.ids[index] = "#" + id });
      var selector = data.ids.join(",");
      [].forEach.call(document.querySelectorAll(selector), function(n) {
        n.remove();
      });
    });
  });
 
var
  config = { childList: true, subtree: true };

observer.observe(target, config);