Specter Syntax Highlighting

Implements syntax highlighting for [CODE] bb tags.

当前为 2016-01-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Specter Syntax Highlighting
  3. // @namespace ngusyntax
  4. // @description Implements syntax highlighting for [CODE] bb tags.
  5. // @include https://www.nextgenupdate.com/forums/*
  6. // @include http://www.nextgenupdate.com/forums/*
  7. // @version 1.02
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /* Test if the thread contains a [CODE] tag */
  12. if(/<pre class="bbcode_code"/i.test(document.body.innerHTML))
  13. {
  14. alert("This thread uses bbcode [CODE] tags. We have attempted to highlight the syntax for you!");
  15. /* Keep comments grayed out */
  16. document.body.innerHTML= document.body.innerHTML.replace(/\n\/\/.+/g, function(m){
  17. return '<span style="color:#C2C2C2">'+m+'</span>'
  18. });
  19. document.body.innerHTML= document.body.innerHTML.replace(/\n\/\*[^]*?\*\//g, function(m){
  20. return '<span style="color:#C2C2C2">'+m+'</span>'
  21. });
  22. /* Highlight all #include pre-processor directives and "import" for python to a green colour */
  23. document.body.innerHTML= document.body.innerHTML.replace(/#include/g, function(m){
  24. return '<span style="color:#30B300">'+m+'</span>'
  25. });
  26. document.body.innerHTML= document.body.innerHTML.replace(/import /g, function(m){
  27. return '<span style="color:#30B300">'+m+'</span>'
  28. });
  29. /* Highlight all strings to a green colour */
  30. document.body.innerHTML= document.body.innerHTML.replace(/\ \".+?\"\\;/g, function(m){
  31. return '<span style="color:#30B300">'+m+'</span>'
  32. });
  33. document.body.innerHTML= document.body.innerHTML.replace(/\ \".+?\"\)/g, function(m){
  34. return '<span style="color:#30B300">'+m+'</span>'
  35. });
  36. document.body.innerHTML= document.body.innerHTML.replace(/\(\".+?\"/g, function(m){
  37. return '<span style="color:#30B300">'+m+'</span>'
  38. });
  39. /* Highlight all function names to a purple colour */
  40. document.body.innerHTML= document.body.innerHTML.replace(/\ (?!rgb)[a-zA-Z]+(?=\()/g, function(m){
  41. return '<span style="color:#cc0099">'+m+'</span>'
  42. });
  43. document.body.innerHTML= document.body.innerHTML.replace(/\t(?!rgb)[a-zA-Z]+(?=\()/g, function(m){
  44. return '<span style="color:#cc0099">'+m+'</span>'
  45. });
  46. /* Highlight all data-types to a yellow colour */
  47. document.body.innerHTML= document.body.innerHTML.replace(/unsigned int /g, function(m){
  48. return '<span style="color:#ff9933">'+m+'</span>'
  49. });
  50. document.body.innerHTML= document.body.innerHTML.replace(/int /g, function(m){
  51. return '<span style="color:#ff9933">'+m+'</span>'
  52. });
  53. document.body.innerHTML= document.body.innerHTML.replace(/unsigned char /g, function(m){
  54. return '<span style="color:#ff9933">'+m+'</span>'
  55. });
  56. document.body.innerHTML= document.body.innerHTML.replace(/char /g, function(m){
  57. return '<span style="color:#ff9933">'+m+'</span>'
  58. });
  59. document.body.innerHTML= document.body.innerHTML.replace(/string /g, function(m){
  60. return '<span style="color:#ff9933">'+m+'</span>'
  61. });
  62. document.body.innerHTML= document.body.innerHTML.replace(/short /g, function(m){
  63. return '<span style="color:#ff9933">'+m+'</span>'
  64. });
  65. document.body.innerHTML= document.body.innerHTML.replace(/float /g, function(m){
  66. return '<span style="color:#ff9933">'+m+'</span>'
  67. });
  68. document.body.innerHTML= document.body.innerHTML.replace(/double /g, function(m){
  69. return '<span style="color:#ff9933">'+m+'</span>'
  70. });
  71. document.body.innerHTML= document.body.innerHTML.replace(/void/g, function(m){
  72. return '<span style="color:#ff9933">'+m+'</span>'
  73. });
  74. document.body.innerHTML= document.body.innerHTML.replace(/struct /g, function(m){
  75. return '<span style="color:#ff9933">'+m+'</span>'
  76. });
  77. document.body.innerHTML= document.body.innerHTML.replace(/enum /g, function(m){
  78. return '<span style="color:#ff9933">'+m+'</span>'
  79. });
  80. document.body.innerHTML= document.body.innerHTML.replace(/ return/g, function(m){
  81. return '<span style="color:#ff9933">'+m+'</span>'
  82. });
  83. document.body.innerHTML= document.body.innerHTML.replace(/\treturn/g, function(m){
  84. return '<span style="color:#ff9933">'+m+'</span>'
  85. });
  86. /* Highlight all if conditions to a yellow colour */
  87. document.body.innerHTML= document.body.innerHTML.replace(/if(?=\()/g, function(m){
  88. return '<span style="color:#ff9933">'+m+'</span>'
  89. });
  90. document.body.innerHTML= document.body.innerHTML.replace(/else if(?=\()/g, function(m){
  91. return '<span style="color:#ff9933">'+m+'</span>'
  92. });
  93. document.body.innerHTML= document.body.innerHTML.replace(/switch/g, function(m){
  94. return '<span style="color:#ff9933">'+m+'</span>'
  95. });
  96. }