kinozal.tv: remove external scripts

Remove external scripts (ads/tracking) on kinozal.tv

  1. // ==UserScript==
  2. // @name kinozal.tv: remove external scripts
  3. // @description Remove external scripts (ads/tracking) on kinozal.tv
  4. // @version 2.0
  5. // @author wOxxOm
  6. // @namespace https://greasyfork.org/users/2159-woxxom
  7. // @license MIT License
  8. // @match http://kinozal.tv/*
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. stop();
  13.  
  14. (function overwrite(link) {
  15. var xhr = new XMLHttpRequest();
  16. xhr.open('GET', link.href);
  17. xhr.onload = () => {
  18. var html = xhr.responseText
  19. .replace(/<script\b[\s\S]*?<\/script>/g, s => {
  20. if (s.includes('fromCharCode') ||
  21. s.includes('iframe') ||
  22. s.includes('document.write') ||
  23. s.includes('document.createElement("script")') ||
  24. s.includes("document.createElement('script')") ||
  25. /^[^>]+?src=['"][^'"/]*\/\//.test(s)) {
  26. // console.debug(GM_info.script.name + ': ' + s);
  27. return '';
  28. } else {
  29. return s;
  30. }
  31. })
  32. .replace(/<(object|iframe)\s[\s\S]*?<\/\1>/g, ''); // strip swfs
  33. document.open();
  34. document.write(html);
  35. document.close();
  36.  
  37. document.querySelector('[id*="ScriptRoot"]').parentNode.remove();
  38.  
  39. if (link.nodeName)
  40. history.pushState(0, document.title, link.href);
  41.  
  42. var prevUrl = location.href;
  43. window.addEventListener('popstate', e => {
  44. if (!prevUrl.includes('#') && !location.href.includes('#'))
  45. overwrite(location);
  46. });
  47.  
  48. window.addEventListener('click', e => {
  49. var a = e.target.closest('a');
  50. if (a && !a.onclick && a.hostname == location.hostname) {
  51. e.preventDefault();
  52. overwrite(a);
  53. }
  54. });
  55. };
  56. xhr.send();
  57. })(location);