Gfy

srrdb.user.js

Gfy
Sep 5th, 2011
189
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           srrdb.com
  3. // @author         Gfy
  4. // @namespace      http://www.srrdb.com/
  5. // @description    Selective select.
  6. // @include        http://www.srrdb.com/*
  7. // ==/UserScript==
  8.  
  9. //TODO: strip spaces list search
  10.  
  11. function check() {
  12.     var searchString = document.getElementById('selectString').value.replace(/[ ]/g,'.*');
  13.     if (searchString.substr(0, 5) == 'user:') {
  14.         var usearch = searchString.substr(5);
  15.        
  16.         for (i = 0; i < inputs.length; i++) {
  17.             var uploader = inputs[i].parentNode.parentNode.title;
  18.             if (uploader.indexOf(usearch, 12) > -1) {
  19.                 inputs[i].checked = true;
  20.             }
  21.         }
  22.     } else {
  23.         var test = new RegExp(searchString, 'i');
  24.  
  25.         for (i = 0; i < inputs.length; i++) {
  26.             if (test.test(inputs[i].id.substr(4))) {
  27.                 inputs[i].checked = true;
  28.             }
  29.         }
  30.     }
  31. }
  32.  
  33. function clear() {
  34.     for (i = 0; i < inputs.length; i++) {
  35.         inputs[i].checked = false;
  36.     }
  37. }
  38.  
  39. function addBrowseSearchField() {
  40.     // search field
  41.     var selector = document.createElement('input');
  42.     selector.setAttribute('type', 'text');
  43.     selector.setAttribute('name', 'selectString');
  44.     selector.setAttribute('id', 'selectString');
  45.     selector.setAttribute('style', 'margin-left: 10px');
  46.     selector.addEventListener('keydown', function() {
  47.         if (event.keyCode == 13) { // for enter
  48.             document.getElementById('buttonFilter').click();
  49.         } else if (event.keyCode == 27) { // for escape
  50.             document.getElementById('selectString').value = '';
  51.         }
  52.     }, false);
  53.  
  54.     // button search
  55.     var buttonFilter = document.createElement('input');
  56.     buttonFilter.setAttribute('type', 'button');
  57.     buttonFilter.setAttribute('id', 'buttonFilter');
  58.     buttonFilter.setAttribute('value', 'Select');
  59.     buttonFilter.setAttribute('style', 'margin-left: 3px');
  60.     buttonFilter.addEventListener('click', function() { check(); }, false);
  61.  
  62.     // button clear
  63.     var buttonClear = document.createElement('input');
  64.     buttonClear.setAttribute('type', 'button');
  65.     buttonClear.setAttribute('id', 'buttonClear');
  66.     buttonClear.setAttribute('value', 'Clear');
  67.     buttonClear.setAttribute('style', 'margin-left: 3px');
  68.     buttonClear.addEventListener('click', function() { clear(); }, false);
  69.  
  70.     // put them on the page
  71.     var content = document.getElementById('right').firstElementChild;
  72.     if (content) {
  73.         var rel = content.getElementsByTagName('tr')[0].children[1]; // TODO: test if it exists
  74.         rel.appendChild(selector);
  75.         rel.appendChild(buttonFilter);
  76.         rel.appendChild(buttonClear);
  77.     }
  78. }
  79.  
  80. // for GreaseMonkey compatibility
  81. if (typeof unsafeWindow != "undefined") {
  82.     window = unsafeWindow;
  83. }
  84. //"Opera’s implementation appears to be just perfect..."
  85. //http://frans.lowter.us/archives/2006/07/13/opera-user-js-and-greasemonkey-interoperability/
  86.  
  87. /**
  88.  * When the site loads, check which page we are and add functionality.
  89.  */
  90. window.addEventListener(
  91.   'load',
  92.   function (e) {
  93.     /*
  94.     * additions for the *release list*  page
  95.     */
  96.     if( document.documentURI.match("browse.php") ) {
  97.         addBrowseSearchField();
  98.     }
  99.    
  100.     if( document.documentURI.match("addfile.php") ) {
  101.         //document.getElementById('folder').value = 'Sample';
  102.         document.getElementById('folder').select();
  103.     }
  104.    
  105.     //http://www.srrdb.com/admin_comparedupes.php?release=
  106.     //http://www.srrdb.com/details.php?release=
  107.     //http://www.srrdb.com/download.php?release=
  108.     if( document.documentURI.match("admin_comparedupes.php") ) {
  109.         firstDiv = document.getElementsByTagName('div')[0];
  110.         var link = document.createElement('a');
  111.         link.setAttribute('href', document.documentURI.replace('admin_comparedupes', 'details'));
  112.         link.setAttribute('target', '_blank');
  113.         link.innerHTML = 'SRR';
  114.         firstDiv.appendChild(link);
  115.         var link = document.createElement('a');
  116.         link.setAttribute('href', document.documentURI.replace('admin_comparedupes', 'download'));
  117.         //link.setAttribute('target', '_blank');
  118.         link.innerHTML = '&nbsp;Download';
  119.         firstDiv.appendChild(link);
  120.     }
  121.    
  122.     // remove # crap that makes the window jump
  123.     links = document.getElementsByTagName("a");
  124.     for (i = 0; i < links.length; i = i + 1) {
  125.         idx = links[i].href.indexOf("#");
  126.         if (idx > 0) {
  127.             //links[i].href = links[i].href.substring(0, idx);
  128.         }
  129.     }
  130.   },
  131.   false
  132. );
RAW Paste Data