ogenerationify

olds' generation

  1. // ==UserScript==
  2. // @name ogenerationify
  3. // @version 4.1999.5
  4. // @description olds' generation
  5. // @include https://*hkgalden.com/view*
  6. // @include http://*hkgalden.com/view*
  7. // @copyright 1999
  8. // @namespace 1999oldman
  9. // ==/UserScript==
  10.  
  11. String.prototype.repeat = function(num){
  12. return new Array(num + 1).join(this);
  13. };
  14. String.prototype.insertAt = function(idx,str){
  15. return this.substr(0, idx) + str + this.substr(idx);
  16. };
  17. var rand = function(min,max){
  18. return Math.floor(Math.random() * (max - min + 1) + min);
  19. };
  20. var getRandBool = function(){
  21. return Math.round(Math.random()) < 1;
  22. };
  23. var getRandEmotion = function(){
  24. var a = ['[369]','#adore#','#yup#','O:-)',':-[','#ass#','[banghead]',':D','[bomb]','[bouncer]','[bouncy]','#bye#','[censored]','#cn#',':o)',':~(','xx(',':-]','#ng#','#fire#','[flowerface]',':-(','fuck','@_@','#good#','#hehe#','#hoho#','#kill2#','#kill#','^3^','#love#','#no#','[offtopic]',':O','[photo]','[shocking]','[slick]',':)','[sosad]','#oh#',':P',';-)','???','?_?','[yipes]','Z_Z'];
  25. return a[Math.floor(Math.random() * a.length)];
  26. };
  27. var getRandStrike = function(){
  28. return getRandBool() ? '=' : '-';
  29. };
  30. var getRandQuote = function(){
  31. return getRandBool() ? (getRandBool() ?['(((',')))'] : [' >>> ','>>> ']) : (getRandBool() ? ['[',']'] : [' ',' ']);
  32. };
  33. var ogenerationify = function(text){
  34. var rq = getRandQuote();
  35. text = text.replace(/唔/g, getRandBool() ? '吾' : '唔')
  36. .replace(/但/g, 'but')
  37. .replace(/女/g, '囡')
  38. .replace(/我/g, '阿叔' + (getRandBool() ? '' : '我'))
  39. .replace(/係/g, getRandBool() ? '糸' : '係')
  40. .replace(/喎/g, '咼')
  41. .replace(/好/g, '#good#')
  42. .replace(/撚(頭|樣)/g, '蒙$1')
  43. .replace(/老一輩/g, '老#good#輩')
  44. .replace(/啦/g, 'la')
  45. .replace(/子|仔/g, getRandBool() ? '仔' : '囝')
  46. .replace(/ {2,}(.+?) {2,}/, ' '+rq[0]+' $1 '+rq[1]+' ');
  47. var startStrike = getRandStrike().repeat(rand(4,16));
  48. text = startStrike + (getRandBool() ? '\n' : ' ') + text;
  49. for(var i = 0; i < rand(1, Math.round(text.length / 2)); i++){
  50. var rp = rand(0, text.length - 1);
  51. if(text.charCodeAt(rp) > 255 || /(\s|=|-)/.test(text.charAt(rp))){
  52. var rc = getRandBool() ? (getRandBool() ? getRandEmotion() : ' ') : (getRandBool() ? (Math.round(Math.random() * 10) > 6 ? ' ' : '\n') : (getRandBool() ? '..'.repeat(2,4) : getRandStrike().repeat(rand(1,8))));
  53. text = text.insertAt(rp, rc);
  54. }
  55. }
  56. text += getRandBool() ? getRandEmotion() : getRandEmotion() + getRandStrike().repeat(rand(4,16));
  57. return text;
  58. };
  59.  
  60. setTimeout(function(){
  61. $('#fast_reply [id*="submit_fast_reply"]').click();
  62. $('#fpy').removeClass('fcs');
  63. $('#hkga-noti').empty();
  64. var clickEvts = $.grep($._data(document, 'events').click, function(e){
  65. return e.selector && e.selector.indexOf('submit_fast_reply') > 0 && e.handler.toString().indexOf('/ajax/fastreply') > 0;
  66. });
  67. unsafeWindow.ogenerationified = !1;
  68. for(var i = 0; i < clickEvts.length; i++){
  69. var origHandler = clickEvts[i].handler,
  70. origSelector = clickEvts[i].selector;
  71. clickEvts[i].handler = function(e){
  72. e.preventDefault();
  73. var ctn = $('#gae #ta');
  74. ctn.val(ogenerationify(ctn.val()));
  75. if(origSelector.indexOf('temp') < 0) origHandler(e);
  76. };
  77. }
  78. },1000);