fe-const.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /**
  2. * 常量定义
  3. * @author zhaoxianlie
  4. */
  5. /**
  6. * 各个模块进行信息交互时的消息类型
  7. */
  8. const MSG_TYPE = {
  9. //browserAction被点击
  10. BROWSER_CLICKED : "browser-clicked",
  11. //提取CSS
  12. GET_CSS : "get-css",
  13. //提取JS
  14. GET_JS : "get-js",
  15. //提取HTML
  16. GET_HTML : "get-html",
  17. //cookie
  18. GET_COOKIE : 'get-cookie',
  19. //remvoe cookie
  20. REMOVE_COOKIE : 'remove-cookie',
  21. //set cookie
  22. SET_COOKIE : 'set-cookie',
  23. //get options
  24. GET_OPTIONS : 'get_options',
  25. //set options
  26. SET_OPTIONS : 'set_options',
  27. //css ready...
  28. CSS_READY : 'css-ready',
  29. //js ready...
  30. JS_READY : 'js-ready',
  31. //html ready...
  32. HTML_READY : 'html-ready',
  33. //启动项
  34. START_OPTION : 'start-option',
  35. //启动FCPHelper
  36. OPT_START_FCP : 'opt-item-fcp',
  37. //启动栅格检测
  38. OPT_START_GRID : 'opt-item-grid',
  39. //计算网页加载时间
  40. CALC_PAGE_LOAD_TIME : "calc-page-load-time",
  41. //页面相关性能数据
  42. GET_PAGE_WPO_INFO : 'get_page_wpo_info',
  43. //查看加载时间
  44. SHOW_PAGE_LOAD_TIME : "show-page-load-time",
  45. //执行FCP Helper检测
  46. FCP_HELPER_DETECT : 'fcp-helper-detect',
  47. //执行栅格检测
  48. GRID_DETECT : 'grid-detect',
  49. //执行JS嗅探:Tracker,from 志龙(http://ucren.com)
  50. JS_TRACKER : 'js_tracker',
  51. CODE_COMPRESS : 'code_compress',
  52. FROM_POPUP : 'from_popup_action',
  53. TAB_CREATED_OR_UPDATED: 'tab_created_or_updated',
  54. ////////////////////如下是popup中的menu,value和filename相同///////////////////
  55. REGEXP_TOOL : 'regexp',
  56. //字符串编解码
  57. EN_DECODE : 'endecode',
  58. //json查看器
  59. JSON_FORMAT : 'jsonformat',
  60. //QR生成器
  61. QR_CODE : 'qrcode',
  62. //代码美化
  63. CODE_BEAUTIFY : 'codebeautify',
  64. // 时间转换
  65. TIME_STAMP : 'timestamp',
  66. // 图片base64
  67. IMAGE_BASE64 : 'imagebase64',
  68. //页面json代码自动格式化
  69. AUTO_FORMART_PAGE_JSON : "opt_item_autojson"
  70. };
  71. /**
  72. * 文件类型
  73. */
  74. const FILE = {
  75. //css的<style>标签
  76. STYLE : "style",
  77. //css的<link>标签
  78. LINK : "link",
  79. //js:通过script定义的内联js
  80. SCRIPT : "script-block"
  81. };
  82. //首先配一个DTD中的白名单
  83. const PUBLIC_ID_WHITE_LIST = {
  84. '': {
  85. systemIds: {
  86. '': true
  87. }
  88. },
  89. '-//W3C//DTD HTML 3.2 Final//EN': {
  90. systemIds: {
  91. '': true
  92. }
  93. },
  94. '-//W3C//DTD HTML 4.0//EN': {
  95. systemIds: {
  96. '': true,
  97. 'http://www.w3.org/TR/html4/strict.dtd': true
  98. }
  99. },
  100. '-//W3C//DTD HTML 4.01//EN': {
  101. systemIds: {
  102. '': true,
  103. 'http://www.w3.org/TR/html4/strict.dtd': true
  104. }
  105. },
  106. '-//W3C//DTD HTML 4.0 Transitional//EN': {
  107. systemIds: {
  108. '': true,
  109. 'http://www.w3.org/TR/html4/loose.dtd': true
  110. }
  111. },
  112. '-//W3C//DTD HTML 4.01 Transitional//EN': {
  113. systemIds: {
  114. '': true,
  115. 'http://www.w3.org/TR/html4/loose.dtd': true,
  116. 'http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd': true
  117. }
  118. },
  119. '-//W3C//DTD XHTML 1.1//EN': {
  120. systemIds: {
  121. 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd': true
  122. }
  123. },
  124. '-//W3C//DTD XHTML Basic 1.0//EN': {
  125. systemIds: {
  126. 'http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd': true
  127. }
  128. },
  129. '-//W3C//DTD XHTML 1.0 Strict//EN': {
  130. systemIds: {
  131. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd': true
  132. }
  133. },
  134. '-//W3C//DTD XHTML 1.0 Transitional//EN': {
  135. systemIds: {
  136. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd': true
  137. }
  138. },
  139. 'ISO/IEC 15445:1999//DTD HyperText Markup Language//EN': {
  140. systemIds: {
  141. '': true
  142. }
  143. },
  144. 'ISO/IEC 15445:2000//DTD HTML//EN': {
  145. systemIds: {
  146. '': true
  147. }
  148. },
  149. 'ISO/IEC 15445:1999//DTD HTML//EN': {
  150. systemIds: {
  151. '': true
  152. }
  153. }
  154. };
  155. /**
  156. * IE和Webkit对Doctype的解析差异
  157. */
  158. const COMPAT_MODE_DIFF_PUBLIC_ID_MAP = {
  159. '-//W3C//DTD HTML 4.0 Transitional//EN': {
  160. systemIds: {
  161. 'http://www.w3.org/TR/html4/loose.dtd': {
  162. IE: 'S',
  163. WebKit: 'Q'
  164. }
  165. }
  166. },
  167. 'ISO/IEC 15445:2000//DTD HTML//EN': {
  168. systemIds: {
  169. '': {
  170. IE: 'Q',
  171. WebKit: 'S'
  172. }
  173. }
  174. },
  175. 'ISO/IEC 15445:1999//DTD HTML//EN': {
  176. systemIds: {
  177. '': {
  178. IE: 'Q',
  179. WebKit: 'S'
  180. }
  181. }
  182. }
  183. };
  184. /**
  185. * 过时的HTML标签,HTML5已经不再支持
  186. */
  187. const HTML_DEPRECATED_TAGS = {
  188. acronym: "定义首字母缩写",
  189. applet: "定义Java Applet",
  190. basefont: "定义Font定义",
  191. big: "定义大号文本",
  192. center: "定义居中的文本",
  193. dir: "定义目录列表",
  194. font: "定义文字相关",
  195. frame: "定义框架",
  196. frameset: "定义框架集",
  197. isindex: "定义单行的输入域",
  198. noframes: "定义noframe 部分",
  199. s: "定义加删除线的文本",
  200. strike: "定义加删除线的文本",
  201. tt: "定义打字机文本",
  202. u: "定义下划线文本",
  203. xmp: "定义预格式文本",
  204. layer: "定义层"
  205. };
  206. /**
  207. * 过时的HTML属性,HTML5已经不再支持
  208. */
  209. const HTML_DEPRECATED_ATTRIBUTES = {
  210. align: {
  211. iframe: true,
  212. img: true,
  213. object: true,
  214. table: true
  215. },
  216. color: {
  217. font: true
  218. },
  219. height: {
  220. td: true,
  221. th: true
  222. },
  223. language: {
  224. script: true
  225. },
  226. noshade: {
  227. hr: true
  228. },
  229. nowrap: {
  230. td: true,
  231. th: true
  232. },
  233. size: {
  234. hr: true,
  235. font: true,
  236. basefont: true
  237. }
  238. };
  239. /**
  240. * 块级元素
  241. */
  242. const BLOCK_HTML_ELEMENT = [
  243. 'address','blockquote','center','dir',
  244. 'div','dl','fieldset','form','h1','h2',
  245. 'h3','h4','h5','h6','hr','isindex','menu',
  246. 'noframes','noscript','ol','p','pre','table','ul'
  247. ];
  248. /**
  249. * 内联元素
  250. */
  251. const INLINE_HTML_ELEMENT = [
  252. 'a','acronym','b','bdo','big','br','cite','code',
  253. 'dfn','em','font','i','img','input','kbd','label',
  254. 'q','s','samp','select','small','span','strike','strong',
  255. 'sub','sup','textarea','tt','u','var'
  256. ];
  257. /**
  258. * 可变元素:为根据上下文语境决定该元素为块元素或者内联元素。
  259. */
  260. const CHANGE_ABLE_HTML_ELEMENT = [
  261. 'applet','button','del','iframe',
  262. 'ins','map','object','script'
  263. ];
  264. //关于IE的条件注释,可以参考这里:http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
  265. //条件注释的正则匹配规则
  266. const CONDITIONAL_COMMENT_REGEXP = /\[\s*if\s+[^\]][\s\w]*\]/i;
  267. // 非IE条件注释开始:<![if !IE]> or <![if false]>
  268. const NOT_IE_REVEALED_OPENING_CONDITIONAL_COMMENT_REGEXP = /^\[if\s+(!IE|false)\]$/i;
  269. // IE条件注释结束:<![endif]>
  270. const REVEALED_CLOSING_CONDITIONAL_COMMENT_REGEXP = /^\[endif\s*\]$/i;
  271. // 非IE的条件注释整体: <!--[if !IE]> HTML <![endif]--> or <!--[if false]> HTML <![endif]-->
  272. const NOT_IE_HIDDEN_CONDITIONAL_COMMENT_REGEXP = /^\[if\s+(!IE|false)\]>.*<!\[endif\]$/i;
  273. /* 正则 */
  274. const REG = {
  275. //script标签
  276. SCRIPT: /<script[^>]*>[\s\S]*?<\/[^>]*script>/gi,
  277. //注释
  278. COMMENT: /<!--[\s\S]*?--\>/g,
  279. //cssExpression
  280. CSS_EXPRESSION: /expression[\s\r\n ]?\(/gi,
  281. //textarea
  282. TEXTAREA:/<textarea[^>]*>[\s\S]*?<\/[^>]*textarea>/gi,
  283. //不合法的标签
  284. INVALID_TAG:/<\W+>/gi
  285. };
  286. /**
  287. * 能够自动闭合的标签,就算不闭合也不影响兄弟节点的布局
  288. */
  289. const SELF_CLOSING_TAGS = [
  290. 'meta','link','area','base',
  291. 'col','input','img','br',
  292. 'hr','param','embed'
  293. ];