Drupal Hotkeys

Using a pre-defined hotkey, quickly switch from HTTPS to HTTP or vice versa.

  1. // ==UserScript==
  2. // @name Drupal Hotkeys
  3. // @namespace kirkland
  4. // @version 0.1.2
  5. // @include *://*rit.edu*
  6. // @description Using a pre-defined hotkey, quickly switch from HTTPS to HTTP or vice versa.
  7. // ==/UserScript==
  8.  
  9. var map = [],
  10.  
  11.  
  12. switchHTTPS = function()
  13. {
  14. var targetURL = new String();
  15.  
  16. targetURL = window.location.href;
  17.  
  18. if (targetURL.indexOf("https") >= 0)
  19. {
  20. targetURL = targetURL.replace(/https:\/\//, "http://");
  21. } else {
  22. targetURL = targetURL.replace(/http:\/\//, "https://");
  23. }
  24. window.location.href = targetURL;
  25. },
  26.  
  27.  
  28. currentPageSaveable = function()
  29. {
  30. var url = window.location.href,
  31. page = "",
  32. drupal_editables = {
  33. // drupal structure type: Drupal "save" button
  34. 'node': 'edit-submit',
  35. 'view': 'edit-actions-save',
  36. 'menu': 'edit-actions-submit',
  37. 'block': 'edit-submit'
  38. };
  39.  
  40. if (url.match(/\/node\/[0-9]+\/edit/))
  41. {
  42. console.log('matches node edit');
  43. return drupal_editables.node;
  44. } else if (url.match(/\/structure\/views\/view\/.*/))
  45. {
  46. console.log('matches view edit');
  47. return drupal_editables.view;
  48. } else if (url.match(/\/structure\/menu\/manage\/.*/))
  49. {
  50. console.log('matches menu edit');
  51. return drupal_editables.menu;
  52. } else if (url.match(/\/structure\/block\/manage\/block\/[0-9]+/))
  53. {
  54. console.log('matches block edit');
  55. return drupal_editables.block;
  56. }
  57.  
  58. return false;
  59. };
  60.  
  61.  
  62. onkeydown = onkeyup = function(e){
  63. e = e || event; // to deal with IE
  64. map[e.keyCode] = e.type == 'keydown';
  65.  
  66. if((map[17] || map[91]) && map[16] && map[83]) { // (CTRL or CMD)+SHIFT+S
  67. switchHTTPS();
  68. }
  69.  
  70. if((map[17] || map[91]) && map[83]) // (CTRL || CMD) + S
  71. {
  72. if(clickThis = currentPageSaveable())
  73. {
  74. document.getElementById(clickThis).click();
  75. return false;
  76. }
  77. }
  78.  
  79. // This code taken from Stack Overflow:
  80. // Author: B1KMusic
  81. // Question: http://stackoverflow.com/questions/5203407/javascript-multiple-keys-pressed-at-once
  82. // Changes have been made
  83. // License: CC by-sa 3.0
  84. };