').css({'font-weight':'bold'}));
/* Create contents area */
var contents = $('');
box.append(contents);
var timer = null;
var timeout = 0;
var inhibit_fade = false;
function set_visible(visible) {
if (visible && box.is(':hidden')) box.fadeIn(500);
else if (!visible && box.is(':visible')) box.fadeOut(500);
}
function clear_timer() {
if (timer) {
window.clearTimeout(timer);
timer = null;
}
}
function set_timer() {
if (!timer && timeout > 0) {
timer = window.setTimeout(function() { clear_timer(); set_visible(false); }, timeout);
}
}
function update_timer(t) {
clear_timer();
timeout = t;
if (!inhibit_fade) set_timer();
}
function set_inhibit_fade(inhibit) {
inhibit_fade = inhibit;
if (!inhibit_fade) { set_timer(); }
else clear_timer();
}
/* Register event handlers */
box.mouseenter(function(event) {
set_inhibit_fade(true);
$(this).fadeTo(500, 0.8);
});
box.mouseleave(function(event) {
set_inhibit_fade(false);
$(this).fadeTo(500, 0.5);
});
box.click(function(event) {
clear_timer();
$(this).unbind('mouseenter');
$(this).unbind('mouseleave');
set_visible(false);
});
/* Append to global status area */
status_area.append(box);
return {
contents: function() {
return contents;
},
show: function(t) {
if (global_hideStatusBox != 'true' || /\/torrents\.php.type/.test(document.URL)) {
t = t || 0;
update_timer(t);
set_visible(true);
}
},
hide: function() {
clear_timer();
set_visible(false);
}
};
}
function doOptionsMenu() {
var options_menu = $('#gazelle_options_menu').eq(0);
if (options_menu.length == 0) {
var optHeight = 570;
var optWidth = 820;
options_menu = $('').css({
'top': window.innerHeight,
'left': '50%',
'margin-left': -optWidth*.5,
'width': optWidth,
'height': optHeight,
'border-radius': '10px'
}).hide();
var css_div = $('').css({
'width': '95%', 'height':'auto','margin': '20px 20px 15px','color':'#ffffff'//,'overflow': 'hidden'
});
var refreshHeader = $('
Update Frequency
');
var refreshInput = $('Interval between updates in minutes (minimum of 10) ').css({'text-align':'right', 'width':'20px'});
var columns_div = $('').css({ 'width':'100%', 'margin-top':'-18px', 'display':'table'});
var leftColumn = $('');
leftColumn.append(refreshHeader);
leftColumn.append(refreshInput);
var hideHeader = $('
Visibility
');
var check_box_hide = $('Show the status box on all pages ');
var explanation_div = $('
The status box will always appear on \'/torrents.php?type=...\' and whenever a script update is available.
');
leftColumn.append(hideHeader);
leftColumn.append(check_box_hide);
leftColumn.append(explanation_div);
var positionHeader = $('
Status Box Position
');
var radio_button_tl = $('Top Left ');
var radio_button_tr = $('Top Right ');
var radio_button_bl = $('Bottom Left ');
var radio_button_br = $('Bottom Right ');
var rightColumn = $('');
rightColumn.append(positionHeader);
rightColumn.append(radio_button_tl);
rightColumn.append(radio_button_tr);
rightColumn.append(radio_button_bl);
rightColumn.append(radio_button_br);
var offsetHeader = $('
Status Box Y-Offset
');
var offsetInput = $('The offset in pixels from the top or bottom of the window ').css({'text-align':'right', 'width':'20px'});
rightColumn.append(offsetHeader);
rightColumn.append(offsetInput);
columns_div.append(leftColumn);
columns_div.append(rightColumn);
css_div.append(columns_div);
var full_div = $('');
var styleHeader = $('
Link Style Settings
');
full_div.append(styleHeader);
var sampleText = $('Sample Group Snatched Torrent Link ');
sampleText.click(function () { return false; });
snatchedInput = $('.group_snatched');
var applyLink = $('Test');
applyLink.click(function () { ApplyStyle('sample_gsnatched', 'input_gsnatched'); return false; });
var defaultLink = $('Default');
defaultLink.click(function () { SetStyle('sample_gsnatched', GROUP_SNATCHED); $("input[id='input_gsnatched']").val(GROUP_SNATCHED); return false; });
full_div.append(sampleText);
full_div.append(snatchedInput);
full_div.append(applyLink);
full_div.append(defaultLink);
var sampleText = $('Sample Snatched Torrent Link ');
sampleText.click(function () { return false; });
var snatchedInput = $('.gazelle_snatched');
applyLink = $('Test');
applyLink.click(function () { ApplyStyle('sample_tsnatched', 'input_tsnatched'); ApplyStyle('sample_seeding', 'input_tsnatched', 'input_seeding'); return false; });
defaultLink = $('Default');
defaultLink.click(function () { SetStyle('sample_tsnatched', T_SNATCHED); SetStyle('sample_seeding', T_SNATCHED + $("input[id='input_seeding']").val()); $("input[id='input_tsnatched']").val(T_SNATCHED); return false; });
full_div.append(sampleText);
full_div.append(snatchedInput);
full_div.append(applyLink);
full_div.append(defaultLink);
sampleText = $('Sample Uploaded Torrent Link ');
sampleText.click(function () { return false; });
snatchedInput = $('.gazelle_uploaded');
applyLink = $('Test');
applyLink.click(function () { ApplyStyle('sample_uploaded', 'input_uploaded'); ApplyStyle('sample_ul_seed', 'input_uploaded', 'input_seeding'); return false; });
defaultLink = $('Default');
defaultLink.click(function () { SetStyle('sample_uploaded', UPLOADED); SetStyle('sample_ul_seed', UPLOADED + $("input[id='input_seeding']").val()); $("input[id='input_uploaded']").val(UPLOADED); return false; });
full_div.append(sampleText);
full_div.append(snatchedInput);
full_div.append(applyLink);
full_div.append(defaultLink);
//sampleText = $('Sample Seeding Snatched Torrent Link (.gazelle_snatched style is also applied to this link) ');
//sampleTxt2 = $('Sample Seeding Uploaded Torrent Link (.gazelle_uploaded style is also applied to this link) ');
sampleText = $('Seeding links will always have either the .gazelle_snatched style or the .gazelle_uploaded style applied to them, so .gazelle_seeding is commonly used to override those base styles.');
var sampleTxt2 = $('Sample Seeding Snatched Torrent LinkSample Seeding Uploaded Torrent Link ');
//sampleText.click(function () { return false; });
sampleTxt2.click(function () { return false; });
snatchedInput = $('.gazelle_seeding');
applyLink = $('Test');
applyLink.click(function () { ApplyStyle('sample_seeding', 'input_tsnatched', 'input_seeding'); ApplyStyle('sample_ul_seed', 'input_uploaded', 'input_seeding'); return false; });
defaultLink = $('Default');
defaultLink.click(function () { SetStyle('sample_seeding', $("input[id='input_tsnatched']").val() + SEEDING); $("input[id='input_seeding']").val(SEEDING);
SetStyle('sample_ul_seed', $("input[id='input_uploaded']").val() + SEEDING); return false; });
full_div.append(sampleText);
full_div.append(sampleTxt2);
full_div.append(snatchedInput);
full_div.append(applyLink);
full_div.append(defaultLink);
sampleText = $('Sample Leeching Torrent Link ');
sampleText.click(function () { return false; });
snatchedInput = $('.gazelle_leeching');
applyLink = $('Test');
applyLink.click(function () { ApplyStyle('sample_leeching', 'input_leeching'); return false; });
defaultLink = $('Default');
defaultLink.click(function () { SetStyle('sample_leeching', LEECHING); $("input[id='input_leeching']").val(LEECHING); return false; });
full_div.append(sampleText);
full_div.append(snatchedInput);
full_div.append(applyLink);
full_div.append(defaultLink);
sampleText = $('Sample Bookmarked Torrent Link ');
sampleText.click(function () { return false; });
snatchedInput = $('.gazelle_bookmark');
applyLink = $('Test');
applyLink.click(function () { ApplyStyle('sample_bookmarked', 'input_bookmarked'); return false; });
defaultLink = $('Default');
defaultLink.click(function () { SetStyle('sample_bookmarked', BOOKMARKED); $("input[id='input_bookmarked']").val(BOOKMARKED); return false; });
full_div.append(sampleText);
full_div.append(snatchedInput);
full_div.append(applyLink);
full_div.append(defaultLink);
css_div.append(full_div);
var okay_button = $('Submit');
okay_button.click(function () { CommitOptions(); DisplaySlideMenu(false); });
var cancel_button = $('Cancel');
cancel_button.click(function () { DisplaySlideMenu(false); });
var button_div = $('').css({
'width': '95%', 'margin': '15px','overflow': 'hidden'
});
options_menu.append(css_div);
button_div.append(cancel_button);
button_div.append(okay_button);
options_menu.append(button_div);
$('body').append(options_menu);
} else {
// we already created the div
var boxPos = getDomainLSValue('box_position', 'top_right');
$("input[name='location'][id='" + boxPos + "']").attr('checked','checked');
if (global_hideStatusBox != 'true')
$("input[name='visibility']").attr('checked','checked');
$("input[name='interval']").val(global_updateFreq);
$("input[name='yOffset']").val(global_SB_YOffset);
ApplyStyle('sample_gsnatched', 'input_gsnatched');
ApplyStyle('sample_tsnatched', 'input_tsnatched');
ApplyStyle('sample_uploaded', 'input_uploaded');
ApplyStyle('sample_leeching', 'input_leeching');
ApplyStyle('sample_seeding', 'input_tsnatched', 'input_seeding');
ApplyStyle('sample_ul_seed', 'input_uploaded', 'input_seeding');
ApplyStyle('sample_bookmarked', 'input_bookmarked');
}
}
function ApplyStyle(textControl, styleControl, styleControl2) {
var css_style = $("input[id='" + styleControl + "']").val();
if (styleControl2)
css_style += $("input[id='" + styleControl2 + "']").val();
SetStyle(textControl, css_style);
}
function SetStyle(textControl, css_style) {
$("a[id='" + textControl + "']").removeAttr('style');
$("a[id='" + textControl + "']").attr('style',css_style);
}
function CommitOptions() {
var locRadio = $("input[name='location']:checked").attr('id');
if (locRadio.length != 0)
setDomainLSValue('box_position',locRadio);
var boxHide = $("input[name='visibility']:checked");
if (boxHide.length != 0)
deleteDomainLSValue('box_hidden');
else {
setDomainLSValue('box_hidden','true');
global_hideStatusBox = true;
status.hide();
}
var updateFreq = $("input[name='interval']").val();
if (jQuery.isNumeric(updateFreq)) {
if (updateFreq != AUTO_UPDATE_INTERVAL) {
if (updateFreq < 10) updateFreq = 10;
setDomainLSValue('update_freq', updateFreq);
}
else
deleteDomainLSValue('update_freq');
}
var offset = $("input[name='yOffset']").val();
if (jQuery.isNumeric(offset) && offset >= 0) {
if (offset != STATUS_BOX_YOFFSET)
setDomainLSValue('box_yoffset', offset);
else
deleteDomainLSValue('box_yoffset');
}
AddOrDeleteCustomStyle('input_gsnatched', GROUP_SNATCHED, 'style_groupsnatched', '.group_snatched');
AddOrDeleteCustomStyle('input_tsnatched', T_SNATCHED, 'style_tsnatched', '.gazelle_snatched');
AddOrDeleteCustomStyle('input_uploaded', UPLOADED, 'style_uploaded', '.gazelle_uploaded');
AddOrDeleteCustomStyle('input_leeching', LEECHING, 'style_leeching', '.gazelle_leeching');
AddOrDeleteCustomStyle('input_seeding', SEEDING, 'style_seeding', '.gazelle_seeding');
AddOrDeleteCustomStyle('input_bookmarked', BOOKMARKED, 'style_bookmarked', '.gazelle_bookmark');
}
function AddOrDeleteCustomStyle(inputName, def_css, storageVal, className) {
var css = jQuery.trim($("input[id='" + inputName + "']").val());
if (css == def_css) { // if the current css stripped of whitespace equals the default style, delete the custom style
deleteDomainLSValue(storageVal);
css = def_css;
}
else
setDomainLSValue(storageVal, css);
GM_addStyle(className + '{' + css + '}'); // updates the page without reloading (at least on chrome)
}
function DisplaySlideMenu(showMenu) {
if (showMenu) {
if (!slideMenuShowing) {
slideMenuShowing = 1;
$('#gazelle_options_menu').show().animate({
top:'-=' + ($('#gazelle_options_menu').innerHeight()-10) + 'px'
});
}
} else {
slideMenuShowing = 0;
$('#gazelle_options_menu').animate({
top:'+=' + ($('#gazelle_options_menu').innerHeight()-10) + 'px'
}, function () { $('#gazelle_options_menu').hide(); });
}
}
/*****************************/
/*** END OPTIONS PAGE CODE ***/
/*****************************/
/* Cache */
function Cache(name, def_value) {
var cache;
return {
serialize: function() {
setDomainLSValue(name, JSON.stringify(cache));
},
unserialize: function() {
cache = jQuery.parseJSON(getDomainLSValue(name, 'false'));
if (!cache) cache = jQuery.extend({}, def_value); /* clone */
return cache;
},
clear: function() {
cache = jQuery.extend({}, def_value); /* clone */
this.serialize();
}
};
}
function registerMenuCommand(oText, oFunc) {
if(/firefox/i.test(navigator.userAgent))
GM_registerMenuCommand(oText, oFunc);
MenuCommandArray[MenuCommandArray.length] = [oText.replace("Gazelle Snatched: ",""),oFunc,oText.replace("Gazelle Snatched: ","").replace(" ","_")];
}
/************************************/
/*** SCRIPT EXECUTION STARTS HERE ***/
/************************************/
/* Get gazelle base URL */
// var whatcd_url_base = document.URL.match(/^(https:\/\/ssl\.what\.cd|https:\/\/what\.cd)/)[1];
var gazelle_url_base = location.protocol + '//' + location.hostname;
/* Create proxy */
var whatcd_proxy = Proxy(gazelle_url_base, 1000);
/* Get user id of this user */
var whatcd_id = (function() {
var m = $('#userinfo_username .username').eq(0).attr('href').match(/user\.php\?id=(\d+)/);
if (m) return m[1];
return null;
})();
if (!whatcd_id) return; /* Exceptional condition: User ID not found */
/* Create status box */
// var server_version = GM_getLSValue("serverVersion", CURRENT_VERSION);
var status = StatusBox('Gazelle Snatched');
var options = doOptionsMenu();
var slideMenuShowing = 0;
/* backup what.cd cache */ /* TODO: Remove this eventually? */
var whatcd_cache = GM_getLSValue('snatch_cache', {});
if (whatcd_cache.length > 5) {
whatcd_cache = jQuery.parseJSON(whatcd_cache);
delete whatcd_cache.torrents;
GM_setLSValue('whatcd_snatched_groups', JSON.stringify(whatcd_cache));
console.warn('Saved what.cd snatched groups list for later use. -- You should not see this message again.');
GM_deleteLSValue('snatch_cache');
}
/* Cache of snatched torrents */
var snatch_cache = Cache('snatch_cache', { groups: {}, torrents: {} });
var bookmark_cache = Cache('bookmark_cache', { groups: {} });
var MenuCommandArray = [];
var hasPageGMloaded = false;
/* Reset command */
registerMenuCommand('Gazelle Snatched: Reset Snatched', function() {
snatch_cache.clear(); bookmark_cache.clear();
setDomainLSValue('last_update', '0');
setDomainLSValue('full_update','1');
setDomainLSValue('fullUpdateStarted','1');
location.reload();
});
/* Update w/o clear */
registerMenuCommand('Gazelle Snatched: Update', function() {
setDomainLSValue('last_update', '0');
setDomainLSValue('full_update','1');
setDomainLSValue('force_all','1');
setDomainLSValue('fullUpdateStarted','1');
location.reload();
});
registerMenuCommand('Gazelle Snatched: Options', function() { DisplaySlideMenu(true); });
doGMMenu();
doOptionsMenu();
/* Scan torrent table in doc and mark links as type in cache */
function scan_torrent_page(doc, type) {
//log(type);
var torrent_table = $(doc).find('#content > .thin > table').eq(0);
if (torrent_table.length == 0) return 0;
var found = 0;
/* Old version: {"groups":{"2417":{"name":"pg.lost - Yes I Am"}}, "torrents":{941290:{type:"snatched", seeding:true}}} */
/* New version: {"groups":{"2417":{"nm":"pg.lost - Yes I Am"}}, "torrents":{941290:{ty:"snatched", sd:1}}} // this was changed to save space */
var d = snatch_cache.unserialize();
torrent_table.find('div.group_info').each(function(i) {
/* Find group and torrent ID */
var group_id;
var torrent_id;
var link = $(this).children('a:last').eq(0);
var m = link.attr('href').match(/torrents\.php\?id=(\d+)&torrentid=(\d+)/);
if (m) {
group_id = m[1];
torrent_id = m[2];
} else {
/* I don't know if we can ever get here! */
log("Not sure how Gazelle Snatched got here. Please notify Mordred with what you were doing");
m = link.attr('href').match(/torrents\.php\?id=(\d+)/);
if (m) {
group_id = m[1];
//link = $(this).children('td').eq(1).children('span').eq(0).children('a').eq(0);
link = $(this).children('td').eq(1).find('span:first a:first').eq(0);
m = link.attr('href').match(/torrents\.php\?action=download&id=(\d+)/);
if (m) torrent_id = m[1];
}
if (!m) {
status.contents().append('
Failed: '+$(this).children('td').eq(1).text()+'
');
z(); //purposely error out
}
}
/* Save in cache */
if (group_id && torrent_id) {
// we are saving a type of "snatched" but when applying that class we have to apply it as "gazelle_snatched" due to gazelle having it's own .snatched style now
if (!d.torrents[torrent_id] ||
(type != 'seeding' && d.torrents[torrent_id].ty != type && !(type!='uploaded' && d.torrents[torrent_id].ty=='uploaded')) || // we have issues if you've snatched a torrent you uploaded, so uploaded takes precendence
(type == 'seeding' && !d.torrents[torrent_id].sd)) {
var reg = $(this).text().match(/.*\s]\s+(.+)\s(\[\d{4}\])\s-/);
if (!reg)
reg = $(this).text().match(/.*\s]\s+(.+)\s-?/);
var nm = jQuery.trim(reg[1]);
//trying alternate method
//log($(this).clone().children('span, div, strong').remove().end().text());
//var nm = jQuery.trim($(this).clone().children('span, div, strong').remove().end().text().match(/(.+)\s(\[|-)/)[1]);
d.groups[group_id] = { nm: nm.replace(/"/g,"'") };
if (type == 'seeding') { /* Special case seeding */
if (d.torrents[torrent_id])
d.torrents[torrent_id].sd = 1;
else
d.torrents[torrent_id] = { ty: 'seeding', sd: 1 };
} else {
if (d.torrents[torrent_id])
d.torrents[torrent_id].ty = type;
else
d.torrents[torrent_id] = { ty: type, sd: 0 };
}
//log ("adding:" + nm + " with group_id="+group_id+", torrent_id="+torrent_id);
found += 1;
}
}
});
if (found == 0) return 0;
snatch_cache.serialize();
return found;
}
function scan_bookmark_page(doc) {
//log ('scanning bookmark page');
var torrent_table = $(doc).find('#torrent_table').eq(0);
if (torrent_table.length == 0) return 0;
var found = 0;
bookmark_cache.clear(); // makes sense not to save bookmarks because they get added/removed a lot and it's just one page
var b = bookmark_cache.unserialize();
torrent_table.find('tr.group.discog').each(function(i) {
/* Find group and torrent ID */
var group_id;
var link = $(this).find('strong a:last').eq(0);
var m = link.attr('href').match(/torrents\.php\?id=(\d+)/);
if (m) {
group_id = m[1];
b.groups[group_id] = 1;
found++;
}
//log (found + ". group_id:" + group_id + " - " + link.text());
});
torrent_table.find('tr.torrent').each(function(i) { // single, non-music torrents show up not in a group
/* Find group and torrent ID */
var group_id;
var link = $(this).find('strong a:last').eq(0);
var m = link.attr('href').match(/torrents\.php\?id=(\d+)/);
if (m) {
group_id = m[1];
b.groups[group_id] = 1;
found++;
}
//log (found + ". group_id:" + group_id + " - " + link.text());
});
bookmark_cache.serialize();
return found;
}
/* Fetch and scan all pages of type, call callback when done */
function scan_all_torrent_pages(type, page_cb, finish_cb, forced_full) {
var page = 1;
var total = 0;
var lastPage = 0;
function request_url() {
if (type == 'bookmark')
return '/bookmarks.php?type=torrents';
else
return '/torrents.php?type='+type+'&userid='+whatcd_id+'&page='+page;
}
function error_handler(response, reason) {
status.contents().append('
Error: Unable to fetch '+type+' page '+page+' ('+reason+')
');
status.show();
finish_cb(total);
}
function page_handler(response) {
if (response.status == 200) {
//pageText = response.responseText.replace(/collageShow.*\);/g,";");
//log (pageText);
var doc = document.implementation.createHTMLDocument('');
doc.documentElement.innerHTML = response.responseText; //.replace(/[\s\S]*<\/head>/,"<\/head>");
page_cb(type, page);
if (forced_full == 1) {
lastPage = 1;
$(doc).find('#content .linkbox').eq(0).find('a:last').each(function(i) {
var pgVal = $(this).attr('href').match(/torrents\.php\?page=(\d+)&type/);
lastPage = pgVal[1];
});
}
if (type == 'bookmark')
var found = scan_bookmark_page(doc);
else
var found = scan_torrent_page(doc, type);
total += found;
if ((found == 0 && forced_full == 0) || (forced_full == 1 && page >= lastPage) || (type == 'bookmark')) { finish_cb(type, total); return; } /* End of asynchronous chain */
page += 1;
whatcd_proxy.get({ url: request_url(), callback: page_handler, error: error_handler });
} else {
error_handler(response, 'HTTP '+response.status);
}
}
whatcd_proxy.get({ url: request_url(), callback: page_handler, error: error_handler });
}
function parse_json_api(type, page_cb, finish_cb) {
function error_handler(response, reason) {
status.contents().append('
Error: Unable to fetch '+type+'s ('+reason+')
');
status.show();
finish_cb(total);
}
// if the API gets expanded to other types, we won't hard code the URL here
jQuery.getJSON('/ajax.php?action=bookmarks&type=torrents', function (data) {
bookmark_cache.clear(); // we don't need to save the old bookmarks
var b = bookmark_cache.unserialize();
jQuery.each(data.response.bookmarks, function (key,val) {
b.groups[val.id] = 1;
//log("id:"+ val.id + " - name:" + val.name);
});
finish_cb(type, data.response.bookmarks.length);
bookmark_cache.serialize();
})
.fail(function(jqXHR, textStatus) {
error_handler("null",textStatus);
});
}
/* Mark all links to torrents that are snatched/uploaded/leeching/seeding/bookmarked */
function mark_snatched_links() {
var d = snatch_cache.unserialize();
var b = bookmark_cache.unserialize();
/* Go through all links */
$('#content a').each(function(i) {
var href = $(this).attr('href');
if (href) {
var group_id;
var torrent_id;
/* Find and mark links to snatched torrents */
var m = href.match(/torrents\.php\?id=(\d+)&torrentid=(\d+)/);
if (m) {
group_id = m[1];
torrent_id = m[2];
} else {
m = href.match(/torrents\.php\?torrentid=(\d+)/);
if (m) {
torrent_id = m[1];
} else {
m = href.match(/torrents\.php\?id=(\d+)/);
if (m) group_id = m[1];
}
}
/* Add classes */
if (group_id && d.groups[group_id] &&
(!torrent_id || !$(this).parent().parent().is('.group_torrent')) && !$(this).is('.post_id')) {
$(this).addClass('group_snatched');
}
if (group_id && b.groups[group_id] && !(/\/bookmarks\.php/.test(document.URL)) &&
!(/\/user\.php/.test(document.URL)) &&
(!torrent_id || !$(this).parent().parent().is('.group_torrent')) && !$(this).is('.post_id')) {
$(this).addClass('gazelle_bookmark');
}
if (torrent_id && d.torrents[torrent_id]) {
if (d.torrents[torrent_id].ty == 'snatched')
$(this).addClass('gazelle_snatched'); // we can't use .snatched anymore because what has now added it's own .snatched class
else if (d.torrents[torrent_id].ty == 'uploaded')
$(this).addClass('gazelle_uploaded');
else if (d.torrents[torrent_id].ty == 'leeching')
$(this).addClass('gazelle_leeching');
if (d.torrents[torrent_id].sd) {
if (d.torrents[torrent_id].ty != 'uploaded')
$(this).addClass('gazelle_seeding gazelle_snatched'); // we're really just marking seeding here, but you can't seed if you haven't snatched so adding that class as well
else
$(this).addClass('gazelle_seeding');
}
}
/* Change text if text is url */
if (('/'+$(this).text()) == $(this).attr('href')
&& group_id && d.groups[group_id] && d.groups[group_id].nm) {
$(this).text(d.groups[group_id].nm);
}
}
});
/* Mark links on album page in torrent table */
if (/what\.cd\/torrents\.php/.test(document.URL)) {
/* Parse search */
var search = {};
var search_list = document.location.search.substring(1).split('&');
for (var i = 0; i < search_list.length; i++) {
var pair = search_list[i].split('=');
search[pair[0]] = pair[1];
}
if (search.id) {
/* Album page */
$('#content .torrent_table:first tr.group_torrent').each(function(i) {
/* Find torrent id */
var torrent_id;
$(this).find('td:first span:first a').each(function(i) {
var href = $(this).attr('href');
if (href) {
var m = href.match(/torrents\.php\?torrentid=(\d+)/);
if (m) {
// the permalink automatically gets the style applied to it, so we need to remove it here and then manually add it to the text below
torrent_id = m[1];
$(this).removeClass('group_snatched gazelle_snatched gazelle_uploaded gazelle_leeching gazelle_seeding');
return false;
}
}
});
if (torrent_id && d.torrents[torrent_id]) {
var link = $(this).find('td:first a:last');
if (d.torrents[torrent_id].ty == 'snatched')
link.addClass('gazelle_snatched'); // we can't use .snatched anymore because what has now added it's own .snatched class
else if (d.torrents[torrent_id].ty == 'uploaded')
link.addClass('gazelle_uploaded');
else if (d.torrents[torrent_id].ty == 'leeching')
link.addClass('gazelle_leeching');
if (d.torrents[torrent_id].sd) {
if (d.torrents[torrent_id].ty != 'uploaded')
link.addClass('gazelle_seeding gazelle_snatched'); // we're really just marking seeding here, but you can't seed if you haven't snatched so setting that class too
else
link.addClass('gazelle_seeding');
}
}
});
}
}
/* Show bookmark link on bookmarked album page */
if (/what\.cd\/torrents\.php\?id/.test(document.URL)) {
var albumName = $('#content > .thin > .header > h2 > span').eq(0);
if (albumName) {
var m = document.URL.match(/torrents\.php\?id=(\d+)/);
if (m) {
group_id = m[1];
if (b.groups[group_id])
albumName.addClass('gazelle_bookmark');
}
}
/* show mark/unmark snatched on album page */
if ($("a.add_bookmark").length && !$("#mark_snatched").length) {
if (d.groups[group_id])
mark_snatched = $('Unmark Snatched');
else
mark_snatched = $('Mark Snatched');
mark_snatched.on("click", function () {
if (d.groups[group_id]) {
delete d.groups[group_id]
mark_snatched.text("Mark Snatched");
}
else {
d.groups[group_id] = { nm: albumName.text().replace(/"/g,"'") };
mark_snatched.text("Unmark Snatched");
}
snatch_cache.serialize();
});
mark_snatched.insertAfter(".add_bookmark");
spacing = $(''); // just used to add spacing
spacing.insertAfter(".add_bookmark");
}
}
}
/* Mark torrent as leeching when download link is clicked */
function mark_download_links() {
$('#content').find('a').each(function(i) {
var href = $(this).attr('href');
if (href) {
/* Find download links */
var m = href.match(/torrents\.php\?action=download&id=(\d+)/);
if (m) {
var torrent_id = m[1];
$(this).click(function(event) {
var d = snatch_cache.unserialize();
d.torrents[torrent_id] = { ty: 'leeching', sd: 0 };
snatch_cache.serialize();
mark_snatched_links();
});
}
}
});
}
function mark_bookmark_links() {
$('#content').find('a').each(function(i) {
var id = $(this).attr('id');
if (id) {
/* Find download links */
var m = id.match(/bookmarklink_torrent_(\d+)/);
if (m) {
//log (m);
var group_id = m[1];
$(this).click(function(event) {
if (!/remove/i.test($(this).text()) && !/unbookmark/i.test($(this).text())) {
var b = bookmark_cache.unserialize();
b.groups[group_id] = 1;
bookmark_cache.serialize();
mark_snatched_links();
} else {
var b = bookmark_cache.unserialize();
delete b.groups[group_id];
bookmark_cache.serialize();
$('#content').find('a.gazelle_bookmark').each(function(i) {
var href = $(this).attr('href');
torrentString = 'torrents.php?id='+group_id;
if (href && href=='torrents.php?id='+group_id) {
$(this).removeClass('gazelle_bookmark');
}
});
$('#content > .thin > .header > h2 > span').eq(0).removeClass('gazelle_bookmark');
}
});
}
}
});
}
/* This function was hacked from a generic one and converted to jQuery to work better with Gazelle Snatched.
If you'd like to see that version it's here: http://userscripts.org/scripts/show/68559 */
function doGMMenu() {
// jQuery Version
if( !MenuCommandArray.length ) { return; }
var mdiv = $('');
$.each(MenuCommandArray, function(i, value) {
if (i+1' + MenuCommandArray[i][0] + '\u00A0\u00A0|\u00A0\u00A0');
else
var mEntry = $('' + MenuCommandArray[i][0] + '');
mEntry.click(function () { MenuCommandArray[i][1](arguments[0]); var e = arguments[0]; e.stopPropagation(); return false; });
mdiv.append(mEntry);
});
status.contents().append(mdiv);
}
/* Scan current page */
if (/\/torrents\.php/.test(document.URL)) {
/* Parse search */
var search = {};
var search_list = document.location.search.substring(1).split('&');
for (var i = 0; i < search_list.length; i++) {
var pair = search_list[i].split('=');
search[pair[0]] = pair[1];
}
var full_update = getDomainLSValue('full_update','0');
if ((search.type == 'snatched' || search.type == 'uploaded' || search.type == 'seeding' || search.type == 'leeching') &&
search.userid == whatcd_id && full_update == 0) {
var scan_status = $('
Scanning current page...
');
status.contents().append(scan_status);
status.show();
/* Scan current page */
var found = scan_torrent_page(document, search.type);
scan_status.children('span').text('Done ('+((found > 0) ? (found+' updates found') : 'no updates found')+')');
status.show(5000);
}
}
if (/what\.cd\/bookmarks\.php(?!.action=edit)/i.test(document.URL)) {
var scan_status = $('
Scanning current page...
');
status.contents().append(scan_status);
status.show();
bookmark_cache.clear();
var found = scan_bookmark_page(document);
scan_status.children('span').text(((found > 0) ? (found+' bookmarks found') : 'no bookmarks found'));
status.show(5000);
}
/* Mark links */
mark_download_links();
mark_bookmark_links();
mark_snatched_links();
/*******************************/
/*** AUTO-UPDATE STARTS HERE ***/
/*******************************/
var now = new Date();
var just_updated = 0;
var last_update = parseInt(getDomainLSValue('last_update', '0'));
var next_update = last_update + global_updateFreq*60*1000;
var full_update = getDomainLSValue('full_update','0');
var forced_full = getDomainLSValue('force_all','0');
// if (scriptVersion != CURRENT_VERSION) {
// log("Script was recently updated to " + CURRENT_VERSION);
// // the script was recently updated
// GM_setLSValue('script_version', CURRENT_VERSION);
// //deleteDomainLSValue('snatch_cache'); // Had to reset this due to changes in the cache structure. Will remove in a version or two.
// deleteDomainLSValue('serverVersion'); // we remove this just to make sure it will be properly retrieved in the future
// deleteDomainLSValue('lastUpdateCheck');
// deleteDomainLSValue('last_update');
// just_updated = 1; // location.reload is called after we reach the end of this function so we don't want the script to continue executing before reloading first
// location.reload();
// }
if (full_update == 1 /*&& !(/what\.cd\/torrents\.php/.test(document.URL))*/) {
deleteDomainLSValue('full_update');
deleteDomainLSValue('last_update');
deleteDomainLSValue('force_all');
next_update = 0;
last_update = 0;
}
if (next_update < now.getTime() && just_updated!=1) {
setDomainLSValue('last_update', now.getTime().toString());
var fullUpdateFinished = getDomainLSValue('fullUpdateStarted', '0');
var jobs = 5;
var total_found = {};
/* Show auto update status */
last_update = 0;
if (last_update == 0) {
var update_status = {
snatched: $('
Updating snatched: Initializing...
'),
uploaded: $('
Updating uploaded: Initializing...
'),
leeching: $('
Updating leeching: Initializing...
'),
seeding: $('
Updating seeding: Initializing...
'),
bookmark: $('
Updating bookmarks: Initializing...
'),
};
for (var type in update_status) status.contents().append(update_status[type]);
status.show();
}
function scan_page_handler(type, page) {
if (last_update == 0) {
update_status[type].children('span').text('Page '+page+'...');
status.show();
}
}
function scan_finished_handler(type, found) {
if (last_update == 0) {
if (type != 'bookmark')
update_status[type].children('span').text('Done ('+((found > 0) ? (found+' updates found') : 'no updates found')+')');
else
update_status[type].children('span').text('Done ('+((found > 0) ? (found+' bookmarks found') : 'no bookmarks found')+')');
}
jobs -= 1;
total_found[type] = found;
if (jobs == 0) {
mark_snatched_links();
if (last_update == 0) {
var total = [];
for (var type in total_found)
if (total_found[type] > 0)
total.push(type+': '+total_found[type]);
status.contents().append('