no-yandex-ads

Removes ads on *.yandex.ru

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);