Ajoute la connexion automatique, un bouton télécharger à la recherche, et plus encore
当前为
// ==UserScript==
// @name YggTorrent amélioré
// @namespace https://openuserjs.org/users/clemente
// @match https://yggtorrent.li/*
// @version 1.8
// @author clemente
// @license MIT
// @description Ajoute la connexion automatique, un bouton télécharger à la recherche, et plus encore
// @inject-into content
// @noframes
// @grant GM_getValue
// @grant GM_setValue
// @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();
displayNewSearchButton();
keepSearchWhenClickingOnSubcategoryIcon();
function login(alreadyCalled) {
const loginButton = document.getElementById('register');
if (!loginButton) return; // If the user is already logged in, do nothing
if (!alreadyCalled && !window.jQuery) { // If jQuery is not present, wait one second so that the scripts are loaded and the login system is active
setTimeout(() => login(true), 1000);
return;
}
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() {
// For every torrent, add the download button
const torrents = document.querySelectorAll('.results table 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);
downloadButton.style = 'float: left;';
const nameLink = torrent.querySelector('td:nth-child(3) a');
nameLink.parentNode.insertBefore(downloadButton, nameLink);
});
}
function hideSidebar() {
const sidebar = document.getElementById('cat');
if (sidebar && 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://yggtorrent.li/favicon.ico";
}
function displayNewSearchButton() {
const buttonTitleByStatus = {
true: "Recherche améliorée activée. Cliquer pour désactiver.",
false: "Recherche améliorée désactivée. Cliquer pour activer.",
};
const buttonColorByStatus = {
true: "color: #98e3da;",
false: "color: inherit;",
};
const searchEngineByStatus = {
true: "new_search",
false: "engine",
};
const searchForm = document.querySelector('form.search');
const searchInput = document.querySelector('form.search .input');
const newSearchButton = document.createElement('button');
const newSearchIcon = document.createElement('span');
newSearchIcon.classList = 'ico_search-plus';
newSearchButton.appendChild(newSearchIcon);
function initFormWithStatus() {
const newSearchStatus = GM_getValue('newSearchStatus', false);
newSearchButton.title = buttonTitleByStatus[newSearchStatus];
newSearchButton.style = 'left: unset; right: 15px;' + buttonColorByStatus[newSearchStatus];
searchForm.action = `/${searchEngineByStatus[newSearchStatus]}/search`;
}
function toggleNewSearchStatus() {
const newSearchStatus = GM_getValue('newSearchStatus', false);
GM_setValue('newSearchStatus', !newSearchStatus);
initFormWithStatus();
}
newSearchButton.onclick = (e) => { toggleNewSearchStatus(); e.preventDefault(); };
initFormWithStatus();
searchInput.appendChild(newSearchButton);
}
function keepSearchWhenClickingOnSubcategoryIcon() {
document.querySelectorAll('[class^="tag_subcat_"]').forEach(node => {
const subcategoryId = node.className.split('tag_subcat_')[1];
node.parentNode.href = `${document.URL}&sub_category=${subcategoryId}`;
});
}
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址