Greasy Fork is available in English.
Extend titles, add images to torrent list, full width site
当前为
// ==UserScript==
// @name 1337x - UX Enhancement
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Extend titles, add images to torrent list, full width site
// @author French Bond
// @match https://1337x.to/*
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @license MIT
// ==/UserScript==
(function () {
'use strict';
// List all torrent links on the page
function listTorrentLinks() {
return document.querySelectorAll('a[href^="/torrent/"]');
}
// Clean the page title in order to get the torrent title
function cleanTitle(title) {
// Remove "Download " from the beginning
if (title.startsWith('Download ')) {
title = title.substring('Download '.length);
}
// Remove anything after " |"
let pipeIndex = title.indexOf(' Torrent |');
if (pipeIndex !== -1) {
title = title.substring(0, pipeIndex);
}
return title;
}
// Modify the H1 content on torrent pages to show the full title
function modifyH1ContentOnTorrentPages() {
if (window.location.pathname.startsWith('/torrent/')) {
let h1Element = document.querySelector('.box-info-heading h1');
if (h1Element) {
let cleanedTitle = cleanTitle(document.title);
h1Element.textContent = cleanedTitle;
}
}
}
// Fetch the link and process the title and images
function fetchAndProcessLink(link) {
GM_xmlhttpRequest({
method: 'GET',
url: link.href,
onload: function (response) {
let parser = new DOMParser();
let doc = parser.parseFromString(response.responseText, 'text/html');
// Process title
let title = doc.querySelector('title').innerText;
title = cleanTitle(title);
link.innerText = title;
// Create download buttons
let torrentLink = doc.querySelector("a[href*='itorrents.org/torrent/']");
let magnetLink = doc.querySelector("a[href^='magnet:?']");
// Create and style download buttons container
let buttonsContainer = document.createElement('div');
buttonsContainer.style.display = 'flex';
buttonsContainer.style.alignItems = 'center';
buttonsContainer.style.gap = '5px';
// Torrent button
let torrentButton = document.createElement('a');
torrentButton.href = torrentLink ? torrentLink.href.replace('http:', 'https:') : '#';
torrentButton.title = 'Download torrent file';
torrentButton.innerHTML =
'<i class="flaticon-torrent-download" style="color: #89ad19; font-size: 16px"></i>';
// Magnet button
let magnetButton = document.createElement('a');
magnetButton.href = magnetLink ? magnetLink.href : '#';
magnetButton.title = 'Download via magnet';
magnetButton.innerHTML =
'<i class="flaticon-magnet" style="color: #da3a04; font-size: 16px"></i>';
// Append buttons to the container
buttonsContainer.appendChild(torrentButton);
buttonsContainer.appendChild(magnetButton);
// Insert buttons container after the link
link.after(buttonsContainer);
// Process images
let images = doc.querySelectorAll('#description img');
if (images.length > 0) {
let flexContainer = document.createElement('div');
flexContainer.style.display = 'flex';
flexContainer.style.flexWrap = 'wrap';
flexContainer.style.gap = '10px';
flexContainer.style.marginTop = '10px';
images.forEach((img) => {
let clonedImg = img.cloneNode(true);
if (img.hasAttribute('data-original')) {
clonedImg.src = img.getAttribute('data-original');
}
clonedImg.style.maxHeight = '100px';
flexContainer.appendChild(clonedImg);
});
// Append the flex container with images after the buttons
buttonsContainer.after(flexContainer);
}
},
});
}
// Replace the link text with the title and append images
function replaceLinkTextWithTitlesAndAppendImages() {
let torrentLinks = listTorrentLinks();
torrentLinks.forEach((link) => {
fetchAndProcessLink(link);
});
}
function injectCustomCSS() {
// Remove the max-width on the container
GM_addStyle('.container { max-width: none !important; }');
}
// Modify the function calls accordingly
replaceLinkTextWithTitlesAndAppendImages();
modifyH1ContentOnTorrentPages();
injectCustomCSS();
})();