KatTrak

A Trakt system for integrating with Kickass Torrents.

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

  1. // ==UserScript==
  2. // @name KatTrak
  3. // @namespace PXgamer
  4. // @version 0.4
  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, run through the auth process here: https://pxgamer.github.io/PX-Scripts/KatTrak/
  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. var logged_in_valid = false;
  57. $.ajax({
  58. beforeSend: function (request)
  59. {
  60. request.setRequestHeader("Content-type", "application/json");
  61. request.setRequestHeader("trakt-api-key", "9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3");
  62. request.setRequestHeader("trakt-api-version", 2);
  63. request.setRequestHeader("Authorization", "Bearer "+auth_code+"");
  64. },
  65. type: "GET",
  66. async: false,
  67. url: "https://api-v2launch.trakt.tv/sync/last_activities",
  68. success: function (data) {
  69. if (data.all !== '') {
  70. logged_in_valid = true;
  71. }
  72. },
  73. returnData: "json"
  74. });
  75. if (auth_code !== '' && logged_in_valid) {
  76. $('.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>');
  77. $('.unauthKt').replaceWith('<button class="btn btn-lg btn-danger unauthKt" type="button">Unauthorise KatTrak</button>');
  78. $('.unauthKt').on('click', function() {
  79. GM_setValue('katTrakAuth', '');
  80. location.reload();
  81. });
  82. }
  83. else if (auth_code !== '') {
  84. $('.checkup-box').html('<table style="margin-left: 20%;"><tr style="text-align: left;"><td>Status:</td><td style="padding: 15px"></td><td>Failed: Invalid Auth Code</td></tr><tr style="text-align: left;"><td>Auth Code:</td><td style="padding: 15px"></td><td>' + auth_code + '</td></tr></table>');
  85. $('.unauthKt').replaceWith('<button class="btn btn-lg btn-primary unauthKt" type="button">Re-Authorise KatTrak</button>');
  86. $('.unauthKt').on('click', function() {
  87. GM_setValue('katTrakAuth', '');
  88. location.href = 'https://trakt.tv/oauth/authorize?client_id=9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3&redirect_uri=https%3A%2F%2Fpxstat.us%2Ftrakt%2F&response_type=code';
  89. });
  90. }
  91. else {
  92. $('.checkup-box').html('<table style="margin-left: 20%;"><tr style="text-align: left;"><td>Status:</td><td style="padding: 15px"></td><td>Failed: No Code Provided</td></tr><tr style="text-align: left;"><td>Auth Code:</td><td style="padding: 15px"></td><td>' + auth_code + '</td></tr></table>');
  93. $('.unauthKt').replaceWith('<button class="btn btn-lg btn-primary unauthKt" type="button">Authorise KatTrak</button>');
  94. $('.unauthKt').on('click', function() {
  95. GM_setValue('katTrakAuth', '');
  96. location.href = 'https://trakt.tv/oauth/authorize?client_id=9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3&redirect_uri=https%3A%2F%2Fpxstat.us%2Ftrakt%2F&response_type=code';
  97. });
  98. }
  99. }
  100. if (getURL.indexOf('kat.cr') > -1 && getURL.indexOf('.html') > -1) {
  101. var category = $('span[id^="cat_"] strong a[href]:first').text();
  102. $('a.kaGiantButton[href^="/torrents/"][data-download]').attr('target', '_blank');
  103. var imdbId = "tt" + $('a.plain[href^="http://www.imdb.com/title/tt"]').text();
  104. if (category == 'Movies') {
  105. sendData = {
  106. "movies": [
  107. {
  108. "ids": {
  109. "imdb": imdbId
  110. }
  111. }
  112. ]
  113. };
  114. }
  115. else if (category == 'TV') {
  116. sendData = {
  117. "shows": [
  118. {
  119. "ids": {
  120. "imdb": imdbId
  121. }
  122. }
  123. ]
  124. };
  125. }
  126.  
  127. $('a.kaGiantButton[href^="/torrents/"][data-download]').on('click', function() {
  128. $.ajax({
  129. beforeSend: function (request)
  130. {
  131. request.setRequestHeader("Content-type", "application/json");
  132. request.setRequestHeader("trakt-api-key", "9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3");
  133. request.setRequestHeader("trakt-api-version", 2);
  134. request.setRequestHeader("Authorization", "Bearer "+auth_code+"");
  135. },
  136. type: "POST",
  137. url: "https://api-v2launch.trakt.tv/sync/collection",
  138. data: JSON.stringify(sendData),
  139. success: function (data) {
  140. console.log(data);
  141. },
  142. returnData: "json"
  143. });
  144. });
  145. $('a.kaGiantButton[href^="magnet:?xt"][data-nop]').on('click', function() {
  146. $.ajax({
  147. beforeSend: function (request)
  148. {
  149. request.setRequestHeader("Content-type", "application/json");
  150. request.setRequestHeader("trakt-api-key", "9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3");
  151. request.setRequestHeader("trakt-api-version", 2);
  152. request.setRequestHeader("Authorization", "Bearer "+auth_code+"");
  153. },
  154. type: "POST",
  155. url: "https://api-v2launch.trakt.tv/sync/collection",
  156. data: JSON.stringify(sendData),
  157. success: function (data) {
  158. console.log(data);
  159. },
  160. returnData: "json"
  161. });
  162. });
  163. }
  164. })();