View difference between Paste ID: truR7YUh and SKuYDmFr
SHOW: | | - or go back to the newest paste.
1
// ==UserScript==
2
// @name        Fix Customs Forge Search Page's Download links
3
// @namespace   CustomsForge
4
// @description Fixes the download links on the CustomsForge.com search page
5
// @include     http://search.customsforge.com/
6
// @include     https://search.customsforge.com/
7
// @include     http://search.customsforge.com/*
8
// @include     https://search.customsforge.com/*
9-
// @version     3
9+
// @version     3.2
10
// @grant       none
11
// ==/UserScript==
12
13
14-
 //console.log('customsforge userscript startup');
14+
15-
  
15+
	
16-
  var trs=document.querySelectorAll('#songs_table tr.odd,#songs_table tr.even');
16+
	var trs=document.querySelectorAll('#songs_table tr.odd,#songs_table tr.even');
17-
  var songtd;
17+
	var songtd;
18-
  qlink=document.createElement('a');
18+
	qlink=document.createElement('a');
19-
  qlink.innerHTML='&nbsp;<b>?</b>';
19+
20-
  for(i=0;i<trs.length;i++) {
20+
	// bigger search "button"
21-
    songtd=trs[i].getElementsByTagName('td')[2];
21+
	qlink.innerHTML='<b>[ S ]</b>';
22-
    dllink=trs[i].querySelector('img.dl').parentNode.href;
22+
23-
    if(dllink.match(/r(\d+)$/)){
23+
	for(i=0;i<trs.length;i++) {
24-
      qlink.href=songtd.getElementsByTagName('a')[0].href;
24+
		songtd=trs[i].getElementsByTagName('td')[2];
25-
      qlink.title='Check for more versions of this song';
25+
		dllink=trs[i].querySelector('img.dl').parentNode.href;
26-
      songtd.appendChild(qlink.cloneNode(true));
26+
		if(dllink.match(/r(\d+)$/)){
27-
      songtd.getElementsByTagName('a')[0].href=dllink;
27+
			qlink.href=songtd.getElementsByTagName('a')[0].href;
28-
      songtd.getElementsByTagName('a')[0].title='Song Info';
28+
			qlink.title='Check for more versions of this song';
29-
      trs[i].querySelector('img.dl').parentNode.href='http://customsforge.com/process.php?id='+dllink.match(/r(\d+)$/)[1];
29+
			songtd.appendChild(qlink.cloneNode(true));
30-
      trs[i].querySelector('img.dl').parentNode.title="Download Page";
30+
			songtd.getElementsByTagName('a')[0].href=dllink;
31-
    }
31+
			songtd.getElementsByTagName('a')[0].title='Song Info';
32-
  }
32+
33
			// send new link to right
34
			songtd.getElementsByTagName('a')[1].setAttribute("style", "float:right;");
35
36-
  if(document.querySelector('.cfinfolink'))
36+
			trs[i].querySelector('img.dl').parentNode.href='http://customsforge.com/process.php?id='+dllink.match(/r(\d+)$/)[1];
37-
    return;
37+
			trs[i].querySelector('img.dl').parentNode.title="Download Page";
38-
  else 
38+
			
39-
    window.setTimeout(fixlinks,1000);
39+
			// send play button to right
40
			var ytButton = songtd.firstChild;
41
			if (typeof ytButton !== "undefined") {
42
				if ((ytButton.tagName == 'DIV') && (ytButton.id.substr(0, 3) == "yt_") ) {
43
					parent = ytButton.parentNode,
44
					prev = ytButton.previousSibling,
45
					oldChild = parent.removeChild(ytButton);
46
					oldChild.setAttribute('style', 'float:right;');
47
					parent.insertBefore( oldChild, prev );
48
				}
49
			}
50
		}
51
		else {
52
			// for official dlc
53
			var ytButton = songtd.firstChild;
54
			if (typeof ytButton !== "undefined") {
55
				if ((ytButton.tagName == 'DIV') && (ytButton.id.substr(0, 3) == "yt_") ) {
56
					parent = ytButton.parentNode,
57
					prev = ytButton.previousSibling,
58
					oldChild = parent.removeChild(ytButton);
59
					oldChild.setAttribute('style', 'float:right;padding-right: 24px;');
60
					parent.insertBefore( oldChild, prev );
61
				}
62
			}
63
		}
64
	}
65
}
66
67
function onNodeInserted() {
68
	if(document.querySelector('.cfinfolink')) {
69
		return;
70
	}
71
	else {
72
		window.setTimeout(fixlinks,1000);
73
	}
74
}
75
76
window.setTimeout(fixlinks,1000);
77
document.addEventListener('DOMNodeInserted', onNodeInserted, false);