Greasy Fork 还支持 简体中文。

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. // @version 1
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. /* Test if the thread contains a [CODE] tag */
  11. if(/<pre class="bbcode_code"/i.test(document.body.innerHTML))
  12. {
  13. alert("This thread uses bbcode [CODE] tags. We have attempted to highlight the syntax for you!");
  14. /* Keep comments grayed out */
  15. document.body.innerHTML= document.body.innerHTML.replace(/\n\/\/.+/g, function(m){
  16. return '<span style="color:#C2C2C2">'+m+'</span>'
  17. });
  18. document.body.innerHTML= document.body.innerHTML.replace(/\n\/\*[^]*?\*\//g, function(m){
  19. return '<span style="color:#C2C2C2">'+m+'</span>'
  20. });
  21. /* Highlight all #include pre-processor directives and "import" for python to a green colour */
  22. document.body.innerHTML= document.body.innerHTML.replace(/#include/g, function(m){
  23. return '<span style="color:#30B300">'+m+'</span>'
  24. });
  25. document.body.innerHTML= document.body.innerHTML.replace(/import /g, function(m){
  26. return '<span style="color:#30B300">'+m+'</span>'
  27. });
  28. /* Highlight all strings to a green colour */
  29. document.body.innerHTML= document.body.innerHTML.replace(/\ \".+?\"\\;/g, function(m){
  30. return '<span style="color:#30B300">'+m+'</span>'
  31. });
  32. document.body.innerHTML= document.body.innerHTML.replace(/\ \".+?\"\)/g, function(m){
  33. return '<span style="color:#30B300">'+m+'</span>'
  34. });
  35. document.body.innerHTML= document.body.innerHTML.replace(/\(\".+?\"/g, function(m){
  36. return '<span style="color:#30B300">'+m+'</span>'
  37. });
  38. /* Highlight all function names to a purple colour */
  39. document.body.innerHTML= document.body.innerHTML.replace(/\ (?!rgb)[a-zA-Z]+(?=\()/g, function(m){
  40. return '<span style="color:#cc0099">'+m+'</span>'
  41. });
  42. document.body.innerHTML= document.body.innerHTML.replace(/\t(?!rgb)[a-zA-Z]+(?=\()/g, function(m){
  43. return '<span style="color:#cc0099">'+m+'</span>'
  44. });
  45. /* Highlight all data-types to a yellow colour */
  46. document.body.innerHTML= document.body.innerHTML.replace(/unsigned int /g, function(m){
  47. return '<span style="color:#ff9933">'+m+'</span>'
  48. });
  49. document.body.innerHTML= document.body.innerHTML.replace(/int /g, function(m){
  50. return '<span style="color:#ff9933">'+m+'</span>'
  51. });
  52. document.body.innerHTML= document.body.innerHTML.replace(/char/g, function(m){
  53. return '<span style="color:#ff9933">'+m+'</span>'
  54. });
  55. document.body.innerHTML= document.body.innerHTML.replace(/string/g, function(m){
  56. return '<span style="color:#ff9933">'+m+'</span>'
  57. });
  58. document.body.innerHTML= document.body.innerHTML.replace(/double/g, function(m){
  59. return '<span style="color:#ff9933">'+m+'</span>'
  60. });
  61. document.body.innerHTML= document.body.innerHTML.replace(/void/g, function(m){
  62. return '<span style="color:#ff9933">'+m+'</span>'
  63. });
  64. document.body.innerHTML= document.body.innerHTML.replace(/ return/g, function(m){
  65. return '<span style="color:#ff9933">'+m+'</span>'
  66. });
  67. document.body.innerHTML= document.body.innerHTML.replace(/\treturn/g, function(m){
  68. return '<span style="color:#ff9933">'+m+'</span>'
  69. });
  70. /* Highlight all if conditions to a yellow colour */
  71. document.body.innerHTML= document.body.innerHTML.replace(/if(?=\()/g, function(m){
  72. return '<span style="color:#ff9933">'+m+'</span>'
  73. });
  74. document.body.innerHTML= document.body.innerHTML.replace(/else if(?=\()/g, function(m){
  75. return '<span style="color:#ff9933">'+m+'</span>'
  76. });
  77. }