Skip to content

Instantly share code, notes, and snippets.

@leeroybrun
Created July 6, 2017 07:52
Show Gist options
  • Save leeroybrun/cd00f40b2888a9cb20244def7b052d66 to your computer and use it in GitHub Desktop.
Save leeroybrun/cd00f40b2888a9cb20244def7b052d66 to your computer and use it in GitHub Desktop.
Notify when new torrents appears on TorrentLeech. Check every 30s.
// ==UserScript==
// @name TorrentLeech-notify
// @namespace https://www.torrentleech.org/
// @version 0.1
// @description Notify when new torrents appears on TorrentLeech. Check every 30s.
// @author Leeroy Brun
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @match https://www.torrentleech.org/torrents/browse*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_notification
// @grant GM_openInTab
// ==/UserScript==
setTimeout(() => location.reload(), 30000);
const notifiedTorrents = JSON.parse(GM_getValue('notifiedTorrents', '{}'));
console.log(Object.keys(notifiedTorrents).length +' torrents already notified');
function genOnClickHandler(url) {
return function() {
GM_openInTab(url, {active:true});
};
}
$('#torrenttable tbody tr').each((i, torrentEl) => {
const torrentId = $(torrentEl).attr('id');
//if(i == 1) { // For testing purpose
if(!(torrentId in notifiedTorrents)) {
const torrentUrl = 'https://www.torrentleech.org'+ $('.title a', torrentEl).attr('href');
GM_notification($('.title', torrentEl).text() +"\n"+ $('td:nth-child(5)', torrentEl).text() +' - '+ $('.seeders', torrentEl).text() +'/'+$('.leechers', torrentEl).text() +' peers', null, null, genOnClickHandler(torrentUrl));
notifiedTorrents[torrentId] = true;
}
});
GM_setValue('notifiedTorrents', JSON.stringify(notifiedTorrents));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment