Thingiverse AdBlock

Blocks ads from Thingiverse

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           Thingiverse AdBlock
// @description    Blocks ads from Thingiverse 
// @description:de Blendet Werbung auf Thingiverse aus
// @author         Tobse
// @license        MIT
// @name:de        Thingiverse AdBlock
// @name:en        Thingiverse AdBlock
// @match          https://www.thingiverse.com/thing*
// @run-at         document-idle
// @version        0.1.2.20221001100000
// @namespace      https://github.com/TobseF
// ==/UserScript==

function blockAds(){
    let found = '';
    let i = 0;
    let query = "//div[contains(@class,\"AdCard\")]"
    do {
        found  = document.evaluate(query, document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue
        if(found  != null){
            found.remove()
        }
    } while (found  != null && i < 10);
}

(new MutationObserver(waitForGallery)).observe(document, {childList: true, subtree: true});

function waitForGallery(changes, observer) {
    // Wait until image gallery is visible
    if (document.querySelector('[class^="AdCard"]')) {
        observer.disconnect();
        blockAds();
    }
}