Greasy Fork

Greasy Fork is available in English.

killZhihuAd-屏蔽知乎广告-沉浸模式浏览

干掉知乎广告+沉浸模式可选;只优化知乎,没有其他乱七八糟的功能

当前为 2020-10-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         killZhihuAd-屏蔽知乎广告-沉浸模式浏览
// @description  干掉知乎广告+沉浸模式可选;只优化知乎,没有其他乱七八糟的功能
// @namespace    http://tampermonkey.net/
// @icon         https://www.zhihu.com/static/favicon.ico
// @version      0.3(2020/10/19)
// @author       shawn
// @run-at       document-end
// @match        *://*.zhihu.com/*
// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// ==/UserScript==


(function() {
    /* global $ */
    'use strict';
    //沉浸模式开关
    var focus_mode_on = GM_getValue("focus_mode_on");
    if(focus_mode_on){
        GM_registerMenuCommand("☑ 沉浸模式", focus_close, "");
    } else {
        GM_registerMenuCommand("☐ 沉浸模式", focus_open, "");
    }
    function focus_open () {
        GM_setValue("focus_mode_on", true);
        location.reload();
    }
    function focus_close () {
        GM_setValue("focus_mode_on", false);
        location.reload();
    }

    //取消二次转链
    if(window.location.host == "link.zhihu.com"){
    	var regRet = location.search.match(/target=(.+?)(&|$)/);
    	if(regRet && regRet.length == 3){
    		location.href = decodeURIComponent(regRet[1]);
    	}
	}

    //去除特定广告
    $('.css-520aav').remove();
    $(".Footer").remove();//侧边栏底部信息

    //+沉浸模式+杀掉侧边栏、调整卡片宽度
    if(focus_mode_on){
        if(window.location.href.indexOf("https://www.zhihu.com/question/") != -1) {
            setTimeout(resetQuestionColumn, 50);
            setInterval(resetQuestionColumn, 1000);
	    } else if (window.location.href.indexOf("https://www.zhihu.com/search") != -1) {
            setTimeout(resetSearchColumn, 50);
        } else {
            setTimeout(resetMainColumn, 50);
            setInterval(killCardAd, 500);
        }
    } else {
        if(window.location.href.indexOf("https://www.zhihu.com/question/") != -1) {
            setInterval(killSideBarAd, 500);
	    } else {
            setInterval(killCardAd, 500);
            setInterval(killSideBarAd, 500);
        }
    }

    function killCardAd() {
        //答案卡片中的广告
        $(".TopstoryItem--advertCard").remove();
    }
    function killSideBarAd() {
        //右边栏广告
        $(".Pc-card").each(function(){
            if($(this).find(".Banner-adTag").length != 0){
                $(this).remove();
            }
        });
    }
    function resetQuestionColumn() {
        $(".Question-sideColumn").remove();
        $(".Question-mainColumn").width('960px');
        $(".ContentItem-actions").width('920px');
    }
    function resetMainColumn() {
        $(".GlobalSideBar").remove();
        $(".Topstory-mainColumn").width('960px');
        $(".ContentItem-actions").width('920px');
    }
    function resetSearchColumn() {
        $(".SearchSideBar").remove();
        $(".SearchMain").width('960px');
        $(".ContentItem-actions").width('920px');
    }

})();