TorViet Shoutbox Enhancer

A small script to simplify the shoutbox

目前为 2015-05-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name TorViet Shoutbox Enhancer
  3. // @namespace http://torviet.com/userdetails.php?id=1662
  4. // @version 0.4.14
  5. // @license http://www.wtfpl.net/txt/copying/
  6. // @homepageURL https://github.com/S-a-l-a-d/TorViet-Shoutbox-Enhancer
  7. // @supportURL https://github.com/S-a-l-a-d/TorViet-Shoutbox-Enhancer/issues
  8. // @icon http://torviet.com/pic/salad.png
  9. // @description A small script to simplify the shoutbox
  10. // @author Salad
  11. // @match http://torviet.com/qa.php*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. $(function(){
  16. // Remove unneeded elements.
  17. $('#boxHead, .marquee, #sltTheme, #clock').remove();
  18.  
  19. // Alter existing element CSS.
  20. var windowHeight = $(window).height();
  21. var remainingHeight = $('.input-section').parent().height() + $('.navigation_page').height();
  22.  
  23. $('.all-wrapper').css({
  24. 'background-image': 'none',
  25. 'margin': 'auto',
  26. 'height': windowHeight
  27. });
  28. $('.input-section').parent().css('padding', '0px');
  29. $('.navigation_page').css('width', 'auto');
  30. $('#boxQuestion').css('height', windowHeight - remainingHeight - 20);
  31. $('#emo-section').css('height', windowHeight - remainingHeight - 22);
  32. $('.slimScrollDiv, .emo-group-detail').css('height', windowHeight - remainingHeight - 32);
  33.  
  34. // Alter existing elements.
  35. $('.emo-group-detail').empty();
  36. $('.emo-group-detail').append(getEmoticons(524, 574));
  37. $('.emo-group-detail').append(getEmoticons(707));
  38. $('.emo-group-detail').append(getEmoticons(200, 234));
  39.  
  40. // Add elements.
  41. var myScript = document.createElement('script');
  42. myScript.type = 'text/javascript';
  43. myScript.innerHTML = 'function toggleEmoSlt(){$(".emo-group-title-wrapper").slideToggle();}';
  44. $('.input-section-a').append(myScript);
  45. $('.input-section-a').append('<input type="button" value="Toggle" onclick="toggleEmoSlt()" />');
  46.  
  47. // Firefox detection.
  48. if (typeof InstallTrigger !== 'undefined')
  49. $(window).keypress(changeEmoGroup);
  50. else
  51. $(window).keydown(changeEmoGroup);
  52.  
  53. // Override functions.
  54. $('a.btuEmotion').click(function() {
  55. $('#idQuestion').get(0).value += $(this).attr('alt');
  56. $('#idQuestion').focus();
  57. });
  58.  
  59. // Custom functions.
  60. function getEmoticons(start, end) {
  61. var emos = '';
  62.  
  63. if (end === undefined)
  64. emos = '<div style="height:43px;width:43px;float:left;display:inline-block;margin:1px;"><a style="margin:0px 0px 0px 0px;" class="btuEmotion" alt="[em' + start +
  65. ']"><img style="max-width: 43px; max-height: 43px" src="/pic/smilies/' + start +
  66. '.gif" alt=""></a></div>';
  67. else
  68. for (i = start; i <= end; i++)
  69. emos += '<div style="height:43px;width:43px;float:left;display:inline-block;margin:1px;"><a style="margin:0px 0px 0px 0px;" class="btuEmotion" alt="[em' + i +
  70. ']"><img style="max-width: 43px; max-height: 43px" src="/pic/smilies/' + i +
  71. '.gif" alt=""></a></div>';
  72.  
  73. return emos;
  74. }
  75.  
  76. function changeEmoGroup(e) {
  77. switch (e.keyCode) {
  78. case 40:
  79. $('#emogroup option:selected').next().prop('selected', true);
  80. $('#emogroup').change();
  81. break;
  82. case 38:
  83. $('#emogroup option:selected').prev().prop('selected', true);
  84. $('#emogroup').change();
  85. break;
  86. default:
  87. }
  88. }
  89.  
  90. // Run at startup.
  91. toggleEmoSlt();
  92. $('#idQuestion').focus();
  93. });