KatTrak

A Trakt system for integrating with Kickass Torrents.

当前为 2016-06-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name KatTrak
  3. // @namespace PXgamer
  4. // @version 0.2
  5. // @description A Trakt system for integrating with Kickass Torrents.
  6. // @author PXgamer
  7. // @include *kat.cr/*
  8. // @include *pxstat.us/trakt*
  9. // @include *pxgamer.github.io/PX-Scripts/KatTrak/
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // ==/UserScript==
  13. /*jshint multistr: true */
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // NOTE: To set this up, first go to Trakt.tv here: https://trakt.tv/oauth/authorize?client_id=9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3&redirect_uri=https%3A%2F%2Fpxstat.us%2Ftrakt%2F&response_type=code
  19. // No, I'm not going to steal your data or anything. This is just a project to add what you download to your Trakt.tv Collection.
  20.  
  21. var auth_code = GM_getValue('katTrakAuth', '');
  22.  
  23. // Config Params
  24. // ---------------------------
  25. //GM_setValue('katTrakAuth', ''); location.reload(); // Uncomment to reset the auth_code.
  26.  
  27.  
  28. // DO NOT EDIT BELOW THIS LINE
  29. // ---------------------------
  30.  
  31. function getQV(variable)
  32. {
  33. var query = window.location.search.substring(1);
  34. var vars = query.split("&");
  35. for (var i=0;i<vars.length;i++) {
  36. var pair = vars[i].split("=");
  37. if(pair[0] == variable){return pair[1];}
  38. }
  39. return(false);
  40. }
  41.  
  42. var getURL = location.href.toLowerCase();
  43. var sendData;
  44.  
  45. if (getURL.indexOf('pxstat.us/trakt/?kattrakauth') > -1) {
  46. GM_setValue('katTrakAuth', getQV('katTrakAuth'));
  47.  
  48. if (getQV('ret') == 'ktInstall') {
  49. location.href = 'https://pxgamer.github.io/PX-Scripts/KatTrak/#checkup';
  50. }
  51. else {
  52. location.href = 'https://kat.cr/';
  53. }
  54. }
  55. if (getURL.indexOf('pxgamer.github.io') > -1) {
  56. if (auth_code !== '') {
  57. $('.checkup-box').html('<table style="margin-left: 20%;"><tr style="text-align: left;"><td>Status:</td><td style="padding: 15px"></td><td>Success</td></tr><tr style="text-align: left;"><td>Auth Code:</td><td style="padding: 15px"></td><td>' + auth_code + '</td></tr></table>');
  58. }
  59. else {
  60. $('.checkup-box').html('<table style="margin-left: 20%;"><tr style="text-align: left;"><td>Status:</td><td style="padding: 15px"></td><td>Failed</td></tr><tr style="text-align: left;"><td>Auth Code:</td><td style="padding: 15px"></td><td>' + auth_code + '</td></tr></table>');
  61. }
  62. }
  63. if (getURL.indexOf('kat.cr') > -1 && getURL.indexOf('.html') > -1) {
  64. var category = $('span[id^="cat_"] strong a[href]:first').text();
  65. $('a.kaGiantButton[href^="/torrents/"][data-download]').attr('target', '_blank');
  66. var imdbId = "tt" + $('a.plain[href^="http://www.imdb.com/title/tt"]').text();
  67. if (category == 'Movies') {
  68. sendData = {
  69. "movies": [
  70. {
  71. "ids": {
  72. "imdb": imdbId
  73. }
  74. }
  75. ]
  76. };
  77. }
  78. else if (category == 'TV') {
  79. sendData = {
  80. "shows": [
  81. {
  82. "ids": {
  83. "imdb": imdbId
  84. }
  85. }
  86. ]
  87. };
  88. }
  89.  
  90. $('a.kaGiantButton[href^="/torrents/"][data-download]').on('click', function() {
  91. $.ajax({
  92. beforeSend: function (request)
  93. {
  94. request.setRequestHeader("Content-type", "application/json");
  95. request.setRequestHeader("trakt-api-key", "9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3");
  96. request.setRequestHeader("trakt-api-version", 2);
  97. request.setRequestHeader("Authorization", "Bearer "+auth_code+"");
  98. },
  99. type: "POST",
  100. url: "https://api-v2launch.trakt.tv/sync/collection",
  101. data: JSON.stringify(sendData),
  102. success: function (data) {
  103. console.log(data);
  104. },
  105. returnData: "json"
  106. });
  107. });
  108. $('a.kaGiantButton[href^="magnet:?xt"][data-nop]').on('click', function() {
  109. $.ajax({
  110. beforeSend: function (request)
  111. {
  112. request.setRequestHeader("Content-type", "application/json");
  113. request.setRequestHeader("trakt-api-key", "9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3");
  114. request.setRequestHeader("trakt-api-version", 2);
  115. request.setRequestHeader("Authorization", "Bearer "+auth_code+"");
  116. },
  117. type: "POST",
  118. url: "https://api-v2launch.trakt.tv/sync/collection",
  119. data: JSON.stringify(sendData),
  120. success: function (data) {
  121. console.log(data);
  122. },
  123. returnData: "json"
  124. });
  125. });
  126. }
  127. })();