Is it possible to find a general plugin to remove ads in a webpage?
I examined the webpage myself and found that, if I remove the content after a string "<li class='comments'>", most ads can be skipped and the stored page would be significantly smaller - one third the orginal size.
If possible, could you kindly also code the pre_save function for the job?
The webpage is:
http://www.businessweek.com/articles/2012-12-10/apples-cook-says-more-macs-will-be-born-in-the-u-dot-s-dot-a-dot
If you think this request is annoying, could you kindly send me an example doing similar stuff?
Thanks!
You can remove ads with a plugin, but it's difficult to write a general plugin. There is no a common method to recognize ads.
Any webpage is a tree in point view of browser. Tree nodes have ids or classes. You can remove nodes with specified ids/classes and ads will be removed. But each site uses his own ids/classes( Therefore general ads cleaner is impossible.
I wrote a simple plugin for businessweek.com articles -
//MPIQPlugin
//Type=PreSave
//Name=AntiAds
//Author=anfilat
function remove(nodes) {
var node;
for (i = nodes.length - 1; i >= 0; i--) {
node = nodes[i];
node.parentElement.removeChild(node);
}
}
function MP_PreSave() {
var dre1, dmn, host, classes, ids;
dre1 = new RegExp(/sanitize_seed_3pncu3gsfk4k84s8ws8gkgkk[sanitize_seed_3pncu3gsfk4k84s8ws8gkgkk^sanitize_seed_3pncu3gsfk4k84s8ws8gkgkk\/]+\/\/(sanitize_seed_3pncu3gsfk4k84s8ws8gkgkk[sanitize_seed_3pncu3gsfk4k84s8ws8gkgkk^sanitize_seed_3pncu3gsfk4k84s8ws8gkgkk\/]+)(?:\/(.*))?/);
dmn = document.URL.match(dre1);
if (dmn) {
host = dmn[1].toLowerCase();
if (host == "www.businessweek.com") {
classes = '.advertisement, .banner_ad';
ids = '#google_ads, #taboola-grid-2x2, #taboola-text-links, #taboola_wrapper, #bw_mall';
remove(document.querySelectorAll(classes + ', ' + ids));
}
}
}
Maybe it's worthwhile for me to learn something about Javascript.
Thanks a lot for your kindly help!
Anyway, thanks for your advice!
Merry Christmas and Happy New Year!