TPB

Add YouTube link to all and IMDb rating to search|top/207|top/201|top/all

  1. // ==UserScript==
  2. // @version 1.0.2
  3. // @name TPB
  4. // @description Add YouTube link to all and IMDb rating to search|top/207|top/201|top/all
  5. // @namespace https://greasyfork.org/users/3159
  6. // @include https://thepiratebay.*/*
  7. // ==/UserScript==
  8. style = document.createElement('style');
  9. style.innerText = ".youtube{color:#b2491a;cursor:pointer}.imdb{color:grey}#bg{background:rgba(0, 0, 0,.8);position:fixed;top:0;left:0;z-index:9001;width:100%;height:100%;display:none}iframe{border:0;width:640px;height:390px;max-width:90%;max-height:90%;margin:auto;position:absolute;top:0;left:0;bottom:0;right:0}";
  10. document.head.appendChild(style);
  11.  
  12. function filter(x) {
  13. x = x.replace(/\./g, ' '); //dots to spaces
  14. x = x.replace(/\(/g, ''); // ( to nothing
  15. y = x.replace(/(S[0-9].*?)\ .*/, '$1'); //remove after season
  16. z = x.match(/18|19|20[0-9]{2}/); // year
  17. if (y != x){
  18. x = y;
  19. } else {
  20. y = x.replace(/(.*?.)((18|19|20)[0-9]{2}).*/, '$1$2');
  21. x = x.split(' ' + z)[0];
  22. } // if no season then year
  23. results = [y, x, z];
  24. return results;
  25. }
  26.  
  27. function iIMDb(ir, n, ii) {
  28. if (ir) {
  29. l = document.getElementsByClassName('imdb')[n - 1];
  30. l.href = "http://imdb.com/title/" + ii + "/";
  31. l.children[0].innerHTML = ir;
  32. }
  33. }
  34.  
  35. list = document.getElementsByTagName('tr');
  36. for (i = 1; i < list.length; i++) {
  37. q = list[i].children[1];
  38. //YouTube
  39. yt = document.createElement('a');
  40. yt.className = "youtube";
  41. yt.innerHTML = "<em>Yt</em> ";
  42. q.appendChild(yt);
  43. bg = document.createElement("div");
  44. bg.id = "bg";
  45. bg.onclick = function () {
  46. bg.style.display = "none";
  47. bg.innerHTML = "";
  48. };
  49. document.body.appendChild(bg);
  50. f1 = filter(list[i].children[1].children[0].className ? list[i].children[1].children[0].children[0].innerHTML : list[i].children[1].children[0].innerHTML[0]); // name
  51. eval("yt.onclick=function(){bg.style.display='block';bg.innerHTML='<iframe src=//youtube.com/embed/?listType=search&list=" + escape(f1) + "&autohide=1></iframe>'};");
  52. //IMDb
  53. if( document.location.pathname.match(/search|top\/207|top\/201|top\/all/) ){
  54. f2 = filter(list[i].children[1].children[0].className ? list[i].children[1].children[0].children[0].innerHTML : list[i].children[1].children[0].innerHTML[0])[1]; // id
  55. f3 = filter(list[i].children[1].children[0].className ? list[i].children[1].children[0].children[0].innerHTML : list[i].children[1].children[0].innerHTML[0])[2]; // year
  56. imdb = document.createElement('a');
  57. imdb.className = "imdb";
  58. imdb.innerHTML = "<code></code>";
  59. q.appendChild(imdb);
  60. eval("var r" + i + "= new XMLHttpRequest;r" + i + ".open('GET', 'https://www.omdbapi.com/?t='+f2+'&y='+f3, true);r" + i + ".onreadystatechange = function () {var num" + i + "=JSON.parse(r" + i + ".responseText).imdbRating;var ii" + i + "=JSON.parse(r" + i + ".responseText).imdbID;iIMDb(num" + i + "," + i + ",ii" + i + ");};r" + i + ".send();");
  61. }
  62. }