Swyter Tweaks for Seriespepito

Puts direct links in the seriespepito.com site.

  1. // ==UserScript==
  2. // @name Swyter Tweaks for Seriespepito
  3. // @description Puts direct links in the seriespepito.com site.
  4. // @match http://*.seriespepito.com/*
  5. // @match http://*.peliculaspepito.com/*
  6. // This one is for the cross-site XHR requests without CORS:
  7. // @match http://*.enlacespepito.com/*
  8. // @grant GM_xmlhttpRequest
  9. // @version 2014.04.06
  10. // @author Swyter
  11. // @namespace https://greasyfork.org/users/4813
  12. // ==/UserScript==
  13.  
  14. /*
  15. * DOMParser HTML extension
  16. * 2012-09-04
  17. *
  18. * By Eli Grey, http://eligrey.com
  19. * Public domain.
  20. * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
  21. */
  22.  
  23. /*! @source https://gist.github.com/1129031 */
  24. /*global document, DOMParser*/
  25.  
  26. (function(DOMParser) {
  27. "use strict";
  28.  
  29. var
  30. DOMParser_proto = DOMParser.prototype
  31. , real_parseFromString = DOMParser_proto.parseFromString
  32. ;
  33.  
  34. // Firefox/Opera/IE throw errors on unsupported types
  35. try {
  36. // WebKit returns null on unsupported types
  37. if ((new DOMParser).parseFromString("", "text/html")) {
  38. // text/html parsing is natively supported
  39. return;
  40. }
  41. } catch (ex) {}
  42.  
  43. DOMParser_proto.parseFromString = function(markup, type) {
  44. if (/^\s*text\/html\s*(?:;|$)/i.test(type)) {
  45. var
  46. doc = document.implementation.createHTMLDocument("")
  47. ;
  48. if (markup.toLowerCase().indexOf('<!doctype') > -1) {
  49. doc.documentElement.innerHTML = markup;
  50. }
  51. else {
  52. doc.body.innerHTML = markup;
  53. }
  54. return doc;
  55. } else {
  56. return real_parseFromString.apply(this, arguments);
  57. }
  58. };
  59. }(DOMParser));
  60.  
  61.  
  62. if (document.domain.match(/enlacespepito.com$/))
  63. {
  64. throw "stop it, you!";
  65. }
  66.  
  67. document.body.addEventListener("click", function(e)
  68. {
  69. if( (e.target.classList.contains("enlace_link")
  70. || e.target.classList.contains("btn_link"))
  71. && !e.target.classList.contains("direct"))
  72. {
  73. e.preventDefault();
  74. GM_xmlhttpRequest({
  75. method: "GET",
  76. url: e.target.href,
  77. onload: function(o)
  78. {
  79. o.responseXML = new DOMParser().parseFromString(o.responseText, "text/html");
  80. e.target.href = o.responseXML.querySelector(".enlace_link").href;
  81. e.target.classList.add("direct");
  82. window.open(e.target.href);
  83. }
  84. });
  85. }
  86. });