Guest User

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

a guest
Sep 26th, 2014
397
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
  10. // @grant       none
  11. // ==/UserScript==
  12.  
  13. function fixlinks () {
  14.  //console.log('customsforge userscript startup');
  15.  
  16.   var trs=document.querySelectorAll('#songs_table tr.odd,#songs_table tr.even');
  17.   var songtd;
  18.   qlink=document.createElement('a');
  19.   qlink.innerHTML='&nbsp;<b>?</b>';
  20.   for(i=0;i<trs.length;i++) {
  21.     songtd=trs[i].getElementsByTagName('td')[2];
  22.     dllink=trs[i].querySelector('img.dl').parentNode.href;
  23.     if(dllink.match(/r(\d+)$/)){
  24.       qlink.href=songtd.getElementsByTagName('a')[0].href;
  25.       qlink.title='Check for more versions of this song';
  26.       songtd.appendChild(qlink.cloneNode(true));
  27.       songtd.getElementsByTagName('a')[0].href=dllink;
  28.       songtd.getElementsByTagName('a')[0].title='Song Info';
  29.       trs[i].querySelector('img.dl').parentNode.href='http://customsforge.com/process.php?id='+dllink.match(/r(\d+)$/)[1];
  30.       trs[i].querySelector('img.dl').parentNode.title="Download Page";
  31.     }
  32.   }
  33. }
  34.  
  35. function onNodeInserted() {
  36.   if(document.querySelector('.cfinfolink'))
  37.     return;
  38.   else
  39.     window.setTimeout(fixlinks,1000);
  40. }
  41.  
  42. window.setTimeout(fixlinks,1000);
  43. document.addEventListener('DOMNodeInserted', onNodeInserted, false);
RAW Paste Data