KatTrak

A Trakt system for integrating with Kickass Torrents.

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

  1. // ==UserScript==
  2. // @name KatTrak
  3. // @namespace PXgamer
  4. // @version 0.3
  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. 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. // Unauth code
  63. $('.unauthKt').on('click', function() {
  64. GM_setValue('katTrakAuth', '');
  65. location.reload();
  66. });
  67. }
  68. if (getURL.indexOf('kat.cr') > -1 && getURL.indexOf('.html') > -1) {
  69. var category = $('span[id^="cat_"] strong a[href]:first').text();
  70. $('a.kaGiantButton[href^="/torrents/"][data-download]').attr('target', '_blank');
  71. var imdbId = "tt" + $('a.plain[href^="http://www.imdb.com/title/tt"]').text();
  72. if (category == 'Movies') {
  73. sendData = {
  74. "movies": [
  75. {
  76. "ids": {
  77. "imdb": imdbId
  78. }
  79. }
  80. ]
  81. };
  82. }
  83. else if (category == 'TV') {
  84. sendData = {
  85. "shows": [
  86. {
  87. "ids": {
  88. "imdb": imdbId
  89. }
  90. }
  91. ]
  92. };
  93. }
  94.  
  95. $('a.kaGiantButton[href^="/torrents/"][data-download]').on('click', function() {
  96. $.ajax({
  97. beforeSend: function (request)
  98. {
  99. request.setRequestHeader("Content-type", "application/json");
  100. request.setRequestHeader("trakt-api-key", "9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3");
  101. request.setRequestHeader("trakt-api-version", 2);
  102. request.setRequestHeader("Authorization", "Bearer "+auth_code+"");
  103. },
  104. type: "POST",
  105. url: "https://api-v2launch.trakt.tv/sync/collection",
  106. data: JSON.stringify(sendData),
  107. success: function (data) {
  108. console.log(data);
  109. },
  110. returnData: "json"
  111. });
  112. });
  113. $('a.kaGiantButton[href^="magnet:?xt"][data-nop]').on('click', function() {
  114. $.ajax({
  115. beforeSend: function (request)
  116. {
  117. request.setRequestHeader("Content-type", "application/json");
  118. request.setRequestHeader("trakt-api-key", "9efcadc5be0011a406fa0819192bd3aef0b3b2d9fa6ba90f3ffd3907138195d3");
  119. request.setRequestHeader("trakt-api-version", 2);
  120. request.setRequestHeader("Authorization", "Bearer "+auth_code+"");
  121. },
  122. type: "POST",
  123. url: "https://api-v2launch.trakt.tv/sync/collection",
  124. data: JSON.stringify(sendData),
  125. success: function (data) {
  126. console.log(data);
  127. },
  128. returnData: "json"
  129. });
  130. });
  131. }
  132. })();