chrome脚本-知乎专栏广告屏蔽、知乎登录屏蔽

一: 知乎广告屏蔽

将代码放在Tampermonkey中运行

// ==UserScript==
// @name         知乎专栏广告屏蔽
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://zhuanlan.zhihu.com/*
// @icon         https://www.google.com/s2/favicons?domain=zhihu.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    console.log("asd");
window.setInterval(get, 300);
function get()
{
    let elementsByClassName = document.getElementsByClassName("Button Modal-closeButton Button--plain")[0];
    if (elementsByClassName) {
        elementsByClassName.click();
        console.log("屏蔽专栏广告");
    }
}
    console.log("asdssss");
})();

二: 知乎登录屏蔽

// ==UserScript==
// @name         知乎登录屏蔽
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.zhihu.com/*
// @icon         https://www.google.com/s2/favicons?domain=zhihu.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    console.log("asd");
window.setInterval(get, 300);
function get()
{
    let elementsByClassName = document.getElementsByClassName("Button Modal-closeButton Button--plain");
    let elementsByClassName2 = document.getElementsByClassName("Button QuestionRichText-more Button--plain");
    let elementsByClassName1 = document.getElementsByClassName("Pc-word-card-sign-label");


    if (elementsByClassName1.length!=0) {
        for (const elementsByClassName1Element of elementsByClassName1) {
            elementsByClassName1Element.click();
            let elementsByClassName3 = document.getElementsByClassName("Pc-word-card-sign-popup-menu");
            if (elementsByClassName3.length!=0) {
                elementsByClassName3[0].firstElementChild.click();;
                console.log("删除广告");
            }
        }
    }
    if (elementsByClassName.length!=0) {
        elementsByClassName[0].click();
        console.log("屏蔽登录");
    }
    if (elementsByClassName2.length!=0) {
        elementsByClassName2[0].click();
        console.log("打开全文");
    }
}
    console.log("asdssss");
})();

你可能感兴趣的:(chrome,javascript,前端)