优酷视频去广告

Remove ADs

  1. // ==UserScript==
  2. // @name 优酷视频去广告
  3. // @namespace https://greasyfork.org/users/91873
  4. // @version 1.0.0.0
  5. // @description Remove ADs
  6. // @match https://v.youku.com/v_show/*
  7. // @author wujixian
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. //破解清晰度
  14. window.onload = function () {
  15. var qpo = 0;
  16. $(".youku-film-player").children("video").bind('play', function () {
  17. if (qpo === 0) {
  18. $(".quality-dashboard").children("div").not("div[data-val='download']").eq(1).click();
  19. qpo = 1;
  20. };
  21. });
  22. $(".youku-layer-wuliao").hide();
  23. $(".js-hdr").children("span.youku_vip_pay_btn").removeClass("youku_vip_pay_btn disable");
  24. $(".quality-dashboard").children("div.youku_vip_pay_btn").removeClass("youku_vip_pay_btn disable");
  25. $(".quality-dashboard").children("div.login-canuse").removeClass("login-canuse");
  26. }
  27. //去广告
  28. const rules = [{
  29. //去倒计时
  30. url: /^(https:)?\/\/acs\.youku\.com\/h5\/mtop\.youku\.play\.ups\.appinfo\.get.+callback=mtopjsonp.+/, async callback(url) {
  31. const val = await (await fetch(url, { credentials: 'include' })).text();
  32. const cb = url.match(/mtopjsonp\d*/);
  33. if (!cb) return;
  34. const index = val.indexOf(cb[0]);
  35. if (index < 2) {
  36. const json = JSON.parse(val.slice(index + cb[0].length + 1, -1));
  37. delete json.data.data.ad;
  38. createScript(`${cb[0]}(${JSON.stringify(json)})`);
  39. }
  40. }
  41. }
  42. ];
  43. const createScript = (text) => {
  44. const script = document.createElement('script');
  45. script.textContent = text;
  46. document.head.appendChild(script);
  47. script.remove();
  48. }
  49. Object.defineProperty(HTMLScriptElement.prototype, '_original', Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src'));
  50. Object.defineProperty(HTMLScriptElement.prototype, 'src', {
  51. get() {return this._original;},
  52. set(val) {
  53. const rule = rules.find(r => r.url.test(val));
  54. if (rule) {rule.callback(val);} else {this._original = val;}
  55. }
  56. });
  57. })();