// ==UserScript== // @name nyaa.si/sukebei.nyaa.si helper // @namespace https://nyaa.si/ // @version 0.1 // @description infinite scroll and image previews of torrents, hold SHIFT key and move mouse over the torrent row to start loading images, white loader means it's loading, so wait, red loader means that you have hit request limit (can't do anything about that), wait a bit (half a second) and try again, to load next page, scroll at the bottom (scrollbar needs to hit the bottom), left most top corner has page information - current page and total known pages (updates upon loading next page) // @author Mossshine // @match https://sukebei.nyaa.si/* // @match https://nyaa.si/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; const BASE_URL = `${window.location.protocol}//${window.location.hostname}`; const IMAGE_REGEXP = /http(.*jpg|.*png)/g; const NEW_LINES = /\]/g; $('body').prepend(`
`); function Utilities() {} Utilities.prototype = { constructor: Utilities, nextPage: function (uri) { if(uri.has('p')) { uri.set('p', (parseInt(uri.get('p')) + 1).toString()) } else { uri.set('p', '2'); } return uri; }, currentPage: function (uri) { if(uri.has('p')) { return uri.get('p'); } else { return 1; } } }; const Utils = new Utilities(); let uri = new URLSearchParams(window.location.search); let isLoadingNextPage = false; $(window).on('wheel', function () { if(isLoadingNextPage === true) { return; } if(($(window).scrollTop() + $(window).height()) === $(document).height()) { Utils.nextPage(uri); isLoadingNextPage = true; $('.total-known-pages').html(``); $.ajax({ url: BASE_URL + '/?' + uri.toString(), type: "GET", success: function (rawHtml) { isLoadingNextPage = false; let table = $(rawHtml).find('.torrent-list'); $('.torrent-list').find('tbody').append(table.find('tbody').html()); let currentHighest = 0; $(rawHtml).find('ul.pagination a').each(function () { let page = parseInt($(this).html()); if(page > currentHighest) { currentHighest = page; } }) $('.actual-page').html(Utils.currentPage(uri)); $('.total-known-pages').html(currentHighest); bindPreviews(); } }) } }); let currentHighest = 0; $('ul.pagination').find('a').each(function () { let page = parseInt($(this).html()); if(page > currentHighest) { currentHighest = page; } }) $('.actual-page').html(Utils.currentPage(uri)); $('.total-known-pages').html(currentHighest); $('.paginator-status').css('display', 'flex'); bindPreviews(); function bindPreviews() { $(".torrent-list tr:not(.loaded)").off().on('mouseover',function (e) { if(e.shiftKey === false) { return; } let row = $(this); if(row.hasClass('loaded') || row.hasClass('loading')) { return; } let torrentUrl = row.find("td[colspan='2'] > a"); if(torrentUrl.length === 0) { return; } row.addClass('loading'); let category = row.find('td:first-child > a'); $.ajax({ url: BASE_URL + torrentUrl.attr('href'), type: "GET", beforeSend: function () { let preloader = category.find('.preloader'); if(preloader.length === 0) { category.find('img').css('display', 'none'); category.append(``); } else { preloader.removeClass('error'); } }, statusCode: { 429: function () { row.removeClass('loading'); let preloader = category.find('.preloader'); if(preloader.length !== 0) { preloader.addClass('error'); } } }, error: function () { row.removeClass('loading'); let preloader = category.find('.preloader'); if(preloader.length !== 0) { preloader.addClass('error'); } }, success: function (rawHtml) { row.removeClass('loading'); if(row.hasClass('loaded')) { return; } row.addClass('loaded'); let rawDescription = $(rawHtml).find('#torrent-description').html(); rawDescription = rawDescription.replace(NEW_LINES, "\n"); let m; let images = []; while ((m = IMAGE_REGEXP.exec(rawDescription)) !== null) { if (m.index === IMAGE_REGEXP.lastIndex) { IMAGE_REGEXP.lastIndex++; } m.forEach((match, groupIndex) => { if(groupIndex === 0) { images.push(`