Enhance Metafilter Titles

Uh, you don't want to install this.

当前为 2014-05-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Enhance Metafilter Titles
  3. // @namespace http://example.com/EnhanceMetafilterTitles
  4. // @description Uh, you don't want to install this.
  5. // @include http://www.metafilter.com/
  6. // @include http://www.metafilter.com/*?page=*
  7. // @include http://ask.metafilter.com/
  8. // @include http://ask.metafilter.com/*?page=*
  9. // @include http://metatalk.metafilter.com/
  10. // @include http://metatalk.metafilter.com/*?page=*
  11. // @version 1
  12. // ==/UserScript==
  13.  
  14. function rand(max) {
  15. return Math.floor(Math.random() * (max + 1));
  16. }
  17.  
  18. function enhance() {
  19. var snap = document.evaluate(
  20. "//div[contains(concat(' ', @class, ' '), ' posttitle ')]//a",
  21. document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  22. for (var i = 0; i < snap.snapshotLength; i++) {
  23. var link = snap.snapshotItem(i);
  24. link.style.fontSize = "" + (rand(100) + 32) + "px";
  25. backColor =
  26. (256 * 256 * rand(255) + 256 * rand(255) + rand(255)).toString(16);
  27. while (backColor.length < 6) {
  28. backColor = "0" + backColor;
  29. }
  30. backColor = "#" + backColor;
  31. link.style.backgroundColor = backColor;
  32. var decorationBits = rand(15);
  33. var decoration = "";
  34. if (decorationBits & 1) {
  35. decoration += "underline ";
  36. }
  37. if (decorationBits & 2) {
  38. decoration += "overline ";
  39. }
  40. if (decorationBits & 4) {
  41. decoration += "line-through ";
  42. }
  43. if (decorationBits & 8) {
  44. decoration += "blink ";
  45. }
  46. decoration = decoration.substr(0, decoration.length - 1);
  47. link.style.textDecoration = decoration;
  48. var fontA = rand(7);
  49. if (fontA == 0) {
  50. font = '"Comic Sans MS"';
  51. } else if (fontA == 1) {
  52. fontA = '"Bradley Hand ITC"';
  53. } else if (fontA == 2) {
  54. fontA = '"Kristen ITC"';
  55. } else if (fontA == 3) {
  56. fontA = '"Curlz MT"';
  57. } else if (fontA == 4) {
  58. fontA = 'Papyrus';
  59. } else if (fontA == 5) {
  60. fontA = 'Vivaldi';
  61. } else if (fontA == 6) {
  62. fontA = '"Viner Hand ITC"';
  63. } else if (fontA == 7) {
  64. fontA = 'wingdings';
  65. }
  66. var fontB = rand(3);
  67. if (fontB == 0) {
  68. fontB = 'cursive';
  69. } else if (fontB == 1) {
  70. fontB = 'Courier';
  71. } else if (fontB == 2) {
  72. fontB = 'Charcoal';
  73. } else if (fontB == 3) {
  74. fontB = 'Gadget';
  75. }
  76. var fontC = rand(2);
  77. if (fontC == 0) {
  78. fontC = 'serif';
  79. } else if (fontC == 1) {
  80. fontC = 'sans-serif';
  81. } else if (fontC == 2) {
  82. fontC = 'monospace';
  83. }
  84. link.style.fontFamily = fontA + ", " + fontB + ", " + fontC;
  85. }
  86. }
  87.  
  88. enhance();
  89. setInterval(enhance, 5000);