让unblock youku 和 pullywood 去广告插件和平相处

6月27号更新,前一阵子更新很频繁.这次迎来一个大更新.整个urls2pac方法重写了
直接给出修改后的结果,40-42行是添加的部分: (43行完整了一下逻辑,加了个else)

View Code JAVASCRIPTDownload tools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function urls2pac(url_whitelist, url_list, proxy_server) {
    "use strict";
    var http_map_str = gen_url_map('http', url_whitelist, url_list);
    var https_map_str = gen_url_map('https', url_whitelist, url_list);
 
    var txt = [
        "var _http_map = " + http_map_str + ";",
        "var _https_map = " + https_map_str + ";",
        "var _proxy_str = 'PROXY " + proxy_server + "';",
        "",
        "function _check_regex_list(regex_list, str) {",
        "  var i;",
        "  for (i = 0; i < regex_list.length; i++)",
        "    if (regex_list[i].test(str))",
        "      return true;",
        "  return false;",
        "}",
        "",
        "function _check_patterns(patterns, hostname, full_url, prot_len) {",
        "  if (patterns.hasOwnProperty(hostname))",
        "    if (_check_regex_list(patterns[hostname],",
        "        full_url.slice(prot_len + hostname.length)))",  // check only :port/path
        "      return true;",
        "  if (_check_regex_list(patterns.any,",  // try our best to speed up the checking for non-proxied urls
        "      full_url.slice(prot_len)))",  // check hostname:port/path
        "    return true;",
        "  return false;",
        "}",
        "",
        "function _find_proxy(url_map, host, url, prot_len) {",
        "  if (_check_patterns(url_map.white, host, url, prot_len))",
        "      return 'DIRECT';",
        "  if (_check_patterns(url_map.proxy, host, url, prot_len))",
        "    return _proxy_str;",
        "  return 'DIRECT';",
        "}",
        "",
        "function FindProxyForURL(url, host) {",  // host doesn't contain port
        "  var prot = url.slice(0, 6);",
        "  var regexStr = /^.*?:\\/\\/.*?(youku|qiyi|iqiyi|letv|sohu|ku6|ku6cdn|pps)\\.(com|tv)\\/crossdomain\\.xml$/;\n",
        "  if(regexStr.test(url))",
        "    return 'PROXY api.youku.com:80' ",
        "  else if (prot === 'http:/')",
        "    return _find_proxy(_http_map, host, url, 7);",  // 'http://'.length
        "  else if (prot === 'https:')",
        "    return _find_proxy(_https_map, host, url, 8);",  // 'https://'.length
        "  return 'DIRECT';",
        "}"
    ].join("\n") + "\n";
 
    // console.log('==================');
    // console.log(txt);
    // console.log('==================');
 
    return txt;
}

____________________我是分割线_________________________
4月24号更新,因为我浏览器一般都不关,mac也不关,有时候unblock youku更新了我这里也影响不到,所以更新有时候问题解决的不及时,
最近期末了,没工夫搞这个,先直接给出个work的方法吧:

View Code JAVASCRIPTDownload tools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function urls2pac(url_whitelist, url_list, proxy_server) {
    "use strict";
    var s = 'function FindProxyForURL(url, host) {\n' +
        ' var regexStr = /.*?:\\/\\/.*?(youku|qiyi|iqiyi|letv|sohu|ku6|ku6cdn)\\.com\\/crossdomain\\.xml/;\n' +
            '    if (';
 
    var i;
    s += 'regexStr.test(url)){\n' +
         ' return "PROXY api.youku.com:80";\n' +
         ' }\n';
 
    s += 'else if (';
 
    if (url_whitelist.length > 0) {
	for (i = 0; i < url_whitelist.length; i++) {
            s += 'shExpMatch(url, "' + url_whitelist[i] + '")';
            if (i === url_whitelist.length - 1) {
		s += ') {\n';
            } else {
		s += ' ||\n            ';
            }
	}
 
	s += '        return "DIRECT";\n' +
            '    }\n';
 
	s += 'else if (';
    }
 
    for (i = 0; i < url_list.length; i++) {
        s += 'shExpMatch(url, "' + url_list[i] + '")';
        if (i === url_list.length - 1) {
            s += ') {\n';
        } else {
            s += ' ||\n            ';
        }
    }
 
    s += '        return "PROXY ' + proxy_server + '";\n' +
         '    }\n';
 
    s += '    return "DIRECT";\n' +
         '}';
 
    return s;
}

