Visited Lite

Mark all visited links as custom color.

目前为 2017-11-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Visited Lite
  3. // @namespace iFantz7E.VisitedLite
  4. // @description Mark all visited links as custom color.
  5. // @version 0.23
  6. // @include http*
  7. // @icon https://addons.cdn.mozilla.net/user-media/addon_icons/359/359581-64.png
  8. // @run-at document-start
  9. // @grant none
  10. // @copyright 2015, 7-elephant
  11. // ==/UserScript==
  12.  
  13. (function ()
  14. {
  15.  
  16. //// Config
  17.  
  18. // View your old config from Visited
  19. // about:config?filter=extensions.visited
  20.  
  21. // Copy from extensions.visited.color.visited
  22. var p_color_visited = "LightCoral";
  23.  
  24. // Copy from extensions.visited.except
  25. var p_except = "mail.live.com,";
  26.  
  27. //// End Config
  28.  
  29. //// Variable
  30.  
  31. const style_id = "visited-lite-7e-style";
  32. const css_a_visited = " a:visited, a:visited * { color: %COLOR% !important; } ";
  33.  
  34. var colorArr = ["Aqua","Blue","BlueViolet","Brown","CadetBlue","Chocolate","Coral"
  35. ,"CornflowerBlue","Crimson","DarkGoldenRod","DarkGreen","DarkKhaki","DarkMagenta"
  36. ,"Darkorange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkTurquoise"
  37. ,"DarkViolet","DeepPink","DeepSkyBlue","DodgerBlue","FireBrick","ForestGreen"
  38. ,"Fuchsia","Gold","GoldenRod","Green","GreenYellow","HotPink","IndianRed"
  39. ,"Indigo","Khaki","Lavender","LawnGreen","LightCoral","LightSalmon","LightSeaGreen"
  40. ,"LightSteelBlue","Lime","LimeGreen","Magenta","Maroon"
  41. ,"MediumAquaMarine","MediumOrchid","MediumSlateBlue","MediumTurquoise","NavajoWhite","Navy"
  42. ,"Orange","OrangeRed","Orchid","PaleVioletRed","Peru","Purple","Red","RosyBrown"
  43. ,"RoyalBlue","SaddleBrown","Salmon","SandyBrown","SeaGreen","Sienna","SlateBlue"
  44. ,"SpringGreen","SteelBlue","Tomato","Turquoise","Violet","YellowGreen"];
  45. //// End Variable
  46.  
  47. //// Function
  48.  
  49. function attachOnLoad(callback)
  50. {
  51. window.addEventListener("load", function (e)
  52. {
  53. callback();
  54. });
  55. }
  56.  
  57. function attachOnReady(callback)
  58. {
  59. document.addEventListener("DOMContentLoaded", function (e)
  60. {
  61. callback();
  62. });
  63. }
  64.  
  65. function isExceptSite(except, site)
  66. {
  67. var exceptList = except.split(",");
  68. for (var i = 0; i < exceptList.length; i++)
  69. {
  70. var str = exceptList[i].replace(/\s/ig,"");
  71. var str1 = str;
  72. if (str1.indexOf(".") != 0 && str1.indexOf("/") != 0)
  73. str1 = "." + str1;
  74. var str2 = str;
  75. if (str2.indexOf("://") != 0)
  76. str2 = "://" + str2;
  77. if(str != ""
  78. && (site.indexOf(str1) > -1 || site.indexOf(str2) > -1))
  79. {
  80. return true;
  81. }
  82. }
  83. return false;
  84. }
  85.  
  86. function addStyle(css)
  87. {
  88. var style = document.getElementById(style_id);
  89. if(style == null)
  90. {
  91. var heads = document.getElementsByTagName("head");
  92. if(heads != null && heads.length > 0)
  93. {
  94. var head = heads[0];
  95. var style = document.createElement("style");
  96. if(style != null)
  97. {
  98. style.setAttribute("id",style_id);
  99. style.setAttribute("type","text/css");
  100. head.appendChild(style);
  101. }
  102. }
  103. }
  104.  
  105. if(style != null)
  106. {
  107. style.textContent = String(css);
  108. }
  109. }
  110.  
  111. function assignColor(css, color)
  112. {
  113. return css.replace(/%COLOR%/ig, color);
  114. }
  115.  
  116. function main()
  117. {
  118. var url = document.documentURI;
  119. var css = "";
  120. css += assignColor(css_a_visited, p_color_visited);
  121. if(!isExceptSite(p_except, url))
  122. {
  123. addStyle(css);
  124. }
  125. }
  126.  
  127. //// End Function
  128.  
  129. attachOnReady(main);
  130.  
  131. })();
  132.  
  133. // End