Chrome插件云新浪微博中的淘宝广告

新浪微博中的广告虽说不多,但是看着不舒服。写了个chrome插件去除了一部分,代码如下:

image

image

image

manifest.json:

{
  "name": "clear taobao from weibo",
  "version": "1.0",
  "manifest_version": 2,
  "description": "clear taobao from weibo",
  "permissions": [ "http://weibo.com/*"],
  "content_scripts": [ {
      "all_frames": true,
      "exclude_globs": [  ],
      "exclude_matches": [  ],
      "include_globs": [  ],
      "js": ["help.js"],
      "matches": [ "http://weibo.com/*"],
      "run_at": "document_idle"
   } ]
}

 

help.js:

function withjQuery(callback, safe) {
	if (typeof (jQuery) == "undefined") {
		var script = document.createElement("script");
		script.type = "text/javascript";
		script.src = "http://img3.douban.com/js/packed_jquery.min9556435062.js";
		if (safe) {
			var cb = document.createElement("script");
			cb.type = "text/javascript";
			cb.textContent = "jQuery.noConflict();(" + callback.toString()
					+ ")(jQuery, window);";
			script.addEventListener('load', function() {
				document.head.appendChild(cb);
			});
		} else {
			var dollar = undefined;
			if (typeof ($) != "undefined")
				dollar = $;
			script.addEventListener('load', function() {
				jQuery.noConflict();
				$ = dollar;
				callback(jQuery, window);
			});
		}
		document.head.appendChild(script);
	} else {
		setTimeout(function() {
			// Firefox supports
			callback(jQuery, typeof unsafeWindow === "undefined" ? window
					: unsafeWindow);
		}, 30);
	}
}
// 要进行的操作
withjQuery(
		function($, window) {
            $('div[ad-data^="id=ads_"]').attr('ad-data', '');
		}, true);

发表评论

邮箱地址不会被公开。 必填项已用*标注