downthemall / anticontainer

DownThemAll! AntiContainer (Extension to a Firefox, Seamonkey extension)
Mozilla Public License 2.0
93 stars 41 forks source link

Naver.net redirector plugin #140

Open Shigeto1 opened 7 years ago

Shigeto1 commented 7 years ago

I'm trying to modify the following naver plugin to work with an alternate subdomain of naver.net:

{
    "type": "redirector",
    "author": "1z2x1z",
    "ns": "naver.net",
    "prefix": "naver.net_JPG",
    "match": "^https?://blogfiles.naver.net/[A-Za-z0-9._~-]+/[A-Za-z0-9._~-]+/[A-Za-z0-9._~%-]+.jpg\\?type=w[1-9]+",
    "pattern": "jpg\\?type=w[1-9]+",
    "replacement": "jpg"
}

The subdomain looks like this:

http://mimgnews1.naver.net/image/origin/433/2017/05/29/30725.jpg?type=wc318_q90 http://mimgnews2.naver.net/image/origin/433/2017/05/29/30730.jpg?type=wc318_q90 http://mimgnews1.naver.net/image/origin/117/2016/12/24/2856261.jpg?type=nfc135_124_q90 http://mimgnews2.naver.net/image/origin/011/2017/05/29/3041474.jpg?type=nfc135_124_q90 and http://mimgnews1.naver.net/image/origin/433/2017/05/29/30732.jpg?type=m1920_1080 http://mimgnews2.naver.net/image/origin/433/2017/05/29/30733.jpg?type=m1920_1080

The url I'm trying to redirect to would be:

http://mimgnews[1-2].naver.net/image/origin/433/2017/05/29/30725.jpg

I don't know anything about regex or javascript but this was the best I could come up with:

{
    "type": "redirector",
    "author": "test",
    "ns": "naver.net",
    "prefix": "naver x dispatch HD",
    "match": "^https?://mimgnews[1-2]{1}.naver.net/image/origin/[0-9]{3}/[0-9]{4}/[0-9]{2}/[0-9]{2}/[A-Za-z0-9._~%-]+.jpg\\?type=[a-zA-Z0-9_]+",
    "pattern": "jpg\\?type=[a-zA-Z0-9_]+",
    "replacement": "jpg"
}

Ideally I would like the plugin to work for both types of links but for testing I'm only using the first type (http://mimgnews1.naver.net/image/origin/433/2017/05/29/30734.jpg?type=wc318_q90).

I'm not positive the regex string is even correct however I tested it with the following javascript:

    var str = "http://mimgnews1.naver.net/image/origin/433/2017/05/29/30734.jpg?type=wc318_q90";
    var patt = new RegExp("^https?://mimgnews[1-2]{1}.naver.net/image/origin/[0-9]{3}/[0-9]{4}/[0-9]{2}/[0-9]{2}/[A-Za-z0-9._~%-]+.jpg\\?type=[a-zA-Z0-9_]+");
    var res = patt.test(str);

The script returned a 'true' result which as far as I know indicates the regex pattern is a match, but the plugin does not work as intended. After opening the webpage I'm trying to rip with DTA, I can see the image links but the thumbnail ?type suffixes have not been removed as seen here:

output

This is all pretty new to me and I'm not sure what I'm doing wrong. Any help would be greatly appreciated.