KAT Headers Unified

Unifies and improves the headers of both the community and torrent sections of the site. (and makes community pages full width)

目前為 2018-08-24 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name KAT Headers Unified
  3. // @namespace NotNeo
  4. // @version 0.7
  5. // @description Unifies and improves the headers of both the community and torrent sections of the site. (and makes community pages full width)
  6. // @author NotNeo
  7. // @match https://katcr.co/*
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  9. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM.setValue
  13. // @grant GM.getValue
  14. // ==/UserScript==
  15.  
  16. var headerShrunkByDefault = "remember"; //yes,no,remember
  17. var PMCheckInterval = 90000; //in ms
  18.  
  19. var url = window.location.href;
  20. var sessionId;
  21. var userName;
  22. var numOfPM;
  23.  
  24. if(url.indexOf("/community") > -1) {
  25. //style
  26. if(true) {
  27. addGlobalStyle(`
  28. #wrapper {
  29. max-width: 100% !important;
  30. }
  31.  
  32. #header {
  33. padding-left: 5px;
  34. position: fixed;
  35. width: 100%;
  36. z-index: 100;
  37. }
  38.  
  39. #content_section {
  40. padding-top: 65px;
  41. }
  42.  
  43. #header div.frame {
  44. padding-right: 5px;
  45. }
  46.  
  47. #top_section > .forumtitle {
  48. margin-right: -55px;
  49. }
  50.  
  51. #top_section {
  52. min-height: 0px;
  53. }
  54.  
  55. #header > .frame > div:last-of-type, #header > .frame > br.clear {
  56. display: none;
  57. }
  58.  
  59. #menu_nav > li > ul {
  60. position: fixed;
  61. border: solid #333 2px;
  62. width: -moz-min-content;
  63. width: -webkit-min-content;
  64. }
  65.  
  66. #search_form {
  67. position: relative;
  68. }
  69.  
  70. #search_form .input_text {
  71. max-width: calc(100% - 1350px) !important;
  72. min-width: 200px;
  73. }
  74.  
  75. .valueBubble {
  76. display: inline-block;
  77. height: 7px;
  78. width: 7px;
  79. margin-bottom: 7px;
  80. margin-left: -10px;
  81. margin-right: -2px;
  82. font-family: sans-serif;
  83. color: #fc7208;
  84. background: #fc7208;
  85. border: 2px solid #594c2d;
  86. border-radius: 50%;
  87. transition: .1s all;
  88. }
  89.  
  90. .valueBubble span {
  91. position: absolute;
  92. margin-top: -22px;
  93. margin-left: 10px;
  94. font-size: 10px;
  95. }
  96.  
  97. #search-new-button {
  98. background: 0 0;
  99. color: #5f5f5f;
  100. box-shadow: none;
  101. display: inline-block;
  102. border: none;
  103. position: absolute;
  104. top: 0px;
  105. right: 12px;
  106. cursor: pointer;
  107. padding: 0 !important;
  108. }
  109.  
  110. #search-new-adv-button {
  111. background: 0 0;
  112. color: #5f5f5f !important;
  113. box-shadow: none;
  114. display: inline-block;
  115. border: none;
  116. position: absolute;
  117. top: 0px;
  118. right: 33px;
  119. cursor: pointer;
  120. padding: 0 !important;
  121. }
  122.  
  123. .columns-2 {
  124. -webkit-column-count: 2;
  125. -moz-column-count: 2;
  126. column-count: 2;
  127. -webkit-column-gap: 0;
  128. -moz-column-gap: 0;
  129. column-gap: 0;
  130. }
  131.  
  132. `);
  133. }
  134.  
  135. function addGlobalStyle(css) {
  136. var head, style;
  137. head = document.getElementsByTagName('head')[0];
  138. if (!head) { return; }
  139. style = document.createElement('style');
  140. style.type = 'text/css';
  141. style.innerHTML = css;
  142. head.appendChild(style);
  143. }
  144.  
  145. function CalcContentPad() {
  146. if($("#upshrink").attr("src").split("images/")[1] == "upshrink.png") {
  147. $("#content_section").prop("style", "padding-top: 165px;");
  148. }
  149. else {
  150. $("#content_section").prop("style", "padding-top: 65px;");
  151. }
  152. }
  153.  
  154. $("#siteslogan").detach().appendTo('#upper_section');
  155. $("#main_menu").parent().detach().appendTo("#top_section");
  156.  
  157. if(headerShrunkByDefault != "remember") { //if header shrink is "remember", let the site handle it...
  158. var imgSrc = $("#upshrink").attr("src").split("images/")[1]; //...else get current state
  159. if((headerShrunkByDefault == "yes" && imgSrc == "upshrink.png") || (headerShrunkByDefault == "no" && imgSrc == "upshrink2.png")) { //...and if the state is wrong...
  160. $("#upshrink").click(); //...change it
  161. }
  162. }
  163.  
  164. //remove search tab and add it to main search ba as advanced
  165. $("#button_search").remove();
  166. $("#search_form .button_submit").remove();
  167. $("#search_form .input_text").after('<a id="search-new-adv-button" title="Advanced Search" href="https://katcr.co/show/community/index.php?action=search"><i class="ka ka-settings"></i></a>');
  168. $("#search_form .input_text").after('<button name="submit" id="search-new-button" title="Search" type="submit"><i class="ka ka-search"></i></button>');
  169.  
  170.  
  171. //GetUserName
  172. userName = $(".greeting > span").text();
  173.  
  174. //Adding/removing/moving header parts
  175. $("#button_sitemap").remove();
  176. $("#button_help").remove();
  177. $("#gallery_torrents").remove();
  178. $("#menu_nav").prepend(`
  179. <li>
  180. <a class="firstlevel" onclick="return false;" href="#"><i class="ka ka-plus"></i> Other</a>
  181. <ul>
  182. <li class="topMsg">
  183. <a href="https://katcr.co/show/community/index.php?action=help">
  184. <i class="ka ka-idea"></i> Help</a>
  185. </li>
  186. <li class="topMsg">
  187. <a href="https://katcr.co/show/community/index.php?action=sitemap">
  188. <i class="ka ka-list"></i> Sitemap</a>
  189. </li>
  190. <li class="topMsg">
  191. <a href="https://katcr.co/gallery/movies/page/">
  192. <i class="ka ka-camera"></i> Gallery</a>
  193. </li>
  194. </ul>
  195. </li>
  196. `);
  197.  
  198. numOfPM = $("#button_pm span.firstlevel strong").text() || 0;//get number of messages
  199. $("#button_pm").remove();
  200. $("#menu_nav").append(`
  201. <li id="button_pm">
  202. <a class="firstlevel" href="https://katcr.co/show/community/index.php?action=pm">
  203. <i class="ka ka-message"></i> <span class="valueBubble"><span>`+numOfPM+`</span></span> Messages
  204. </a>
  205. <ul class="navigation__sub_items">
  206. <li class="navigation__item"><a href="https://katcr.co/show/community/index.php?action=pm;sa=send" class="navigation__link"><i class="ka ka-edit"></i> New message</a></li>
  207. <li class="navigation__item"><a href="https://katcr.co/show/community/index.php?action=pm" class="navigation__link"><i class="ka ka-message"></i> Inbox</a></li>
  208. </ul>
  209. </li>
  210. `);
  211.  
  212. //Get session id for log out
  213. sessionId = $("#button_logout a").prop("href").split(";")[1];
  214.  
  215. $("#button_logout").remove();
  216. $("#button_profile").remove();
  217. $("#menu_nav").append(`
  218. <li id="button_profile">
  219. <a class="firstlevel" href="https://katcr.co/user/`+userName+`/profile/"><i class="ka ka-user"></i> `+userName+`</a>
  220. <ul class="navigation__sub_items" style="right: 45px;">
  221. <li class="navigation__item"><a href="https://katcr.co/user/`+userName+`/profile/" class="navigation__link"><i class="ka ka-torrent"></i> Torrent Profile</a></li>
  222. <li class="navigation__item"><a href="https://katcr.co/show/community/index.php?action=profile" class="navigation__link"><i class="ka ka-community"></i> Forum Profile</a></li>
  223. <li class="navigation__item"><a href="https://katcr.co/show/community/index.php?action=profile;area=forumprofile" class="navigation__link"><i class="ka ka-edit"></i> Edit Profile</a></li>
  224. <li class="navigation__item"><a href="https://katcr.co/show/community/index.php?action=logout;`+sessionId+`" class="navigation__link">Log out</a></li>
  225. </ul>
  226. </li>
  227. `);
  228.  
  229. $("#button_torrents ul").remove();
  230. $("#button_torrents .firstlevel").prop("href", "https://katcr.co/new/full/");
  231. $("#button_torrents").append(`
  232. <ul class="navigation__sub_items columns-2">
  233. <li class="navigation__item"><a class="navigation__link" href="/category/latest/page/"><i class="ka ka-torrent"></i> Latest</a></li>
  234. <li class="navigation__item"><a class="navigation__link" href="/category/movies/page/"><i class="ka ka-film"></i> Movies</a></li>
  235. <li class="navigation__item"><a class="navigation__link" href="/category/tv/page/"><i class="ka ka-film"></i> TV</a></li>
  236. <li class="navigation__item"><a class="navigation__link" href="/category/music/page/"><i class="ka ka-music-note"></i> Music</a></li>
  237. <li class="navigation__item"><a class="navigation__link" href="/category/games/page/"><i class="ka ka-tags"></i> Games</a></li>
  238. <li class="navigation__item"><a class="navigation__link" href="/category/books/page/"><i class="ka ka-bookmark"></i> Books</a></li>
  239. <li class="navigation__item"><a class="navigation__link" href="/new/full/"><i class="ka ka-torrent"></i> FULL</a></li>
  240. <li class="navigation__item"><a class="navigation__link" href="/category/applications/page/"><i class="ka ka-settings"></i> Apps</a></li>
  241. <li class="navigation__item"><a class="navigation__link" href="/category/anime/page/"><i class="ka ka-film"></i> Anime</a></li>
  242. <li class="navigation__item"><a class="navigation__link" href="/category/other/page/"><i class="ka ka-torrent"></i> Other</a></li>
  243. <li class="navigation__item"><a class="navigation__link" href="/category/xxx/page/"><i class="ka ka-delete"></i> XXX</a></li>
  244. <li class="navigation__item"><a class="navigation__link" href="/new/"><i class="ka ka-plus"></i> More</a></li>
  245. </ul>
  246. `);
  247.  
  248. /*$("#upload_torrents").append(`
  249. <ul class="navigation__sub_items">
  250. <li class="navigation__item"><a class="navigation__link" href="/remote/bot-upload/authval/info/"><i class="ka ka-idea"></i> REMOTE API</a></li>
  251. </ul>
  252. `);*/
  253.  
  254. CalcContentPad();
  255. $("#upshrink").click(CalcContentPad);
  256. }
  257. else {//====== Torrent Section =======
  258. userName = $(".navigation__item > .navigation__link .kf__user").parent().text();
  259. try {
  260. sessionId = $(".navigation__item .navigation__sub_items .navigation__link:contains('Log out')").prop("href").split(";")[1];
  261. } catch(err){ sessionId = false; };
  262.  
  263. $(".navigation__item > .navigation__link .kf__user").parent().parent().find("ul.navigation__sub_items").remove();
  264. $(".navigation__item > .navigation__link .kf__user").parent().after(`
  265. <ul class="navigation__sub_items">
  266. <li class="navigation__item"><a href="https://katcr.co/user/`+userName+`/profile/" class="navigation__link"><i class="kf__torrent button button--icon-button"></i> Torrent Profile</a></li>
  267. <li class="navigation__item"><a href="https://katcr.co/show/community/index.php?action=profile" class="navigation__link"><i class="kf__comments button button--icon-button"></i> Forum Profile</a></li>
  268. <li class="navigation__item"><a href="https://katcr.co/show/community/index.php?action=profile;area=forumprofile" class="navigation__link"><i class="kf__gear button button--icon-button"></i> Edit Profile</a></li>
  269. `+(sessionId ? '<li class="navigation__item"><a href="https://katcr.co/show/community/index.php?action=logout;'+sessionId+'" class="navigation__link">Log out</a></li>' : '')+`
  270. </ul>
  271. `);
  272.  
  273. $(".navigation__item > .navigation__link .kf__arrow_up").parent().parent().detach().prependTo("#js-scrollfix"); //Move upload to left
  274. $(".navigation__item > .navigation__link .kf__arrow_up").parent().parent().find("ul.navigation__sub_items").removeClass("columns-2").find("li:last").remove();
  275.  
  276. $(".navigation__item > .navigation__link .kf__camera").parent().parent().remove(); //remove gallery
  277. $("#js-scrollfix").prepend(`
  278. <li class="navigation__item">
  279. <a class="navigation__link" onclick="return false;" href="#"><i class="kf__plus"></i> Other</a>
  280. <ul class="navigation__sub_items">
  281. <li class="navigation__item">
  282. <a class="navigation__link" href="https://katcr.co/show/community/index.php?action=help">
  283. <i class="kf__question button button--icon-button"></i> Help</a>
  284. </li>
  285. <li class="navigation__item">
  286. <a class="navigation__link" href="https://katcr.co/show/community/index.php?action=sitemap">
  287. <i class="kf__list button button--icon-button"></i> Sitemap</a>
  288. </li>
  289. <li class="navigation__item">
  290. <a class="navigation__link" href="https://katcr.co/gallery/movies/page/">
  291. <i class="kf__camera button button--icon-button"></i> Gallery</a>
  292. </li>
  293. </ul>
  294. </li>
  295. `);
  296.  
  297. $(".navigation__item > .navigation__link[href='/new/'] .kf__torrent, .navigation__item > .navigation__link[href='https://katcr.co/new/'] .kf__torrent").parent().html('<i class="kf__torrent"></i> Browse Torrents');
  298. $(".navigation__item > .navigation__link[href='/new/'] .kf__torrent, .navigation__item > .navigation__link[href='https://katcr.co/new/'] .kf__torrent").parent().prop("href", "https://katcr.co/new/full/");
  299. }
  300.  
  301. if(!numOfPM) {
  302. numOfPM = parseInt($(".valueBubble span").html(), 10);
  303. }
  304. if(numOfPM < 1) {
  305. $(".valueBubble").hide();
  306. }
  307.  
  308. if(PMCheckInterval < 10000) {PMCheckInterval = 10000;}
  309. setInterval(function() {
  310. $.ajax({
  311. method: "GET",
  312. url: "https://katcr.co/show/community/index.php?action=help",
  313. dataType: "text"
  314. }).done(function(data) {
  315. try {
  316. let newPMs = parseInt(data.split('id="button_pm"')[1].split('<strong>')[1].split("</strong>")[0], 10);
  317. if(newPMs < 1) {
  318. $(".valueBubble").hide();
  319. }
  320. else {
  321. $(".valueBubble span").html(newPMs);
  322. $(".valueBubble").show();
  323. }
  324. } catch(err){};
  325. });
  326. }, PMCheckInterval);