TPB

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

目前为 2015-06-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @version 1.0.1
  3. // @name TPB
  4. // @description Add YouTube link and IMDb rating to top/207|all
  5. // @namespace https://greasyfork.org/users/3159
  6. // @include https://thepiratebay.*/top/207
  7. // @include https://thepiratebay.*/top/all
  8. // ==/UserScript==
  9. style = document.createElement('style');
  10. 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}";
  11. document.head.appendChild(style);
  12.  
  13. function filter(x) {
  14. x = x.replace(/\./g, ' '); //dots to spaces
  15. x = x.replace(/\(/g, ''); // ( to nothing
  16. y = x.replace(/(S[0-9].*?)\ .*/, '$1'); //remove after season
  17. z = x.match(/18|19|20[0-9]{2}/); // year
  18. y != x ? x = y : (y = x.replace(/(.*?.)((18|19|20)[0-9]{2}).*/, '$1$2'), x = x.split(' ' + z)[0]); // if no season then year
  19. results = [y, x, z];
  20. return results;
  21. }
  22.  
  23. function iIMDb(ir, n, ii) {
  24. if (ir) {
  25. l = document.getElementsByClassName('imdb')[n - 1];
  26. l.href = "http://imdb.com/title/" + ii + "/";
  27. l.children[0].innerHTML = ir;
  28. }
  29. }
  30.  
  31. list = document.getElementsByTagName('tr');
  32. for (i = 1; i < list.length; i++) {
  33. q = list[i].children[1];
  34. //YouTube
  35. yt = document.createElement('a');
  36. yt.className = "youtube";
  37. yt.innerHTML = "<em>Yt</em> ";
  38. q.appendChild(yt);
  39. bg = document.createElement("div");
  40. bg.id = "bg";
  41. bg.onclick = function () {
  42. bg.style.display = "none";
  43. bg.innerHTML = "";
  44. };
  45. document.body.appendChild(bg);
  46. 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
  47. eval("yt.onclick=function(){bg.style.display='block';bg.innerHTML='<iframe src=//youtube.com/embed/?listType=search&list=" + escape(f1) + "&autohide=1></iframe>'};");
  48. //IMDb
  49. 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
  50. 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
  51. imdb = document.createElement('a');
  52. imdb.className = "imdb";
  53. imdb.innerHTML = "<code></code>";
  54. q.appendChild(imdb);
  55. eval("var r" + i + "= new XMLHttpRequest;r" + i + ".open('GET', 'http://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();");
  56. }