其实原理和我之前的那个alternative的方法基本一样,只是替换了一个正则表达式.因为去广告插件给的那个新的正则式不行,替换成老版本的正则式就可以了.
先不管了,如果再出问题,如果我这里更新不及时,可以直接给我发邮箱,按理说我已经把wordpress的评论邮件提醒开了…但是我只能收到自己评论的提醒,不知道为啥…xuhaohp<at>gmail.com
如果这么改了还是不行,请先使用去广告插件里的清除缓存功能,并重新安装去广告插件.又一次改了之后死活就是不行,这么弄了下就好了.

____________________我是分割线_________________________

现在可以用的youku去广告插件就只有Onens.Clean.Player和pullywood的这款插件了.但都是使用了pullywood的创意,使用代理去广告.但是让海外党非常不开心的就是这些插件会和unblock youku冲突, 二者不可兼得. 今天已经给unblock youku作者说过了. 只是他不知道pullywood已经考虑到了和其他代理软件兼容的问题, 可以不使用代理的API.现在搞清楚了,估计很快作者也会更新的.但作者似乎觉得帮助去广告插件解决crossdomain.xml的问题不大合适,详情

但现在我就只好自己下手了,而且就直接了当一点.

进入以下目录

Mac:
~/Library/Application Support/Google/Chrome/Default/Extensions/pdnfnkhpgegpcingjbfihlkjeighnddk/最新版本号/shared

Windows 7/8:
C:\Users\用户名\AppData\Local\Google\Chrome\User Data\Default\Extensions\pdnfnkhpgegpcingjbfihlkjeighnddk\最新版本号\shared

Windows XP:
C:\Documents and Settings\用户名\Local Settings\Application Data\Google\Chrome\User Data\Default\Extensions\pdnfnkhpgegpcingjbfihlkjeighnddk\最新版本号\shared

Linux:
~/.config/google-chrome/Default/Extensions/pdnfnkhpgegpcingjbfihlkjeighnddk/最新版本号/shared

将tools.js中的urls2pac修改成如下即可:

View Code JAVASCRIPTDownload tools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function urls2pac(url_whitelist, url_list, proxy_server) {
    "use strict";
    var s = 'function FindProxyForURL(url, host) {\n' +
            '    if (';
 
    var i;
 
    if (url_whitelist.length > 0) {
	for (i = 0; i < url_whitelist.length; i++) {
            s += 'shExpMatch(url, "' + url_whitelist[i] + '")';
            if (i === url_whitelist.length - 1) {
		s += ') {\n';
            } else {
		s += ' ||\n            ';
            }
	}
 
	s += '        return "DIRECT";\n' +
            '    }\n';
 
	s += 'else if (';
    }
 
    for (i = 0; i < url_list.length; i++) {
        s += 'shExpMatch(url, "' + url_list[i] + '")';
        if (i === url_list.length - 1) {
            s += ') {\n';
        } else {
            s += ' ||\n            ';
        }
    }
 
    s += '        return "PROXY ' + proxy_server + '";\n' +
         '    }\n';
    s += ' var regexStr = ^.*?://.*?(youku|qiyi|iqiyi|letv|sohu|ku6|ku6cdn).com/crossdomain.xml$;\n' +
         ' if(regexStr.test(url)){\n' +
         ' return "PROXY api.youku.com:80";\n' +
         ' }\n';
    s += '    return "DIRECT";\n' +
         '}';
 
    return s;
}

最后将去广告插件开到科学上网模式

