ogenerationify

olds' generation

当前为 2014-10-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name ogenerationify
  3. // @version 3.1999
  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. for(var i = 0; i < rand(1, Math.round(text.length / 2)); i++){
  35. var rp = rand(0, text.length - 1);
  36. if(text.charCodeAt(rp) > 255 || /(\s|=|-)/.test(text.charAt(rp))){
  37. var rc = getRandBool() ? (getRandBool() ? getRandEmotion() : ' ') : (getRandBool() ? (Math.round(Math.random() * 10) > 6 ? ' ' : '\n') : (getRandBool() ? '..'.repeat(2,4) : getRandStrike().repeat(rand(1,8))));
  38. text = text.insertAt(rp, rc);
  39. }
  40. }
  41. var rq = getRandQuote();
  42. text = text.replace(/唔/g, getRandBool() ? '吾' : '唔')
  43. .replace(/但/g, 'but')
  44. .replace(/女/g, '囡')
  45. .replace(/我/g, '阿叔' + (getRandBool() ? '' : '我'))
  46. .replace(/係/g, '糸')
  47. .replace(/喎/g, '咼')
  48. .replace(/啦/g, 'la')
  49. .replace(/子|仔/g, getRandBool() ? '仔' : '囝')
  50. .replace(/ {2,}(.+?) {2,}/, ' '+rq[0]+' $1 '+rq[1]+' ');
  51. text = getRandStrike().repeat(rand(4,16)) + (getRandBool() ? '\n' : ' ') + text;
  52. text += getRandBool() ? getRandEmotion() : getRandEmotion() + getRandStrike().repeat(rand(4,16));
  53. return text;
  54. };
  55.  
  56. setTimeout(function(){
  57. $('#fast_reply [id*="submit_fast_reply"]').click();
  58. $('#fpy').removeClass('fcs');
  59. $('#hkga-noti').empty();
  60. var clickEvts = $.grep($._data(document, 'events').click, function(e){
  61. return e.selector && e.selector.indexOf('submit_fast_reply') > 0 && e.handler.toString().indexOf('/ajax/fastreply') > 0;
  62. });
  63. unsafeWindow.ogenerationified = !1;
  64. for(var i = 0; i < clickEvts.length; i++){
  65. var origHandler = clickEvts[i].handler,
  66. origSelector = clickEvts[i].selector;
  67. clickEvts[i].handler = function(e){
  68. e.preventDefault();
  69. var ctn = $('#gae #ta');
  70. ctn.val(ogenerationify(ctn.val()));
  71. if(origSelector.indexOf('temp') < 0) origHandler(e);
  72. };
  73. }
  74. },1000);