KatTrak

A Trakt system for integrating with Kickass Torrents.

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

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