YggTorrent amélioré

Ajoute la connexion automatique, un bouton télécharger à la recherche, et plus encore

当前为 2020-05-01 提交的版本,查看 最新版本

// ==UserScript==
// @name           YggTorrent amélioré
// @namespace      https://openuserjs.org/users/clemente
// @match          https://*.yggtorrent.se/*
// @version        1.2
// @author         clemente
// @license        MIT
// @description    Ajoute la connexion automatique, un bouton télécharger à la recherche, et plus encore
// @icon           https://www2.yggtorrent.se/favicon.ico
// @inject-into    content
// @noframes
// @homepageURL    https://openuserjs.org/scripts/clemente/YggTorrent_am%C3%A9lior%C3%A9
// @supportURL     https://openuserjs.org/scripts/clemente/YggTorrent_am%C3%A9lior%C3%A9/issues
// ==/UserScript==

/* jshint esversion: 6 */

login();
addDownloadButtonToTorrents();
hideSidebar();
displayLargerNfo();
searchByLatestFirst();
fixFavicon();

function login() {
  const loginButton = document.getElementById('register');
  if (!loginButton) return; // If the user is already logged in, do nothing

  let isLoginFormValid = true;
  const loginForm = document.getElementById('user-login');
  loginForm.querySelectorAll('input').forEach(input => {
    isLoginFormValid = isLoginFormValid && input.checkValidity();
  });
  if (!isLoginFormValid) return; // If the form is not valid, then autocomplete is not active and the popup should not bother the user

  loginButton.click();
  loginForm.querySelector('button').click();
  
  function closePopupIfDisplayed(mutations, observer) {
    mutations.forEach(mutation => {
      mutation.addedNodes.forEach(node => {
        if (node.classList.contains('alert-success')) {
          document.querySelector('button.close').click();
          observer.disconnect();
        }
      });
    });
  }

  // Wait for the confirmation popup to appear then close it
  const popupObserver = new MutationObserver(closePopupIfDisplayed);
  popupObserver.observe(document.body, { childList: true });
}

function addDownloadButtonToTorrents() {
  const torrentTables = document.querySelectorAll('.results table');
  if (torrentTables.length !== 1) return;

  const torrentsTable = document.querySelector('.results table');
  
  // Add empty column after name column
  const nameHeader = torrentsTable.querySelector('thead th:nth-child(2)');
  const emptyHeader = document.createElement('th');
  emptyHeader.classList.add('no');
  nameHeader.parentNode.insertBefore(emptyHeader, nameHeader.nextSibling);
  
  // For every torrent, add the download button
  const torrents = torrentsTable.querySelectorAll('tbody tr');
  torrents.forEach(torrent => {
    const torrentId = torrent.querySelector('a[target]').target;
    const downloadIcon = document.createElement('span');
    downloadIcon.classList.add('ico_download');
    const downloadButton = document.createElement('a');
    downloadButton.href = `/engine/download_torrent?id=${torrentId}`;
    downloadButton.append(downloadIcon);
    const downloadCell = document.createElement('td');
    downloadCell.append(downloadButton);
    
    const nameCell = torrent.querySelector('td:nth-child(2)');
    nameCell.parentNode.insertBefore(downloadCell, nameCell.nextSibling);
  });
}

function hideSidebar() {
  const sidebar = document.getElementById('cat');
  if (sidebar.classList.contains('active')) {
    sidebar.querySelector('.open').click();
  }
}

function displayLargerNfo() {
  const modal = document.getElementById('nfoModal');
  if (!modal) return; // If there is no modal, the user is not on a torrent page and nothing should be done
  const modalDialog = modal.querySelector('.modal-dialog');
  modalDialog.classList.remove('modal-sm');
  modalDialog.classList.add('modal-lg');
}

function searchByLatestFirst() {
  const searchForm = document.querySelector('form.search');
  const orderInput = document.createElement('input');
  orderInput.name = 'order';
  orderInput.value = 'desc';
  orderInput.style = 'display: none';
  const sortInput = document.createElement('input');
  sortInput.name = 'sort';
  sortInput.value = 'publish_date';
  sortInput.style = 'display: none';
  searchForm.append(orderInput);
  searchForm.append(sortInput);
}

function fixFavicon() {
  const favicon = document.querySelector('link[href="https://www.yggtorrent.pe/favicon.ico"]');
  favicon.href = "https://www.yggtorrent.se/favicon.ico";
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址