Guest User

Fix Customs Forge Search Page's Download links (Version 3.2)

a guest
Sep 29th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.2
  10. // @grant       none
  11. // ==/UserScript==
  12.  
  13.  
  14. function fixlinks () {
  15.    
  16.     var trs=document.querySelectorAll('#songs_table tr.odd,#songs_table tr.even');
  17.     var songtd;
  18.     qlink=document.createElement('a');
  19.  
  20.     // bigger search "button"
  21.     qlink.innerHTML='<b>[ S ]</b>';
  22.  
  23.     for(i=0;i<trs.length;i++) {
  24.         songtd=trs[i].getElementsByTagName('td')[2];
  25.         dllink=trs[i].querySelector('img.dl').parentNode.href;
  26.         if(dllink.match(/r(\d+)$/)){
  27.             qlink.href=songtd.getElementsByTagName('a')[0].href;
  28.             qlink.title='Check for more versions of this song';
  29.             songtd.appendChild(qlink.cloneNode(true));
  30.             songtd.getElementsByTagName('a')[0].href=dllink;
  31.             songtd.getElementsByTagName('a')[0].title='Song Info';
  32.  
  33.             // send new link to right
  34.             songtd.getElementsByTagName('a')[1].setAttribute("style", "float:right;");
  35.  
  36.             trs[i].querySelector('img.dl').parentNode.href='http://customsforge.com/process.php?id='+dllink.match(/r(\d+)$/)[1];
  37.             trs[i].querySelector('img.dl').parentNode.title="Download Page";
  38.            
  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);
Add Comment
Please, Sign In to add comment