Skip to content
Browse files

Added exclusion rules for the module "Block External Scripts" (sprash…

…ivai.ru, API vkontakte.ru, API twitter.com, API facebook.com, API odnoklassniki.ru, CDN Amazon, CDN Microsoft)

work isActiveDomain()
  • Loading branch information...
1 parent 6a23a38 commit fa4ae4067f581a15989fb83a6a6b637d9904b10f @Gemorroj committed
Showing with 50 additions and 38 deletions.
  1. +5 −4 includes/noads-common.js
  2. +17 −10 includes/noads-options.js
  3. +1 −1 includes/noads-service.js
  4. +25 −21 includes/noads.js
  5. +2 −2 index.html
View
9 includes/noads-common.js
@@ -16,8 +16,8 @@ var extension = window.opera.extension;
// Helper Functions
// Example: log('[NoAds]: test..');
-var decodeMessage = function(data) { return JSON.parse(data); };
-var encodeMessage = function(data) { return JSON.stringify(data); };
+var decodeMessage = function (data) { return JSON.parse(data); };
+var encodeMessage = function (data) { return JSON.stringify(data); };
var log = function () { if (bDebug) opera.postError('[NoAdsAdvanced] ' + Array.prototype.slice.call(arguments)); };
var extend = function (first, second) { for (var prop in second) { if (!first[prop]) first[prop] = second[prop];} };
var getValue = function (name) { return storage[name] || ''; };
@@ -42,7 +42,7 @@ var addStyle = function (css, id) {
};
var replaceStyle = function (ele, css) {
if (ele) {
- if(!(document.documentElement instanceof window.HTMLHtmlElement)) throw "Not an HTML page.";
+ if (!(document.documentElement instanceof window.HTMLHtmlElement)) throw "Not an HTML page.";
while (ele.firstChild) ele.removeChild(ele.firstChild);
ele.appendChild(document.createTextNode(css));
}
@@ -55,7 +55,8 @@ var splitCSS = function (css) {
var getTLD = function (domain, full) {
if (!domain) return '';
var r = domain.match(/^((?:\d{1,3}\.){3})\d{1,3}$/); if (r) return r[1] + '0';
- var a = domain.split('.'), l = a.length; if (l < 2) return domain;
+ var a = domain.split('.');
@Dither
Dither added a note

Нафига?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ var l = a.length; if (l < 2) return domain;
return full ? a[l - 2] + '.' + a[l - 1] : a[(l > 2 && /^(co|com|net|org|edu|gov|mil|int)$/i.test(a[l - 2])) ? l - 3 : l - 2];
};
var unique = function () {
View
27 includes/noads-options.js
@@ -52,6 +52,7 @@ var imgRefresh = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf
var imgSave = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAH+SURBVBgZBcE9i11VGAbQtc/sO0OCkqhghEREAwpWAWUg8aMVf4KFaJEqQtAipTZWViKiCGOh2Ap2gmJhlSIWFsFOxUK0EsUM3pl79n4f12qHb3z3Fh7D83gC95GOJsDe0ixLk5Qq/+xv/Lw9Xd+78/HLX3Y8fXTr2nWapy4eCFKxG7Fby97SnDlYtMbxthyfzHO//nl85fNvfvnk8MbX5xa8IHx1518Vkrj54Q+qQms2vVmWZjdiu5ZR2rT01166/NCZg/2PFjwSVMU6yjoC1oq+x6Y3VbHdlXWExPd379nf7Nmejv2Os6OC2O4KLK0RNn3RNCdr2Z5GJSpU4o+/TkhaJ30mEk5HwNuvX7Hpi76wzvjvtIwqVUSkyjqmpHS0mki8+9mPWmuWxqYvGkbFGCUAOH/+QevYI9GFSqmaHr5wkUYTAlGhqiRRiaqiNes6SOkwJwnQEqBRRRJEgkRLJGVdm6R0GLMQENE0EkmkSkQSVVMqopyuIaUTs0J455VLAAAAAODW0U/GiKT0pTWziEj44PZ1AAAAcPPqkTmH3QiJrlEVDXDt0qsAAAAAapa5BqUnyaw0Am7//gUAAAB49tEXzTmtM5KkV/y2G/X4M5fPao03n/sUAAAAwIX7y5yBv9vhjW/fT/IkuSp5gJKElKRISYoUiSRIyD1tufs/IXxui20QsKIAAAAASUVORK5CYII=';
var imgLoad = 'data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==';
+
var options = {
stop: null,
checkEnabled: function (name) { return getValue(name) != 'disabled'; },
@@ -139,7 +140,9 @@ var options = {
return rez.join(',');
},
getReScriptBlock: function (name) {
- var rule, pos, rez = [], tmp = getValue(name).split('\n');
+ var rule, pos, rez = [], tmp = getValue(name);
+ if (!tmp) return false;
+ tmp.split('\n');
for (var i = 0, l = tmp.length; i < l; i++) {
rule = tmp[i];
pos = rule.indexOf('##$$');
@@ -190,10 +193,10 @@ var options = {
isWhiteListed: function (rule, domain) {
var pos = rule.indexOf('$');
if (pos != -1) rule = rule.slice(0, pos);
- var end = rule.charAt(rule.length - 1) == '^';
+ var end = rule.charAt(rule.length - 1) === '^';
if (end) rule = rule.slice(0, -1);
pos = domain.indexOf(rule);
- return (pos == 0 || pos > 0 && domain.charAt(pos - 1) == '.') && (!end || pos + rule.length == domain.length);
+ return (pos == 0 || pos > 0 && domain.charAt(pos - 1) === '.') && (!end || pos + rule.length == domain.length);
},
setWhiteList: function (name, value) {
var rule, rez = [], arr = value.split('\n');
@@ -206,11 +209,11 @@ var options = {
},
// create default white list
setDefWhiteList: function () {
- var whiteList = '~translate.google.com,~youtube.com,~metacafe.com,~lastfm.ru,~livegames.ru,~vkontakte.ru,~vk.com,~eurosport.ru,~imageshack.us,~britannica.com,~vimeo.com,~virustotal.com,~wikipedia.org,~newegg.com,~yahoo.com,~facebook.com,~deviantart.com,~hotmail.com,~picasaweb.google.com,~playset.ru,~molotok.ru,~megashare.by,~ya.ru,~acid3.acidtests.org,~mail.ru,~piter.fm,~kinozal.tv,~tvshack.net,~anonym.to,~twitter.com,~flickr.com,~myspace.com,~bbc.co.uk,~ebay.com,~opera.com,~imdb.com,~macromedia.com';
- var skipScripts = '^data:|^https?://[0-9a-z-]*.googleapis.com|^https?://translate.googleusercontent.com|^https?://[0-9a-z-]*.yahooapis.com|^http://yuilibrary.com|^https?://www.google.com/jsapi|^https?://maps.google.com|^https?://www.google.com/recaptcha|^http://[0-9a-z-]+.gstatic.com|^https?://[0-9a-z-]+.appspot.com|^https?://yui.yahooapis.com|^https?://script.aculo.us|^https?://api.bit.ly|^http://static.myopera.com|^http://ipinfodb.com|^http://fonts.gizmodo.com|^http://fastcache.gawkerassets.com|^https?://api.recaptcha.net|^http://rutube.ru|^https?://css.yandex.net|^https?://api-maps.yandex.ru|^https?://sstatic.net|^http://s\\d+.addthis.com/js|^https?://s\\d+.ucoz.net/src/u.js|^http://[0-9a-z-]+.imgsmail.ru|^https?://[0-9a-z-]+.hotmail.|^https?://[0-9a-z-]+.wlxrs.com|^https?://auth.tbn.ru|^https?://easylist-downloads.adblockplus.org/[a-z_+-]+.txt$|^https?://secure.fanboy.co.nz/[a-z_+-]+.txt$|swfobject.js$|yahoo-dom-event.js$|bundle_github.js$|show_afs_search.js$|chart.js$|ajax.js$|widgets.js$|common.js$|AC_RunActiveContent.js$|ext[0-9a-z.-]*.js$|yui[0-9a-z.-]*.js$|jquery[0-9a-z.-]*.js$';
+ var whiteList = '~translate.google.com,~youtube.com,~metacafe.com,~lastfm.ru,~livegames.ru,~vkontakte.ru,~vk.com,~eurosport.ru,~imageshack.us,~britannica.com,~vimeo.com,~virustotal.com,~wikipedia.org,~newegg.com,~yahoo.com,~facebook.com,~deviantart.com,~hotmail.com,~picasaweb.google.com,~playset.ru,~molotok.ru,~megashare.by,~ya.ru,~acid3.acidtests.org,~mail.ru,~piter.fm,~kinozal.tv,~tvshack.net,~anonym.to,~twitter.com,~flickr.com,~myspace.com,~bbc.co.uk,~ebay.com,~opera.com,~imdb.com,~macromedia.com,~sprashivai.ru';
+ var skipScripts = '^data:|^https?://[0-9a-z-]*.googleapis.com|https?://apis.google.com|^https?://translate.googleusercontent.com|^https?://[0-9a-z-]*.yahooapis.com|^http://yuilibrary.com|^https?://www.google.com/jsapi|^https?://maps.google.com|^https?://www.google.com/recaptcha|^http://[0-9a-z-]+.gstatic.com|https?://ajax.aspnetcdn.com|https?://ajax.microsoft.com|^https?://[0-9a-z-]+.appspot.com|^https?://yui.yahooapis.com|^https?://script.aculo.us|^https?://api.bit.ly|^http://static.myopera.com|^http://ipinfodb.com|^http://fonts.gizmodo.com|^http://fastcache.gawkerassets.com|^https?://api.recaptcha.net|^http://rutube.ru|https?://yandex.st|^https?://css.yandex.net|^https?://api-maps.yandex.ru|^https?://sstatic.net|https?://platform.twitter.com/anywhere.js|^https?://vkontakte.ru/js/api/openapi.js|https?://api.odnoklassniki.ru/js/fapi.js|^https?://connect.facebook.net|^https?://[0-9a-z-]*.cloudfront.net|^http://s\\d+.addthis.com/js|^https?://s\\d+.ucoz.net/src/u.js|^http://[0-9a-z-]+.imgsmail.ru|^https?://[0-9a-z-]+.hotmail.|^https?://[0-9a-z-]+.wlxrs.com|^https?://auth.tbn.ru|^https?://easylist-downloads.adblockplus.org/[a-z_+-]+.txt$|^https?://secure.fanboy.co.nz/[a-z_+-]+.txt$|swfobject.js$|yahoo-dom-event.js$|bundle_github.js$|show_afs_search.js$|chart.js$|ajax.js$|widgets.js$|common.js$|AC_RunActiveContent.js$|ext[0-9a-z.-]*.js$|yui[0-9a-z.-]*.js$|jquery[0-9a-z.-]*.js$';
var rez = [], arr = whiteList.split(',');
for (var i = 0, rule; rule = arr[i]; i++) {
- if (rule.charAt(0) == '~') rez.push('@@||' + rule.slice(1) + '^');
+ if (rule.charAt(0) === '~') rez.push('@@||' + rule.slice(1) + '^');
}
setValue('noads_scriptlist_white', rez.join('\n') + '\n@@==' + skipScripts);
rez = null;
@@ -230,14 +233,18 @@ var options = {
rez = null;
},
isActiveDomain: function (name, domain, retRe) {
- //log('wtf is going on '+domain+' with '+name);
- var rule, rez = [], tmp = getValue(name).split('\n');
+ var rule, rez = [], tmp = getValue(name);
+ if (!tmp) return retRe ? new RegExp('^$') : true;
+
+ tmp = tmp.split('\n');
+
for (var i = 0, l = tmp.length; i < l; i++) {
rule = tmp[i];
- if (rule.indexOf('@@||') == 0) { if (this.isWhiteListed(rule.slice(4), domain)) return false; } // @@|| - direct domain, @@== - RegExp domain
+ // @@|| - direct domain, @@== - RegExp domain
+ if (rule.indexOf('@@||') == 0) { if (this.isWhiteListed(rule.slice(4), domain)) return retRe ? new RegExp('^*$') : false; }
else if (retRe && rule.indexOf('@@==') == 0) rez.push(rule.slice(4));
}
- //log((new RegExp(rez.join('|'))).toString());
+
tmp = null;
return retRe ? new RegExp((rez.join('|').replace(/\/|\.(?=[\w\d])/g, '\\$&') || '^$'), 'i') : true;
},
View
2 includes/noads-service.js
@@ -13,7 +13,7 @@
// ==/UserScript==
// global variables
-var bDebug = true, reSkip, reBlock, sStyle, uStyle, sMagic = '', sCSS = '', uCSS = '', blockedScripts = '', inlineScripts = 0;
+var bDebug = true, sStyle, uStyle, sCSS = '', uCSS = '', blockedScripts = '';
var none = '{display: none !important;}',
highlightCSS = '{background-color: #FF5555 !important; outline: 1px solid #FF1111 !important; opacity: 0.6 !important;}',
paddingCSS = 'iframe, embed, object {\
View
46 includes/noads.js
@@ -13,7 +13,7 @@
// ==/UserScript==
// global variables
-var bDebug = options.checkEnabled('noads_debug_enabled_state'), currentdomain, reSkip, reBlock, sStyle, uStyle, sMagic = '', sCSS = '', uCSS = '', bgImages = '', blockedScripts = '', inlineScripts = 0;
+var bDebug = options.checkEnabled('noads_debug_enabled_state'), sStyle, uStyle, sCSS = '', uCSS = '', bgImages = '', blockedScripts = '', inlineScripts = 0;
(function() {
//if(document !== undefined && document.documentElement && !(document.documentElement instanceof window.HTMLHtmlElement)) return;
@@ -60,12 +60,12 @@ var bDebug = options.checkEnabled('noads_debug_enabled_state'), currentdomain, r
}
// also must be parsed on BeforeScript event as class sometimes unavailible before
} else {*/
- (function(name, debug) {
+ (function (name, debug) {
window.opera.defineMagicFunction(j[1], function () { if (debug) window.opera.postError('[NoAdsAdvanced] function ' + name + ' is void'); return; });
})(j[1], bDebug);
//}
- (function(name, debug) {
+ (function (name, debug) {
window[name] = function () { if (debug) window.opera.postError('[NoAdsAdvanced] function ' + name + ' is void'); return; };
})(j[1], bDebug);
} //blocking variables
@@ -91,27 +91,31 @@ var bDebug = options.checkEnabled('noads_debug_enabled_state'), currentdomain, r
}, false);
// Block external scripts
- if (options.checkEnabled('noads_scriptlist_state') && (reSkip = options.isActiveDomain('noads_scriptlist_white', domain, true))) {
- blockingText += ', external scripts';
- window.opera.addEventListener('BeforeExternalScript', function (e) {
- var src = e.element.src;
- if (!src || reSkip.test(src) || e.element.isNoAdsSubscription) return;
- var site = window.location.hostname, full = !/\.(com|[a-z]{2})$/i.test(site);
- var a = src.match(/^https?:\/\/([^\/]+@)?([^:\/]+)/i);
- if (getTLD(a ? a[2] : site, full) != getTLD(site, full)) {
- e.preventDefault();
- if (blockedScripts.indexOf(src) == -1) blockedScripts += blockedScripts ? '; ' + src : src;
- log('blocked script -> ' + src + ' for <' + site + '>');
- }
- }, false);
-
- if (reBlock = options.getReScriptBlock('noads_scriptlist')) {
- window.opera.addEventListener('BeforeScript', function (e) {
- if (reBlock.test(e.element.text)) {
+ if (options.checkEnabled('noads_scriptlist_state')) {
@Dither
Dither added a note

Объясни что делаешь и зачем, если не трудно. Желательно это конечно было делать в описании коммита.

@Gemorroj Owner

в данном случае, просто мелочи. этот код мне понятнее.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ var reSkip = options.isActiveDomain('noads_scriptlist_white', domain, true);
+ if (reSkip) {
+ blockingText += ', external scripts';
+ window.opera.addEventListener('BeforeExternalScript', function (e) {
+ var src = e.element.src;
+ if (!src || reSkip.test(src) || e.element.isNoAdsSubscription) return;
+ var site = window.location.hostname, full = !/\.(com|[a-z]{2})$/i.test(site);
+ var a = src.match(/^https?:\/\/([^\/]+@)?([^:\/]+)/i);
+ if (getTLD(a ? a[2] : site, full) != getTLD(site, full)) {
e.preventDefault();
- inlineScripts++;
+ if (blockedScripts.indexOf(src) == -1) blockedScripts += blockedScripts ? '; ' + src : src;
+ log('blocked script -> ' + src + ' for <' + site + '>');
}
}, false);
+
+ var reBlock = options.getReScriptBlock('noads_scriptlist');
+ if (reBlock) {
+ window.opera.addEventListener('BeforeScript', function (e) {
+ if (reBlock.test(e.element.text)) {
+ e.preventDefault();
+ inlineScripts++;
+ }
+ }, false);
+ }
}
}
View
4 index.html
@@ -8,8 +8,8 @@
<script type='text/javascript' src='scripts/noads-importer.js'></script>
<script type='text/javascript'>
var bDebug = options.checkEnabled('noads_debug_enabled_state'),
- arrayFilters = new Array(),
- arrayUserFilters = new Array(),
+ arrayFilters = [],
+ arrayUserFilters = [],
EXCLUDE = '[exclude]',
UUID = '', tab, filter = opera.extension.urlfilter;

0 comments on commit fa4ae40

Please sign in to comment.
Something went wrong with that request. Please try again.