Chessax

e621 swimmer updated

Jun 25th, 2016
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name             E621 Swimmer
  3. // @description      Navigate e621's pools with arrow keys
  4. // @include          http*://e621.net/post/show/*
  5. // ==/UserScript==
  6. window.onLoad = checkForPool();
  7. function checkForPool()
  8. {
  9.     var tags = document.getElementsByTagName('h6');
  10.     for (var i = 0; i < tags.length; ++i)
  11.     {
  12.         if (tags[i].innerHTML === 'Pool')
  13.         {
  14.             var parent = tags[i].parentNode;
  15.             var innerTags = parent.getElementsByTagName('a');
  16.             document.addEventListener('keydown', function (e)
  17.             {
  18.                 //Uncomment any of these if some modifier key is wanted,
  19.                 // uncommenting all three will require all three to be pressed
  20.                 //if (!e.shiftKey){ return; }
  21.                 //if (!e.ctrlKey){ return; }
  22.                 //if (!e.metaKey){ return; }
  23.                
  24.                 //Return if target is a text field (where text navigation takes precedence)
  25.                 var t = e.srcElement || e.target;
  26.                 var tagName = t.tagName.toUpperCase();
  27.                 var type = '';
  28.                 if (t.type){
  29.                     type = t.type.toUpperCase();
  30.                 }
  31.                 if ((tagName === 'INPUT' &&
  32.                      (
  33.                     type === 'TEXT' ||
  34.                     type === 'PASSWORD' ||
  35.                     type === 'SEARCH' ||
  36.                     type === 'EMAIL' ||
  37.                     type === 'NUMBER' ||
  38.                     type === 'DATE' )
  39.                      ) ||
  40.                     tagName === 'TEXTAREA')
  41.                 {
  42.                     return;
  43.                 }
  44.                
  45.                 var p = innerTags[1];
  46.                 var n = p;
  47.                 if (innerTags.length > 2){
  48.                     n = innerTags[2];
  49.                 }
  50.                 if (e.keyCode === 37 && p.innerHTML.substring(0, 8) == "&lt;&lt;")
  51.                 {
  52.                     window.location=p.href;
  53.                 }
  54.                 else if (e.keyCode === 39 && n.innerHTML.substring(n.innerHTML.length-8, n.innerHTML.length) == "&gt;&gt;")
  55.                 {
  56.                     window.location=n.href;
  57.                 }
  58.             }, false);
  59.             break;
  60.         }
  61.     }
  62. }
Add Comment
Please, Sign In to add comment