P.S. 修改完成后请禁用unblock youku再重新启用.或者直接重启浏览器
为了以防这个function里的代码修改后无法直接替换.
下面给出具体的原理,其实就是在生成的PAC中添加了去广告插件的一条规则.具体的添加方法是添加下面这句,

View Code JAVASCRIPTDownload tools.js
1
2
3
4
    s += ' var regexStr = ^.*?://.*?(youku|qiyi|iqiyi|letv|sohu|ku6|ku6cdn).com/crossdomain.xml$;\n' +
         ' if(regexStr.test(url)){\n' +
         ' return "PROXY api.youku.com:80";\n' +
         ' }\n';

放到最后的

View Code JAVASCRIPTDownload tools.js
1
2
s += '    return "DIRECT";\n' +
         '}';

之前即可

额,按理说应该是没问题了,但是发现这种方法改完了之后我另外一个POST里的那个解决纽约州迅雷快传的方法不好使了.我想了半天也没想明白.但是胡乱折腾中发现了一个work的方法,其实逻辑上和上面的方法只是把我们去广告的规则优先级上提高了而已,和迅雷这个不挨着啊…实在是困了,懒得想了,起床还得赶个due,回头在更新好了.把另外一个work的方法贴一下:

View Code JAVASCRIPTDownload tools.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function urls2pac(url_whitelist, url_list, proxy_server) {
    "use strict";
    var s = 'function FindProxyForURL(url, host) {\n' +
            ' var regexStr = ^.*?://.*?(youku|qiyi|iqiyi|letv|sohu|ku6|ku6cdn).com/crossdomain.xml$;\n' +
            '    if (';
 
    var i;
    s += 'regexStr.test(url)){\n' +
         ' return "PROXY api.youku.com:80";\n' +
         ' }\n';
 
    s += 'else if (';
    if (url_whitelist.length > 0) {
	for (i = 0; i < url_whitelist.length; i++) {
            s += 'shExpMatch(url, "' + url_whitelist[i] + '")';
            if (i === url_whitelist.length - 1) {
		s += ') {\n';
            } else {
		s += ' ||\n            ';
            }
	}
 
	s += '        return "DIRECT";\n' +
            '    }\n';
 
	s += 'else if (';
    }
 
    for (i = 0; i < url_list.length; i++) {
        s += 'shExpMatch(url, "' + url_list[i] + '")';
        if (i === url_list.length - 1) {
            s += ') {\n';
        } else {
            s += ' ||\n            ';
        }
    }
 
    s += '        return "PROXY ' + proxy_server + '";\n' +
         '    }\n';
 
    s += '    return "DIRECT";\n' +
         '}';
 
    return s;
}

其实这两个应该对youku去广告都是没问题的,打完收工睡觉去

Share This: 

26 thoughts on “让unblock youku 和 pullywood 去广告插件和平相处

  1. aaa

    有個問題,我去看首頁的沒問題,去看動漫UNBLOCK YOUKU又不兼容了,是不是規則只包括首頁的?

    Reply
    1. highpower_admin Post author

      @aaa 和是不是主页没关系.这个方法本身就和在switchy sharp里面自定义了一个规则效果是一样的.只是unblock youku不提供这样的接口,我是直接修改了源码加了这样一个规则而已.

      Reply
  2. Pingback: 又是unblock youku, 这次是迅雷 | High Power's

        1. highpower_admin Post author

          @可乐玩 我没发现有啥差别啊,只是加了一个白名单而已.原来的方法,该怎么改就怎么改

          Reply
          1. 可乐玩

            @highpower_admin Post author 小白一个,完全不懂,直接拷你这个代码代替原来的urls2pac function不行啊

  3. highpower_admin Post author

    在最后的
    s += ‘ return “DIRECT”;\n’ +
    ‘}’;

    return s;
    前面添加
    s += ‘ var regexStr = ^.*?://.*?(youku|qiyi|iqiyi|letv|sohu|ku6|ku6cdn).com/crossdomain.xml$;\n’ +
    ‘ if(regexStr.test(url)){\n’ +
    ‘ return “PROXY api.youku.com:80”;\n’ +
    ‘ }\n’;
    我稍等会更新一下文章里的代码

    Reply
    1. 可乐玩

      @highpower_admin Post author 看起来很复杂的扬子,我也没试,因为我装了个保护伞过滤软件,配合unblock youku就没有广告了,也就不折腾了。不过我这里今天刚更新的新版的unblock youku之后,进优酷就看不成了,其他网站貌似还没有什么影响,你那有问题吗?

      Reply
  4. Bin

    Unblock Youku 是又更新了么?
    我在 s += ‘ return “DIRECT”;\n’ + 之前添加你给出的代码之后,Unblock Youku 就失效了,删除后又恢复正常。

    这么测试的时候我已经禁用了 pullywood 去广告插件。

    Reply
    1. highpower_admin Post author

      @XC 第四行的等号到分号之间的部分就是正则表达式.现在的这个是能工作的…我就先不改了.你要是自己想改就改一下.就那一句

      Reply
  5. Bin

    看到unblock youku重写了,于是上来想汇报下,没想到你已经更新脚本了。太赞了!

    Reply
    1. highpower_admin Post author

      @Bin 哈哈,起来刚好看到.不过下个月女朋友来美国玩,更新就不一定这么及时了,但愿下个月没啥大更新…还是希望unblock youku的作者早点实现”支持自定义规则”的诺言.

      Reply
  6. Henry

    hello, 我剛剛看了一下 我的MAC裡面的tools.js是這樣的,那我要怎麼改呢? 還是直接copy and paste整個你的urls2pac function的code進去??
    謝謝哈

    function urls2pac(url_whitelist, url_list, proxy_server, proxy_protocol) {
    “use strict”;
    var http_map_str = gen_url_map(‘http’, url_whitelist, url_list);
    var https_map_str = gen_url_map(‘https’, url_whitelist, url_list);

    if (typeof proxy_protocol === ‘undefined’) {
    proxy_protocol = ‘PROXY’;
    }
    proxy_protocol = proxy_protocol.replace(/:/g,”);
    proxy_protocol = proxy_protocol.replace(/\//g,”);
    proxy_protocol = proxy_protocol.toUpperCase();
    if (proxy_protocol === ‘HTTP’) {
    proxy_protocol = ‘PROXY’;
    }

    var txt = [
    // “(function() {“,
    // “”,
    “var _http_map = ” + http_map_str + “;”,
    “var _https_map = ” + https_map_str + “;”,
    // “var _proxy_str = ‘PROXY ” + proxy_server + “‘;”,
    “var _proxy_str = ‘” + proxy_protocol + ” ” + proxy_server + “‘;”,
    “”,
    “function _check_regex_list(regex_list, str) {“,
    ” var i;”,
    ” for (i = 0; i < regex_list.length; i++)",
    " if (regex_list[i].test(str))",
    " return true;",
    " return false;",
    "}",
    "",
    "function _check_patterns(patterns, hostname, full_url, prot_len) {",
    " if (patterns.hasOwnProperty(hostname))",
    " if (_check_regex_list(patterns[hostname],",
    " full_url.slice(prot_len + hostname.length)))", // check only :port/path
    " return true;",
    " if (_check_regex_list(patterns.any,", // try our best to speed up the checking for non-proxied urls
    " full_url.slice(prot_len)))", // check hostname:port/path
    " return true;",
    " return false;",
    "}",
    "",
    "function _find_proxy(url_map, host, url, prot_len) {",
    " if (_check_patterns(url_map.white, host, url, prot_len))",
    " return 'DIRECT';",
    " if (_check_patterns(url_map.proxy, host, url, prot_len))",
    " return _proxy_str;",
    " return 'DIRECT';",
    "}",
    "",
    "function FindProxyForURL(url, host) {", // host doesn't contain port
    " var prot = url.slice(0, 6);",
    " if (prot === 'http:/')",
    " return _find_proxy(_http_map, host, url, 7);", // 'http://&#039;.length
    " else if (prot === 'https:')",
    " return _find_proxy(_https_map, host, url, 8);", // 'https://&#039;.length
    " return 'DIRECT';",
    "}",
    // "",
    // "window.FindProxyForURL = FindProxyForURL;",
    // "}());"
    ].join("\n") + "\n";

    // console.log('==================');
    // console.log(txt);
    // console.log('==================');

    return txt;
    }

    Reply
    1. KW

      @Henry

      function urls2pac(url_whitelist, url_list, proxy_server, proxy_protocol) {
      “use strict”;
      var http_map_str = gen_url_map(‘http’, url_whitelist, url_list);
      var https_map_str = gen_url_map(‘https’, url_whitelist, url_list);

      if (typeof proxy_protocol === ‘undefined’) {
      proxy_protocol = ‘PROXY’;
      }
      proxy_protocol = proxy_protocol.replace(/:/g,”);
      proxy_protocol = proxy_protocol.replace(/\//g,”);
      proxy_protocol = proxy_protocol.toUpperCase();
      if (proxy_protocol === ‘HTTP’) {
      proxy_protocol = ‘PROXY’;
      }

      var txt = [
      // “(function() {“,
      // “”,
      “var _http_map = ” + http_map_str + “;”,
      “var _https_map = ” + https_map_str + “;”,
      // “var _proxy_str = ‘PROXY ” + proxy_server + “‘;”,
      “var _proxy_str = ‘” + proxy_protocol + ” ” + proxy_server + “‘;”,
      “”,
      “function _check_regex_list(regex_list, str) {“,
      ” var i;”,
      ” for (i = 0; i < regex_list.length; i++)",
      " if (regex_list[i].test(str))",
      " return true;",
      " return false;",
      "}",
      "",
      "function _check_patterns(patterns, hostname, full_url, prot_len) {",
      " if (patterns.hasOwnProperty(hostname))",
      " if (_check_regex_list(patterns[hostname],",
      " full_url.slice(prot_len + hostname.length)))", // check only :port/path
      " return true;",
      " if (_check_regex_list(patterns.any,", // try our best to speed up the checking for non-proxied urls
      " full_url.slice(prot_len)))", // check hostname:port/path
      " return true;",
      " return false;",
      "}",
      "",
      "function _find_proxy(url_map, host, url, prot_len) {",
      " if (_check_patterns(url_map.white, host, url, prot_len))",
      " return 'DIRECT';",
      " if (_check_patterns(url_map.proxy, host, url, prot_len))",
      " return _proxy_str;",
      " return 'DIRECT';",
      "}",
      "",
      "function FindProxyForURL(url, host) {", // host doesn't contain port
      " var prot = url.slice(0, 6);",
      " if (/^.*?:\\/\\/.*?(youku|qiyi|iqiyi|letv|sohu|ku6|ku6cdn|pps)\\.(com|tv)\\/crossdomain\\.xml$/i.test(url))",
      " return 'PROXY api.youku.com:80';",
      " if (prot === 'http:/')",
      " return _find_proxy(_http_map, host, url, 7);", // 'http://&#039;.length
      " else if (prot === 'https:')",
      " return _find_proxy(_https_map, host, url, 8);", // 'https://&#039;.length
      " return 'DIRECT';",
      "}",
      // "",
      // "window.FindProxyForURL = FindProxyForURL;",
      // "}());"
      ].join("\n") + "\n";

      // console.log('==================');
      // console.log(txt);
      // console.log('==================');

      return txt;
      }

      这是最新的,我改的 实测可用
      chrome 40 + Yosemite
      可能有点慢 希望能帮到你

      Reply
    1. highpower_admin Post author

      @Albert @Albert 是因为这个目录是隐藏的…可以直接用Finder的跳转功能(快捷键cmd+shift+G)

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *