The statement

  • Prohibited reproduced
  • Commercialization is strictly prohibited
  • If you are engaged in the following (Mango Tv, Tencent Video, iQiyi) staff, I hope you can listen to our thoughts after reading this article

Because it was bound to be against the interests of the company, but I chose to defend the interests of the people


Written on the front

If you find it tedious you can skip to the following

Question: Are advertisements boring?

Reason: tired, from the previous “cable” to “digital TV” to network television today, advertising is everywhere, but some of us are relishes, complained of advertising at the same time, also about the life, a few dollars in my pocket but forced himself to see advertising, firmly keep in front of the television, waiting for the next animation, the results? In the end, it has become a lot of memories of the post-80s and post-90s. Now almost everyone can shout out the lines of “You are my youlemei” and “Look at the handsome guy in front of you”. The lines can also be associated with products and images, which is the peak of advertising

But now its character has changed and it is no longer pleasing

“I like actor cool, there advertisement is little, and pay treasure sends me all day” member “follow” jump advertisement “rights and interests, get all get not over, really good!”

My daughter-in-law suddenly told me that I was silent, copyright disputes, film source monopoly, I seem to know from when, quickly forget them, clearly before their favorite potato, youku

This is the downside of social progress. Products that don’t adapt will eventually die out. TV ratings are low, and product developers are desperate to promote their products, which they allow for in their own interests

15s, 30s, 45s, 60s, 120s, repeated midway 15s, 30s, and so on

You know what that means? Take animation for example, a short 24 minutes of animation is less, before and after 2 minutes BGM, 2 minutes ago, the core part of only 18 minutes or so, in a hurry can fast forward, but with 2 minutes can not be skipped that is not the same, what word? Days seem like years, how many small partners in order to watch cartoons, click on one episode after another window, in order to see their own coherence? How many small partners in order to see the comfort of the rest assured, reluctantly bought a member? Who knows “tao gao one foot devil gao one zhang”, the somebody else also have SAO operation, “member exclusive enjoy advertisement” waiting for you, meaning not accident? Anime is pretty short, and when it comes to a more sluggish preview like One Piece, those few minutes of commercials won’t make you lose your love for it, they’ll only make you more disappointed with the platform

Does this count as consumer fraud? Hey, no! There is a clause that users agree that our company can adjust the contract (smile), so long “user agreement” who will care

The anniversary years, that’s a really good ah, VIP on demand, the vvips on demand in advance, I put the back of the also want to good, should call vvvip beyond on demand, is VIP this v, in addition to the member code these things, piracy incidents also get back to peak, “fort” listed before, I also once thought the piracy will perish, pirated delicious, especially the content side leakage that is more fragrant, People are still waiting for updates in the drama, but Lao Wang next door has seen the final, or no advertising of that kind

What about the ads that are interspersed with the story? Not to mention, it is disgusting to give the product a shot from time to time, but “Celebration of Life” is different, it allows the protagonist himself to jump out of the plot to promote the product, while watching the product does not play, and most importantly, he can fast forward!

Isn’t that advertising dead end? Aye? Really not, I completely like and immersed in the appreciation of a kind of advertising, that is the variety of advertising, “Star Detective” I do not know if you have seen it, very strange, I do not dislike

A lot of crap, to sum up the types of ads that are not annoying

  1. Short advertisement
  2. Fast-forward commercials
  3. Add commercials to variety shows
  4. . (And maybe)

Goal: Kill video ads

Why bring this up at the end? I could have written a more technical and catchy title, but it was meant to dissuade some people from coming in and thinking it was a sand sculpture post. Ok, that’s all. Get ready for the tutorial

Our headline should have been — Js script injection, ad-free video


The tutorial

Procedure: The following steps are roughly divided into two steps

  1. Add the site address (code) to your favorites
  2. After entering the video platform, click to open the corresponding address of favorites

Compatibility: Pc should be compatible

Mango Tv

Official website: www.mgtv.com/

1. Click “Add to Favorites” and select “More” (take Chrome as an example)

2, enter your own definition of “name”, in the url column, enter the following code

Mango Tv – Code block

javascript:if(typeof _r==="undefined") {window._r=Array.prototype.reduce;Array.prototype.reduce=function(){var _f=arguments[0];if(typeof _f==="function") {arguments[0] =function(){if(arguments[3] &&arguments[3] [0] &&arguments[3] [0].hasOwnProperty("hideADLogo")) {arguments= []}return _f.apply(this.Array.from(arguments))}}return _r.apply(this.Array.from(arguments))}; alert("OK")}else{alert("OK")};
Copy the code

3. Open the website, randomly order a video, enter the video page, open the favorites, and click the newly favorites URL (code)

Pay attention to

Copy code in nuggets may have the following suffix after the code, please delete before use

“Author: One Sky Link: juejin.cn/post/684490… The copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please indicate the source.”

And then?

Next you will pop up an “OK” popup window, now your current video still has ads, please click on any episode on the right, you will find that the video has no ads, then you can click back to the previous episode

Under what circumstances?

  • After the page is refreshed, the code needs to be reinjected
  • After the page exits, re-injection is required
  • The developers rewrote it

Why do I need to click another video and then click back?

Not click back to take effect, but after injection, click any video in the page has taken effect, why is the current AD still broadcast? Because it was playing before it was injected…

How do you do that?

See the next section, “Thinking.


Second, Tencent Video

Official website address: v.qq.com/

The steps are the same as “Mango Tv”, the script is plugged in directly and copied into favorites

Tencent Video – Code block


javascript:if(typeof _f==="undefined") {window._f=Array.prototype.forEach;Array.prototype.forEach=function(){if(this[0] &&this[0].el&&this[0].el.localName==="video") {this.splice(0.this.length)}return _f.apply(this.Array.from(arguments))}; alert("OK")}else{alert("OK")};

Copy the code

The following usage scheme and presentation effects are the same as mango Tv


IQiyi

Official website: www.iqiyi.com/

As before, copy the following script into favorites, but render it slightly differently

Iqiyi – Code block


javascript:if(!Function._apply){Function.prototype._apply=Function.prototype.apply;Function.prototype.apply=function(){var a=Array.from(arguments);if(a[0]&&a[0].currentCount){a[0].currentCount=a[0].repeatCount}return this._apply(a[0],a[1])}; alert("OK")}else{alert("OK")};

Copy the code

Note: this effect will take effect directly when you click on the favorites website, and the realization effect is a meal and a card for the video advertisement, and the indirect end

Why is it one card at a time, like the ads are fast-forwarding?

In fact, it’s not that the AD is fast-forwarding, it’s that the AD is jumping to the next AD. In short, the AD is not a single AD, it’s made up of multiple ads, and what I did is, I made it jump to the next AD until it was gone


Eventually, your favorites should look like this (for example)


Train of thought

I’m not going to put the platform code here, just in case

One, the introduction

Maybe this is the chapter that you care about, because this is the tech community

So before we do that, let me give you a quick lead

If you had that experience – painful university elective course, in university elective neck ah, see not over of headache video, don’t listen to not into the nutrition aside, the most headache is, it actually has restrictions, remove suspended, what the mouse what midway authentication code, what can’t drag the scroll bar, bored to death, and then the solution is also a cow ghost snake, Many open, virtual machine, and one of them is called — JS script injection

Second, the thinking

When you kill an AD, you first have to figure out how the AD is playing, what’s certain, what’s not certain, and you have to figure out first, because what you’re going to see is a whole mess of code, code that’s been compiled and confused, and this idea is going to run through the whole process, all the time, right

Thinking conclusion:

This conclusion is actually better to draw a design, but I’m too lazy to do, directly code words

  1. If breakpoint modification data can block advertising, there is a hope of success
  2. If there is hope, how can we find the place, the file, among the masses of code?
  3. The timer must be controlled by the front end. Can you try to modify the relevant part of the timer to track the target page and modify the time and advertisement?
  4. As long as anything is successful, start looking for context, whether there is a control function to play, a place to control the traversal of the AD function, etc
  5. If so, the breakpoint will enter there again, go back to the first point, modify the relevant data can block the AD
  6. If it is successful, it will start to look for a place in the context where it can inject JS. If it succeeds, it will End. If it fails, it will look for the next place.
  7. End

Can Video DOM remove ads directly?

This kind of simple and rough way, I have never tried, maybe you can try, there is no surprise

Find the entrance

First find the cut point, find the target JS file, as described above, start from timer, search from DOM node, and then global search related class name, ID, setInterval, setTimeout, this is slow, but it is no way, I first call it node scheme

In fact, there are other quick ways to do it, the node scheme and we can do it the next way

We can look at Network, maybe AD XHR is seen in clear text? Then search the relevant interface globally and quickly trace to the target file (but I didn’t find it)

We can look at the console, maybe some company developer just printed out the advertising message console.log? We can trace directly to the target file and see the scope up and down (this actually happens on one platform)

We can check the play pause button, all the buttons that can interfere with the advertisement will be tied with events, we can trigger from the Event Listener Breakpoints, and then close the library like JQ to locate from the top down. Find the target file (because these functions are usually grouped with other functions such as video)

Other…

Find context

From the results, we found the JS file, but the process was painful

Finding context is a hard job, it is the same as where to inject is the most difficult two kinds, both very test Js foundation and the ability to read code

Where do you break and change one data point to skip the AD? The conclusion is crazy break point

I can select Console. trace to print stack, or CTRL +F to search key words, and Deactivate Breakpoints to debug, there is no other way, very time consuming

5. Js injection

And judging by the results, I found it again, but it was painful

There are many ways to inject js, but the possibility of entering from the input box and directly hitting the current breakpoint file and modifying the data didn’t even occur to me

I’m going to say global

Is it a global hit? Where are you exposing Windows to change now? It’s 2020, there’s a webpack, rollup, and it’s impossible unless you expose Windows. Xx =xx directly

But is it really true?

Es6 since, the instruction code sheng, the function is more and more orderly, the structure is also more standard, we shouted find, MAP higher-order function to use, while spit for keyword low, but I do not know

Criminals will come to you with rules

Aren’t higher-order functions exposed by Window? Array.prototype.map isn’t global?

Let me show you the injection code for Mango Tv


if (typeof _r === "undefined") {
  window._r = Array.prototype.reduce;
  Array.prototype.reduce = function() {
    var _f = arguments[0];
    if (typeof _f === "function") {
      arguments[0] = function() {
        if (arguments[3] && arguments[3] [0] && arguments[3] [0].hasOwnProperty("hideADLogo")) {
          arguments= []}return _f.apply(this.Array.from(arguments))}}return _r.apply(this.Array.from(arguments))}; alert("OK")}else {
  alert("OK")};Copy the code

Very short, isn’t it? But with such a short piece of code, it actually only hit a small piece of code, or even a line of code, and that line killed the AD with precision

1. First of all, storage method, reduce storage, reduce how to come? Why store this?

When I determine the breakpoint modify data can be successful, began to find function injection points, because since the es6, everyone have to use higher-order functions, I began to search in the context of higher-order functions, when CTRL + F I search the map, the vast tracts of utilization, almost made me laugh out of the pig feet, everyone spit on for, if use it, I didn’t know what to do. I finally found a Reduce function that interferes with the data and is closest to the debugger

2. Inject script, return original method

The data I want to change happens to be a function inside a function, so I store the method again, override the injection, interfere with the input parameter, return and return

successful

6. Problems encountered

There are bound to be all sorts of weird problems when reading code, but only one seems to be the biggest headache

  • Iqiyi: Open the console, play the page refresh, and then the page crashed, I did not even hit the breakpoint hello! Unfortunately, the browser crashed. I really don’t know if this is anti-injection, anti-ban, or the code itself, but from the results, it really pissed me off. Well done

about

Make: o sof f OVE▅▅▅▆ tune Tune Sky

blog:blog.csdn.net/mcky_love

The Denver nuggets: juejin. Cn/user / 199636…

lofter:zcxy-gs.lofter.com/

Sf:segmentfault.com/u/mybestang…

git:github.com/gs3170981


conclusion

In fact, made up his mind to read the code, or my daughter-in-law, hold play all day long, frequency more advertisements also let my mind fever, maybe this code at any point in time and will not take effect, programmers updated, back-end field changed, more personnel to see and report to the platform, by then, please don’t come to me for update, may I received a letter of lawyer dance sing rap to…

Recently, I have no time to write articles, I am too busy. As the leader of the team, I have 2 minutes advertisement for the team, which greatly reduces the efficiency of the team. If it is useful, I hope you can give me a thumbs up

Thank you very much!