Giter VIP home page Giter VIP logo

del_ad_chrome_ext's Introduction

A chrome extension for removing ads on the web page.

一款简易的chrome拓展程序,可清除页面中的广告。

仓库里是整个插件包,下载安装chrome拓展可以直接使用,chrome插件安装及配置参考: http://open.chrome.360.cn/extension_dev/getstarted.html

通过在匹配的页面注入js脚本文件,通过找到页面中的广告框然后将其隐藏(通过JQ hide()方法)达到清除广告的效果。

通过寻找页面中广告的特性,通过算法可以得到广告框的外层id或者类名。

简单的算法如下:

//简单的智能算法
findSomeAdPossible: function() {
	//找到可能的广告wrapper
	var sap = $('div iframe'),
	    ad_img = $('div script').parent().find('img,embed'),
	    float_img = $('div object').parent().find('img,embed');

	    this.arrayDel(sap,360,200);
	    this.arrayDel(ad_img,350,150);
	    this.arrayDel(float_img,350,150);
},
arrayDel : function(arr,conWidth,conHeight){
	var len = arr.length;

	for(var i = 0 ; i<len ; i++){
		var self = arr.eq(i);

		if(self.width() <= conWidth || self.height() <= conHeight) {
			self.hide();
		}

	}
}

另外设置了一个id数组和class数组用于存放那些没有特性的广告框容器名,缺点是需要手动收集

clear: function() {
	//此处可手动添加广告框id名,去除顽疾ad必备
	var ad_id_name = [
		"cproIframe2001holder",
		"cproIframe2002holder",
		"cproIframe2003holder",
		"cproIframe2004holder",
		"cproIframe2005holder",
		"cproIframe2006holder",
		"cproIframe2007holder",
		"cproIframe2008holder",
		"id_300x250_banner_top",
		"ads",
		"google_image_div",
		"mx_cs_71603_1261456",
		"AC_TR86_71603",
		"cproIframe_u2060917_1",
		"google_image_div",
		"content_right"
	];

	//此处添加广告框类名
	var ad_css_name = [
		"cproIframe_u410704_3",
		"img_ad",
		"hover_btn"
	];

	for (var i = 0; i < ad_id_name.length; i++) {
		$('#' + ad_id_name[i]).hide();
	}

	for (var i = 0; i < ad_css_name.length; i++) {
		$('.' + ad_css_name[i]).hide();
	}
}

由于manifest文件匹配规则只有通配没有非功能,所以可在此方法可以设置不想删除广告的页面

checkUrl: function() {
	var Checkflag = 0,
		url = window.location.href;

	//手动添加不需要清除广告的域
	var notDel = [
		"www.baidu.com",
		"taobao.com",
		"tmall.com",
		"jd.com"
	];

	//正则匹配
	for (var i = 0; i < notDel.length; i++) {
		var reg = new RegExp(notDel[i], "g");

		if (reg.test(url)) {
			console.log('This page does not clear ads.');
			break;
		} else {
			if (i == notDel.length - 1) {
				Checkflag = 1;
			}
		}
	}
	
	if (Checkflag == 1) {
		this.clear();
		this.findSomeAdPossible();
	}
}

如果安装了无法正常使用,需要进行如下配置,打开chrome浏览器,输入框输入

chrome://flags/#enable-npapi

然后,然后启用 NPAPI 、启用 实验性扩展程序 API

blog介绍地址:http://www.cnblogs.com/coco1s/p/4725477.html

del_ad_chrome_ext's People

Contributors

chokcoco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

del_ad_chrome_ext's Issues

manifest的定义存在一些问题

算是一点最佳实践:

1: browser_action 是不需要的,因为一点功能都没有,就显示一个静态的Clear success?不要增加不必要的浏览器元素。
2:permission也是不需要的,因为在content_script中已经定义了。不做CROS,不动态注入的话,不需要申请网址permission
3:content_scripts中的matches值可简写为“:///”, 其他网址的定义就更不需要了。只要有了:///,就是对所有网址都生效,无需再申明其他网址匹配。
4:content_scripts还可添加一项“run_at”:"document_end",这样注入的文件就会在文档节点加载完以后就开始执行,否则默认会等所有资源都加载完才执行。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.