Shoutbox Everywhere

Press L to toggle the shoutbox anywhere in the Hard Drop Forum

当前为 2014-09-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Shoutbox Everywhere
  3. // @description Press L to toggle the shoutbox anywhere in the Hard Drop Forum
  4. // @include http://harddrop.com/*
  5. // @version 0.0.1.20140925095318
  6. // @namespace https://greasyfork.org/users/2233
  7. // ==/UserScript==
  8.  
  9. /*** Settings ***/
  10.  
  11. var display_sb_on_page_load = false // whether to display the shoutbox upon opening a page
  12. var shoutbox_width = Math.floor(window.innerWidth/4) // width in pixel
  13. var shoutbox_height = window.innerHeight // height in pixel
  14. var hotkey = 76 // use "http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes" to find the keycode you want. 76 == L
  15.  
  16. /*** End of Settings ***/
  17.  
  18. var wnd = window
  19. var doc = wnd.document
  20. var loc = location
  21. var href = loc.href
  22.  
  23. if(/\/shout.php\b/.test(href) || /harddrop\.com\/?$/.test(href)) { throw 'exit' }
  24.  
  25. var sb_frm = doc.createElement('IFRAME')
  26. sb_frm.id = 'sb_frm'
  27. sb_frm.src = 'http://harddrop.com/file/shout/shout.php'
  28. sb_frm.width = shoutbox_width
  29. sb_frm.height = shoutbox_height
  30. sb_frm.frameBorder = 0
  31.  
  32. var sb_div = doc.createElement('DIV')
  33. sb_div.id = 'sb_div'
  34. sb_div.style.cssText = 'top:15px; right:0px; position:fixed; background-color:white; z-index:100'
  35. sb_div.appendChild(sb_frm)
  36. doc.body.appendChild(sb_div)
  37.  
  38. if(display_sb_on_page_load) { sb_div.style.visibility = 'visible' }
  39. else { sb_div.style.visibility = 'hidden' }
  40.  
  41. var toggle_sb = function() {
  42. var sb_div = doc.getElementById('sb_div')
  43. if(sb_div.style.visibility != 'hidden') { sb_div.style.visibility = 'hidden'; return }
  44. sb_div.style.visibility = 'visible'
  45. }
  46. addEventListener('keydown', function(evt) { if((evt.target.tagName!='INPUT') && (evt.target.tagName!='TEXTAREA') && (evt.keyCode == hotkey)) { toggle_sb() } }, false)