Positioning advertisement code
Let's first position the logic of advertising on the page.
- Clue 1. Since the advertisement does not appear when the page is loaded, there must be an asynchronous method to load it;
- Clue 2: because every page is called, it is usually encapsulated in a js.
On the Druid main page, press F12, and you can see that the page references the following js file
<script src="js/lang.js" type="text/javascript" charset="utf8"></script> <script src="js/common.js" type="text/javascript" charset="utf8"></script>
After checking one by one, it is found that the advertisement code exists in common.js.
Thirtieth elements
buildFooter : function() { var html ='<footer class="footer">'+ ' <div class="container">'+ '<a href="https://render.alipay.com/p/s/taobaonpm_click/druid_banner_click" target="new"><img src="https://render.alipay.com/p/s/taobaonpm_click/druid_banner"></a><br/>' + ' powered by <a href="https://github.com/alibaba/" target="_blank">AlibabaTech</a> & <a href="http://www.sandzhang.com/" target="_blank">sandzhang</a> & <a href="http://melin.iteye.com/" target="_blank">melin</a> & <a href="https://github.com/shrekwang" target="_blank">shrek.wang</a>'+ ' </div>'+ ' </footer>'; $(document.body).append(html); }
Delete ad code
At present, we can modify the return content of common.js through the Filter filter without changing the source code.
- Judge whether the current path ends with / druid/js/common.js in Filter;
- Get the content that the current file path should return;
- Delete relevant code of advertisement and construct new content;
- Return the new content to the foreground;
if(requestUrl.contains("/druid/js/common.js")){ // Filter / druid/js/common.js path and replace the advertising code chain.doFilter(request, response); response.resetBuffer(); // Get common file content String text = Utils.readFromResource("support/http/resources/js/common.js"); // Regular expressions remove content between < footer class = "footer" > and < / footer >, including the footer itself text = text.replaceAll("<footer class=\"footer\">[^%]*</footer>", ""); // Return new content to front page response.getWriter().write(text); }
After rerunning the code, visit druid/js/common.js, and you will find that the ad code is gone.
buildFooter : function() { var html =''; $(document.body).append(html); },
At this time, I visited Druid's relevant page and found that there was no advertisement. It was a success!
Blog
https://my.oschina.net/gmarshal/blog/3074094
Welcome to my personal wechat subscription number: (it is said that this head portrait app is dedicated to apes)