Advertisement
Drakia

Untitled

Jun 1st, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name BlackCats Customizer
  3. // @description Used to fix problems with Blackcats Games v1.01
  4. // @match http://www.blackcats-games.net/browse.php*
  5. // @include http://www.blackcats-games.net/browse.php*
  6. // ==/UserScript==
  7.  
  8. // Used so we can load jQuery before we start our script.
  9. function main() {
  10.     // Configuration stuff
  11.     var rightIcons = true;
  12.     var resizeBoxart = true;
  13.  
  14.     // ******* Code following, do not modify **********/
  15.  
  16.     // Helper Functions
  17.     function addGlobalStyle(CSS) {
  18.         var head = document.getElementsByTagName("head")[0];
  19.         if (!head) {
  20.             alert("NoHead");
  21.             return;
  22.         }
  23.         var style = document.createElement("style");
  24.         style.type = "text/css";
  25.         style.innerHTML = CSS;
  26.         head.appendChild(style);
  27.     }
  28.     function addScript(JS) {
  29.         var head = document.getElementsByTagName("head")[0];
  30.         if (!head) return;
  31.         var script = document.createElement("script");
  32.         script.type = "text/javascript";
  33.         script.innerHTML = JS;
  34.         head.appendChild(script);
  35.     }
  36.     function nextTextNode(obj) {
  37.         var i = 0;
  38.         while(obj.nodeType != 3 || obj.data.trim() == "" && i++ < 100)
  39.             obj = obj.nextSibling;
  40.  
  41.         if (i == 100) obj = null;
  42.         return obj;
  43.     }
  44.     // Inject our own CSS
  45.     addGlobalStyle("\
  46.        .new {color: #ff0000; font-weight: bold;}\
  47.        .torrentlink {clear: both; font-weight: bold;}\
  48.        .imglink {padding-left: 5px; padding-right: 5px; float: right;}\
  49.        .date {color: #cccccc; font-style: italic; display: block;}\
  50.        ");
  51.  
  52.     // Layout Variables
  53.     var Search = false;
  54.     var Theme = "ICGStation";
  55.  
  56.     // Determine theme
  57.     var Stylesheet = document.getElementsByTagName("link")[0];
  58.     if (Stylesheet.href == "http://www.blackcats-games.net/themes/ICGstation/ICGstation.css") {
  59.         Theme = "ICGStation";
  60.     } else if (Stylesheet.href == "http://www.blackcats-games.net/themes/naito/naito.css") {
  61.         Theme = "Naito";
  62.     }
  63.  
  64.     // Check if we're searching
  65.     if (window.location.href.indexOf('search') != -1)
  66.         Search = true;
  67.  
  68.     // Find the table that contains the torrent list.
  69.     var ConTables = document.getElementById("pagescontainer").getElementsByTagName("table");
  70.     var TorrentList = null;
  71.     for (var i = 0; i < ConTables.length; i++) {
  72.         // Fetch the inner text of the first td tag.
  73.         var InText = ConTables[i].getElementsByTagName("td")[0].innerText;
  74.         // "BoxArt" means we found the torrent list.
  75.         if (InText != "Boxart") continue;
  76.         TorrentList = ConTables[i].getElementsByTagName("tr");
  77.         break;
  78.     }
  79.     // Enter block if we found the list of torrents
  80.     if (TorrentList != null) {
  81.         for (var i = 1; i < TorrentList.length; i++) {
  82.             // Easiest way to re-arrange the box is rebuild it!
  83.             if (rightIcons) {
  84.                 // Get data
  85.                 tData = TorrentList[i].getElementsByTagName("td")[2];
  86.                 tLinks = tData.getElementsByTagName("a");
  87.  
  88.                 torrentSticky = false;
  89.                 if (tLinks[0].getElementsByTagName("img").length != 0)
  90.                     torrentSticky = true;
  91.                 torrentName = tLinks[0].innerText;
  92.                 torrentLink = tLinks[0].href;
  93.                 torrentNew = false;
  94.                 if (tData.getElementsByTagName("img")[0].src == "http://www.blackcats-games.net/pic/new.png" ||
  95.                     tData.getElementsByTagName("img")[1].src == "http://www.blackcats-games.net/pic/new.png")
  96.                     torrentNew = true;
  97.                 torrentDownload = tLinks[1].href;
  98.                 torrentBookmark = tLinks[2].href;
  99.                 torrentDate = nextTextNode(tLinks[0]).data;
  100.  
  101.                 var td = document.createElement("td");
  102.  
  103.                 // Torrent Link
  104.                 var newTorrentData = '';
  105.                 var link = '<a href="' + torrentLink + '" class="torrentlink">' + torrentName;
  106.                 if (torrentNew)
  107.                     link += ' (<span class="new">NEW</span>)';
  108.                 if (torrentSticky)
  109.                     link = '<img class="imglink" src="http://www.blackcats-games.net/pic/sticky.gif"/>' + link;
  110.                 link += '</a></b>';
  111.                 newTorrentData = link;
  112.  
  113.                 // Torrent Upload Date
  114.                 var upload = '<span class="date">' + torrentDate + '</span>';
  115.                 newTorrentData += upload;
  116.                
  117.                 // Download/Bookmark links
  118.                 var download = '<a href="' + torrentDownload + '"><img src="pic/save.PNG" class="imglink" /></a>';
  119.                 newTorrentData += download;
  120.                 var bookmark = '<a href="' + torrentBookmark + '"><img src="/pic/book_open.png" class="imglink" /></a>';
  121.                 newTorrentData += bookmark;
  122.                 td.innerHTML = newTorrentData;
  123.                 TorrentList[i].replaceChild(td, tData);
  124.             }
  125.             if (resizeBoxart) {
  126.                 boxArt = TorrentList[i].getElementsByTagName("td")[0].getElementsByTagName("img")[0];
  127.                 boxArt.style.height = "64px";
  128.                 boxArt.style.width = "64px";
  129.             }
  130.         }
  131.     }
  132. }
  133.  
  134. // Load jQuery using a callback workaround for Chrome. Thanks to Erik Vold (http://erikvold.com/blog/index.cfm/2010/6/14/using-jquery-with-a-user-script)
  135. function loadJQuery(callback) {
  136.     var jq = document.createElement("script");
  137.     jq.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
  138.     jq.addEventListener('load', function() {
  139.         var script = document.createElement("script");
  140.         script.textContent = "(" + callback + ")();";
  141.         document.body.appendChild(script);
  142.     }, false);
  143.     document.body.appendChild(jq);
  144. }
  145.  
  146. // Load jQuery and execute main()
  147. loadJQuery(main);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement