Ad-block is a plugin similar to ad-Block, but its function is not to block advertising, but [block article] [block author], you do not want to see the article or post above the right click, you can choose to block the author or block the article, the next time will not see his article! Isn’t it fun? Let’s explore

First, why do you want to build this plug-in

A few days ago, I came to [nuggets former webmaster @ Yin Yin] a column “old webmaster recent questions answered”, I have nothing to do to browse the comments, found that many digging friends have blocked the article or the appeal of the author, but nuggets does not have this function at present

The screenshot below is from the comments of digger at the bottom of the old webmaster’s recent questions













I belong to the restless kind, always like to find something to do to cultivate a sentiment. Since there are so many people hope to have a shielding function, that I do a must be used? So I made this blocking plugin

What plug-ins do

As anyone who has used Ad-Block knows, it can block ads from a browser, but it’s not a great way to block certain articles or authors.

So what I’ve done is a plugin called Content-block, which allows you to right click on an article or author that you don’t want to see and block that content. But it’s limited to the Chrome desktop browser

Content – Block

The installation

The plugin has been released to the Chrome App Store and can be installed by clicking here.

If not, you can download the source code locally and install the experience as follows


use

(1) In the home page list page, right click the article you don’t like, in the right menu to choose [block author] or [block article]

(2) Right-click anywhere on the article page to block the article or author

[View my Block list]

Click on the plugin icon in the upper right corner of your browser to view your blocked data, where you can remove an author or article from your blocked list



Plug-in shielding range

Currently, only the home page column is supported. – boiling points are not supported (for later consideration)

How to close a plug-in

If you don’t want to block it or temporarily unblock it, just close Chrome here ://extensions/

[Note] If you choose to delete the plug-in, install again, the previous shielded data will not be, operation must be careful



Realize the principle of

The process is about 3 steps

1. Right-click the article you don’t want to see, get the information about the article, including the article URL, author, etc

2. Add article information to the local storage

3. Intercept the request and return filtered data according to the storage to exclude the masked data

The code structure



  • Main.js is responsible for filtering the data
  • Content.js is responsible for message communication and parsing dom
  • Background.js create right-click menu
  • Bridge. Js is responsible for dynamically inserting JS (solve the problem that plug-ins can’t get browser JS variables)
  • Pop.js plugin to block list rendering

Core point: How do I intercept requests?

In the case of nuggets, page requests are sent based on XML request, modify it, specific code [main.js]

For some reason, the code always pasted into a line, only screenshots



Data Storage [Chrome.storage.sync]

What makes it different from regular storage is that you can associate your Chrome account with it. If you switch computers, you log in to your account and your data is synchronized

If you look at the code, you will see that the plugin also uses localStorge. The reason is that the security policy of the Chrome plugin does not allow the plugin to access the browser JS variables directly, so the plugin’s data needs to be synchronized to the page localStorge, and the masked data can be obtained directly from main.js

The last

Plug-in installation address chrome.google.com/webstore/de…

The code section of the article only introduces the core of a point, if you want to see the full code, please go to github.com/ColdDay/con…

Open source is not easy, I will give you a Star as an encouragement, thanks

Declaration: because the author level is limited, does not guarantee the stability of the plug-in or other unknown bugs, only for learning

Please correct me if you have any questions