ILoveClassics Enhancer

Better display for ILoveClassics

  1. // ==UserScript==
  2. // @name ILoveClassics Enhancer
  3. // @namespace surrealmoviez.info
  4. // @description Better display for ILoveClassics
  5. // @include http://www.iloveclassics.com/*
  6. // @require http://code.jquery.com/jquery-1.11.1.min.js
  7. // @grant GM_addStyle
  8. // @version 0.4.0
  9. // ==/UserScript==
  10.  
  11. this.$ = this.jQuery = jQuery.noConflict(true);
  12.  
  13. var uri = document.documentURI;
  14.  
  15. GM_addStyle(".suggestion-element:hover { background-color : #98a099; }");
  16.  
  17. // Global search bar
  18. var userbarTitle = $('.NB_ftcm:contains(User Bar)').closest('.fheader');
  19. var searchDiv = '<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: center;"><tr><td>'
  20. + '<form id="globalSearchBar" action="http://www.iloveclassics.com/browse.php" method="get" style="margin-top: 2px; margin-bottom: 4px; width: 100%;">'
  21. + '<input id="globalSearchInput" type="text" name="search" style="width: 85%; border: 1px solid rgb(51, 51, 51); background-color: rgb(25, 25, 25); color: white; border-radius: 3px; margin-right: 3px; padding-left: 4px; padding-right: 4px;" placeholder="Search torrents" maxlength="250" autocomplete="off">'
  22. + '<div id="suggestionsContainer" style="position: absolute; padding: 8px; background-color: #191919; display: none; margin-left: 6px; text-align: left; z-index: 100; box-shadow: 5px 5px 7px black;"></div>'
  23. + '<input type="hidden" value="0" name="cat">'
  24. + '<input type="hidden" value="1" name="incldead">'
  25. + '<select name="searchin" style="width: 14%; text-align: center; right: 0px; background-color: rgb(25, 25, 25); color: white; border: 1px solid rgb(51, 51, 51); border-radius: 3px;">'
  26. + '<option value="1" style="color: gray;">Title</option>'
  27. + '<option value="2">Description</option>'
  28. + '<option value="0">Both</option>'
  29. + '</select>'
  30. + '</form>'
  31. + '</td></tr></table>';
  32. $(document).ready(function () {
  33. $(searchDiv).insertAfter(userbarTitle);
  34.  
  35. // Hide the 'User Bar' title row
  36. userbarTitle.hide();
  37.  
  38. // Add the suggestions feature to the global search bar
  39. $('#globalSearchInput').keyup(function(event) {
  40. var $suggestions = $("#suggestionsContainer");
  41. if (event.which === 27){
  42. $suggestions.fadeOut('slow');
  43. return;
  44. }
  45. if ($(this).val() !== "") {
  46. // Show the suggestions if there's text in the input
  47. $suggestions.fadeIn('slow');
  48. if ($(this).val().length < 4) {
  49. // Don't make requests for queries shorter than 4 characters
  50. $suggestions.text('...');
  51. } else {
  52. // Show the loading image while the request runs
  53. $suggestions.html('<img src="http://i.imgur.com/EUMuKRs.gif" title="Loading..." alt="Loading...">');
  54. $.get('/suggest.php?q=' + $(this).val(), function(data) {
  55. if (data.trim().length === 0) {
  56. $suggestions.text('Nothing found :(');
  57. return;
  58. }
  59. var arraySuggestions = data.split('\n');
  60. for (var i = 0; i < arraySuggestions.length; i++) {
  61. // Clicking the suggestions automatically submits the form
  62. arraySuggestions[i] = '<span class="suggestion-element" style="display: inline-block; margin-bottom: 2px; cursor: pointer;" onclick="$(\'#globalSearchInput\').val($(this).text()); $(\'#globalSearchBar\').submit()">' + arraySuggestions[i] + '</span>';
  63. }
  64. $suggestions.html(arraySuggestions.join('<br>'));
  65. });
  66. }
  67. } else {
  68. // Hide suggestions if the input is empty
  69. $suggestions.fadeOut('slow');
  70. }
  71. });
  72.  
  73. // Hide the suggestions when clicked outside the form or the suggestions list
  74. $(document).mouseup(function(e) {
  75. var $searchBar = $('#globalSearchBar');
  76. if (!$searchBar.is(e.target) && $searchBar.has(e.target).length === 0) {
  77. $("#suggestionsContainer").hide();
  78. } else if ($('#globalSearchInput').val() !== "") {
  79. $("#suggestionsContainer").show();
  80. }
  81. });
  82.  
  83. // Open search result in new tab if in the shoutbox page
  84. if (uri.indexOf('/sb.php') !== -1) {
  85. $('#globalSearchBar').attr('target', '_blank');
  86. }
  87.  
  88. // Site logo links to the homepage
  89. $('.clear > div > img').wrap('<a href="index.php"></a>');
  90.  
  91. // Reorder the search display to get to the actual data faster
  92. if (uri.indexOf('/browse.php') !== -1) {
  93. // Put the colour keys at the bottom of the list
  94. var colourKeys = $('.NB_fmmain > center');
  95. colourKeys.siblings('br').remove();
  96. $(colourKeys).insertAfter('#hover-over');
  97.  
  98. // Flip the search methods
  99. $('#kutorrentsearch > center').prependTo('#kutorrentsearch');
  100. $('#kutorrentsearch > form').appendTo('#kutorrentsearch');
  101. $('#kutorrentsearch > br').remove();
  102. }
  103.  
  104. // Hide the search area if the user is browsing trough torrent pages
  105. if (uri.indexOf('/browse.php?') !== -1 && uri.indexOf('page=') !== -1 && uri.indexOf('page=0') === -1) {
  106. $('body').scrollTop($('#picutorrentsearch').closest('.ftable').offset().top);
  107. $('#kutorrentsearch').hide();
  108. }
  109.  
  110. // Show hint of previously downloaded torrent in details page
  111. if (uri.indexOf('/details.php?id=') !== -1) {
  112. GM_addStyle("td > a.index:visited { color: #00ff00; }");
  113. }
  114.  
  115. // Show hint of previously downloaded torrent in browse page
  116. if (uri.indexOf('/browse.php') !== -1) {
  117. GM_addStyle("a.floppy:visited { color: #00ff00; }"
  118. + "a.floppy:link { color: #3B3B3B; }");
  119. $('#hover-over img[alt=Download]').parent().addClass('floppy').parent().attr('align', 'center');
  120. $('<span style="font-size: 13pt;">⏬</span>').insertBefore($('#hover-over img[alt=Download]'));
  121. }
  122. // Shortcut to select all reseed requests in PMs
  123. if (uri.indexOf('/messages.php') !== -1) {
  124. $('<input id="check-reseed-requests" type="button" value="Check reseed requests">').insertBefore($('.colhead > input[name=delete]'));
  125. $('#check-reseed-requests').click(function() {
  126. $('form .NB_fmmain input[type=checkbox]').each(function(){
  127. if ($(this).parent().prev().prev().text() === 'System' &&
  128. $(this).parent().prev().prev().prev().text() === 'Reseed request') {
  129. $(this).attr('checked', true);
  130. }
  131.  
  132. });
  133. });
  134. }
  135.  
  136. });