Skip to content

Instantly share code, notes, and snippets.

@MewX
Forked from LostInsight/NexusPHP Hightlight.user.js
Last active April 19, 2022 02:42
Show Gist options
  • Save MewX/e3feb41775ac7004f791329d60acbe81 to your computer and use it in GitHub Desktop.
Save MewX/e3feb41775ac7004f791329d60acbe81 to your computer and use it in GitHub Desktop.
A script for highlighting free and 2xfree items in PT sites for MewX's own use.
// ==UserScript==
// @name MewX Row Free Highlight
// @version 0.7
// @description A script for highlighting free and 2xfree items in PT sites.
// @author MewX, LostMelody
// @note 大量站点未测,特别是CHD,影客,U2,HDChina
// @note 网址和入口参考PT-Plugin-Plus内置地址
// @note 部分识别接口参考Juszoe的flexget-nexusphp但具体未测
// @require https://code.jquery.com/jquery-3.4.1.min.js
// @match *://*.52pt.site/*
// @match *://*.byr.cn/*
// @match *://*.chdbits.co/*
// @match *://*.discfan.net/*
// @match *://*.et8.org/*
// @match *://*.hdcity.city/*
// @match *://*.hddolby.com/*
// @match *://*.hdhome.org/*
// @match *://*.pthome.net/*
// @match *://*.btschool.club/*
// @match *://*.beitai.pt/*
// @match *://*.hdsky.me/*
// @match *://*.hdstreet.club/*
// @match *://*.hdtime.org/*
// @match *://*.hdzone.me/*
// @match *://*.hdupt.com/*
// @match *://*.leaguehd.com/*
// @match *://*.joyhd.net/*
// @match *://*.moecat.best/*
// @match *://*.nanyangpt.com/*
// @match *://*.nicept.net/*
// @match *://*.npupt.com/*
// @match *://*.open.cd/*
// @match *://*.ourbits.club/*
// @match *://*.eastgame.org/*
// @match *://*.hd4fans.org/*
// @match *://*.hdbd.us/*
// @match *://*.hdupt.com/*
// @match *://*.j99.info/*
// @match *://*.keepfrds.com/*
// @match *://*.m-team.cc/*
// @match *://*.msg.vg/*
// @match *://*.soulvoice.club/*
// @match *://*.pterclub.com/*
// @match *://*.ptsbao.club/*
// @match *://*.springsunday.net/*
// @match *://*.tjupt.org/*
// @match *://*.totheglory.im/*
// @match *://*.sjtu.edu.cn/*
// @match *://u2.dmhy.org/*
// @match *://*.uhdbits.org/*
// @match *://*.hdarea.co/*
// @match *://*.yingk.com/*
// ==/UserScript==
const mewxRecDownloadColor = '#009688';
const mewxFreeDownloadColor = '#b2dfdb';
const mewxSnatchedColor = '#bbdefb';
const mewxDefaultColor = '#e0e0e0';
const mewxMinRemainingHourToHighlight = 20;
// Checking website.
const currentURL = '' + window.location;
var website = 'default';
if (currentURL.includes('totheglory.im')) {
website = 'ttg';
} else if (currentURL.includes('open.cd')) {
website = 'opencd'
}
function checkTorrentPage(torrentPagePaths) {
for (let i = 0; i < torrentPagePaths.length; i ++) {
if (currentURL.includes(torrentPagePaths[i])) {
return;
}
}
throw new Error('Not ' + website + ' torrent page');
}
function ttg() {
checkTorrentPage(['totheglory.im/browse.php']);
const tbody = $('table[id="torrent_table"]').find('tbody').eq(0);
const rows = tbody.find('tr');
for (let i = 0; i < rows.length; i ++) {
const row = rows.eq(i);
const cells = row.find('td');
const free = cells.eq(1).find('img[src="/pic/ico_free.gif"]').length > 0;
const hnr = cells.eq(1).find('img[src="/pic/hit_run.gif"]').length > 0;
const snatched = cells.eq(1).find('div[class*="process"]').length > 0;
if (hnr || !free) {
row.css({backgroundColor: mewxDefaultColor});
continue;
}
console.log('Checking: ' + cells.eq(1).find('a').eq(0).text());
if (snatched) {
// In progress.
row.css({backgroundColor: mewxSnatchedColor});
continue;
} else if (parseInt(cells.eq(8).children().first().text()) < 5) {
// Recommend due to low seeder.
row.css({backgroundColor: mewxRecDownloadColor});
} else {
// Ok for freeleech + any seeder.
row.css({backgroundColor: mewxFreeDownloadColor});
}
}
}
function opencd() {
checkTorrentPage(['/torrents.php']);
const tbody = $('form[id="form_torrent"]').find('> table > tbody');
const rows = tbody.find('> tr');
for (let i = 1; i < rows.length; i ++) {
const row = rows.eq(i);
const cells = row.find('> td');
const mainCell = cells.eq(2).find('> table > tbody > tr').eq(0);
const freeTagCell = mainCell.find('img.pro_free,img.pro_free2up');
const free = freeTagCell.length > 0;
const snatched = mainCell.find('div[class="progressarea"]').length > 0;
if (!free) {
row.css({backgroundColor: mewxDefaultColor});
mainCell.css({backgroundColor: mewxDefaultColor});
continue;
}
// Check how long free remaining.
const remainingTag = freeTagCell.eq(0).parent().parent().find('> span');
let remainingMinutes = 99999999; // By default, if not specified.
if (remainingTag.length > 0) {
const expiryTimestamp = new Date(remainingTag.eq(0).attr('title')).getTime();
const nowTimestamp = new Date(new Date(Date.now()).toLocaleString('en-US', { timeZone: 'Asia/Shanghai' })).getTime();
remainingMinutes = (expiryTimestamp - nowTimestamp) / 1000 / 60;
console.log(remainingTag.eq(0).attr('title') + ' (' + expiryTimestamp + ') - remaining in hours: ' + (remainingMinutes / 60));
}
// Setting colors.
if (snatched) {
// In progress.
row.css({backgroundColor: mewxSnatchedColor});
mainCell.css({backgroundColor: mewxSnatchedColor});
continue;
} else if (remainingMinutes / 60 >= mewxMinRemainingHourToHighlight) {
// Recommend due to long free time (e.g. 20h or more).
row.css({backgroundColor: mewxRecDownloadColor});
mainCell.css({backgroundColor: mewxRecDownloadColor});
} else {
// Ok for freeleech + any seeder.
row.css({backgroundColor: mewxFreeDownloadColor});
mainCell.css({backgroundColor: mewxFreeDownloadColor});
}
}
}
(function() {
$(document).ready(function(){
if (website == 'ttg') {
ttg();
} else if (website == 'opencd') {
opencd();
} else {
switch (location.pathname) {
case '/adult.php':
case '/browse.php':
case '/live.php':
case '/movie.php':
case '/music.php':
case '/torrentsasia.php':
case '/torrents.php': {
try {
var cnt=$("form_torrent");
if (!(cnt===null)){
cnt.replaceWith(...cnt.childNodes);
}
}catch(err) {}
var styleElement = document.createElement('style');
styleElement.innerHTML = '.torrents tr:hover{background-color:'+mewxDefaultColor+'}';
document.head.append(styleElement);
const freenames = ['pro_free', 'pro_free2up','free','twoupfree','span_frees','span_twoupfreels','本种子限时不计流量'];
for (const freename of freenames) {
var $free=document.getElementsByClassName(freename);
for (const free of $free) {
free.parentElement.parentElement.setAttribute('style','background:'+mewxFreeDownloadColor);
}
}
}
break;
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment