forked from pjobson/pjUserscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RSR_fixes.user.js
67 lines (59 loc) · 1.5 KB
/
RSR_fixes.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// ==UserScript==
// @name RSR Fixes
// @namespace http://jobson.us
// @include http://www.rsrgroup.com/catalog/search*
// @version 1
// ==/UserScript==
var $ = unsafeWindow.$;
var assc;
var baseUrl = window.location.href;
var totalRes = 0;
var pages = 0;
var curPageSet = 0;
var rsrfixes = {
init: function() {
rsrfixes.scanPages();
},
scanPages: function() {
if ($('div.pagination').html().trim() === "") return;
totalRes = parseInt($('p.show-results').html().match(/of (\d+)/)[1],10);
pages = Math.ceil(totalRes/30);
rsrfixes.loadNextPage();
$('div.pagination').empty();
$('p.show-results').empty();
},
loadNextPage: function() {
curPageSet += 30;
if (totalRes-curPageSet < 0) {
rsrfixes.nixAllocated();
return;
};
var url = baseUrl+curPageSet;
$.ajax({
url: url,
type: "get",
data: 'subpage',
success: function(html){
var items = $(html).find('form div.closed-results-row');
$('form[name="itemlist"]').append($(items));
rsrfixes.loadNextPage();
}
});
},
nixAllocated: function() {
$('form div.closed-results-row').each(function() {
var avail = $(this).find('p.availability').html().replace(/<.+?>/g,'').replace(/[\r\n\t]/g,'');
if (/:Allocated/.test(avail) || /:0 units/.test(avail)) {
$(this).hide();
}
});
}
}
$(document).ajaxSuccess(function(ev,http,args) {
if (args.data === "subpage") return;
if (assc) {
clearTimeout(assc);
}
assc = setTimeout(rsrfixes.init,1500);
});
$( document ).ready(rsrfixes.init);