Skip to content

Instantly share code, notes, and snippets.

@azu azu/ad.js
Created May 23, 2011

Embed
What would you like to do?
adblock++ から adblock# 形式へ変換する(Firebug上で実行)
/**
* Created by azu.
* Date: 11/05/23 23:36
* License: MIT License
*/
// extensions.adblock++.filter_array の値を入れる
var adblockData = [
["feedad", 1, 326103, true],
["/ads", 1, 217358, true],
["/ad.", 1, 129717, true],
["banner", 1, 108402, true],
["pagead2.googlesyndication.com", 1, 93681, true],
["/ad/", 1, 35539, true],
["accesstrade.net", 1, 14168, true],
["http://www.facebook.com/plugins/like.php", 1, 13499, true],
["rcm-jp.amazon.co.jp", 1, 13001, true],
["bdv", 1, 6168, true],
["atdmt.com", 1, 3408, true],
["microad.jp", 1, 2599, true],
["revsci.net", 1, 2341, true],
["468_", 1, 1889, true],
["http://api.tweetmeme.com/button.js", 1, 1343, true],
["axad", 1, 1162, true],
["http://uad.nicovideo.jp/delivery/uajs.php", 1, 894, true],
["pagead", 1, 358, true],
["im.yahooapis.jp", 1, 13, true],
["imgad", 1, 0, true],
["/^http:\\/\\/ext\\.nicovideo\\.jp\\/thumb\\//$subdocument", 2, 8811, true],
["http://efcl.info", 0, 612150, true],
["http://www.feedly.com/", 0, 4254, true],
["http://www.slideshare.net/", 0, 3548, true]
];// これを自分の変えて使う
(function() {
var types = {
"WhiteLists" : 0,
"Filters" : 1,
"RegExps" : 2
};
function getType(typeNumber) {
for (var type in types) {
if (types[type] == typeNumber) {
return type;
}
}
}
function convertData(data) {
adblockData = data || adblockData;
var result = [];
for (var i = 0,len = adblockData.length; i < len; i++) {
var ary = adblockData[i];
var filter = ary[0];// filert文字列
if (!ary[3]) {// 無効になってるなら無視
continue;
}
switch (getType(ary[1])) {//配列の二番目がtype
case "WhiteLists":
result.push("@@" + filter);
break;
case "Filters" :
result.push(validStringFilter(filter));
break;
case "RegExps":
if (hasSubContent(filter)) {
break;
}
result.push(filter);
break;
default:
log(filter);
}
}
return result;
}
// /string/ が誤爆する場合を防ぐ
function validStringFilter(filter) {
if (typeof filter !== "string") {
return filter;
}
if (filter[0] === "/" && filter[filter.length - 1] === "/") {
return "*" + filter + "*"
} else {
return filter;
}
}
function hasSubContent(filter) {
var subcontents;
if (typeof hasSubContent.regExp === "undefined") {
subcontents = ["$image","$script","$stylesheet","$object","$subdocument","$xmlhttprequest",
"$link","$other","$refresh","$media","$ping","$dtd","$font","$subrequest","$xbl"];
hasSubContent.regExp = new RegExp("(\\" + subcontents.join("|\\") + ")$", "i");
}
if (hasSubContent.regExp.test(filter)) {
log("SubContent: " + filter);
return true;
}
}
function log() {
console && console.log.apply(this, arguments);
}
copy(convertData().join("\n"));
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.