fe-const.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. SHOW_PAGE_LOAD_TIME : "show-page-load-time",
  43. //执行FCP Helper检测
  44. FCP_HELPER_DETECT : 'fcp-helper-detect',
  45. //执行栅格检测
  46. GRID_DETECT : 'grid-detect',
  47. //进行FDP平台文件检索
  48. FDP_HELPER : 'fdp-helper',
  49. //字符串编解码
  50. EN_DECODE : 'en-decode',
  51. //json查看器
  52. JSON_FORMAT : 'json_format',
  53. //QR生成器
  54. QR_CODE : 'qr_code',
  55. //页面相关性能数据
  56. GET_PAGE_WPO_INFO : 'get_page_wpo_info'
  57. };
  58. /**
  59. * 文件类型
  60. */
  61. const FILE = {
  62. //css的<style>标签
  63. STYLE : "style",
  64. //css的<link>标签
  65. LINK : "link",
  66. //js:通过script定义的内联js
  67. SCRIPT : "script-block"
  68. };
  69. //首先配一个DTD中的白名单
  70. const PUBLIC_ID_WHITE_LIST = {
  71. '': {
  72. systemIds: {
  73. '': true
  74. }
  75. },
  76. '-//W3C//DTD HTML 3.2 Final//EN': {
  77. systemIds: {
  78. '': true
  79. }
  80. },
  81. '-//W3C//DTD HTML 4.0//EN': {
  82. systemIds: {
  83. '': true,
  84. 'http://www.w3.org/TR/html4/strict.dtd': true
  85. }
  86. },
  87. '-//W3C//DTD HTML 4.01//EN': {
  88. systemIds: {
  89. '': true,
  90. 'http://www.w3.org/TR/html4/strict.dtd': true
  91. }
  92. },
  93. '-//W3C//DTD HTML 4.0 Transitional//EN': {
  94. systemIds: {
  95. '': true,
  96. 'http://www.w3.org/TR/html4/loose.dtd': true
  97. }
  98. },
  99. '-//W3C//DTD HTML 4.01 Transitional//EN': {
  100. systemIds: {
  101. '': true,
  102. 'http://www.w3.org/TR/html4/loose.dtd': true,
  103. 'http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd': true
  104. }
  105. },
  106. '-//W3C//DTD XHTML 1.1//EN': {
  107. systemIds: {
  108. 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd': true
  109. }
  110. },
  111. '-//W3C//DTD XHTML Basic 1.0//EN': {
  112. systemIds: {
  113. 'http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd': true
  114. }
  115. },
  116. '-//W3C//DTD XHTML 1.0 Strict//EN': {
  117. systemIds: {
  118. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd': true
  119. }
  120. },
  121. '-//W3C//DTD XHTML 1.0 Transitional//EN': {
  122. systemIds: {
  123. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd': true
  124. }
  125. },
  126. 'ISO/IEC 15445:1999//DTD HyperText Markup Language//EN': {
  127. systemIds: {
  128. '': true
  129. }
  130. },
  131. 'ISO/IEC 15445:2000//DTD HTML//EN': {
  132. systemIds: {
  133. '': true
  134. }
  135. },
  136. 'ISO/IEC 15445:1999//DTD HTML//EN': {
  137. systemIds: {
  138. '': true
  139. }
  140. }
  141. };
  142. /**
  143. * IE和Webkit对Doctype的解析差异
  144. */
  145. const COMPAT_MODE_DIFF_PUBLIC_ID_MAP = {
  146. '-//W3C//DTD HTML 4.0 Transitional//EN': {
  147. systemIds: {
  148. 'http://www.w3.org/TR/html4/loose.dtd': {
  149. IE: 'S',
  150. WebKit: 'Q'
  151. }
  152. }
  153. },
  154. 'ISO/IEC 15445:2000//DTD HTML//EN': {
  155. systemIds: {
  156. '': {
  157. IE: 'Q',
  158. WebKit: 'S'
  159. }
  160. }
  161. },
  162. 'ISO/IEC 15445:1999//DTD HTML//EN': {
  163. systemIds: {
  164. '': {
  165. IE: 'Q',
  166. WebKit: 'S'
  167. }
  168. }
  169. }
  170. };
  171. /**
  172. * 过时的HTML标签,HTML5已经不再支持
  173. */
  174. const HTML_DEPRECATED_TAGS = {
  175. acronym: "定义首字母缩写",
  176. applet: "定义Java Applet",
  177. basefont: "定义Font定义",
  178. big: "定义大号文本",
  179. center: "定义居中的文本",
  180. dir: "定义目录列表",
  181. font: "定义文字相关",
  182. frame: "定义框架",
  183. frameset: "定义框架集",
  184. isindex: "定义单行的输入域",
  185. noframes: "定义noframe 部分",
  186. s: "定义加删除线的文本",
  187. strike: "定义加删除线的文本",
  188. tt: "定义打字机文本",
  189. u: "定义下划线文本",
  190. xmp: "定义预格式文本",
  191. layer: "定义层"
  192. }
  193. /**
  194. * 过时的HTML属性,HTML5已经不再支持
  195. */
  196. const HTML_DEPRECATED_ATTRIBUTES = {
  197. align: {
  198. iframe: true,
  199. img: true,
  200. object: true,
  201. table: true
  202. },
  203. color: {
  204. font: true
  205. },
  206. height: {
  207. td: true,
  208. th: true
  209. },
  210. language: {
  211. script: true
  212. },
  213. noshade: {
  214. hr: true
  215. },
  216. nowrap: {
  217. td: true,
  218. th: true
  219. },
  220. size: {
  221. hr: true,
  222. font: true,
  223. basefont: true
  224. }
  225. };
  226. /**
  227. * 块级元素
  228. */
  229. const BLOCK_HTML_ELEMENT = [
  230. 'address','blockquote','center','dir',
  231. 'div','dl','fieldset','form','h1','h2',
  232. 'h3','h4','h5','h6','hr','isindex','menu',
  233. 'noframes','noscript','ol','p','pre','table','ul'
  234. ];
  235. /**
  236. * 内联元素
  237. */
  238. const INLINE_HTML_ELEMENT = [
  239. 'a','acronym','b','bdo','big','br','cite','code',
  240. 'dfn','em','font','i','img','input','kbd','label',
  241. 'q','s','samp','select','small','span','strike','strong',
  242. 'sub','sup','textarea','tt','u','var'
  243. ];
  244. /**
  245. * 可变元素:为根据上下文语境决定该元素为块元素或者内联元素。
  246. */
  247. const CHANGE_ABLE_HTML_ELEMENT = [
  248. 'applet','button','del','iframe',
  249. 'ins','map','object','script'
  250. ];
  251. //关于IE的条件注释,可以参考这里:http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
  252. //条件注释的正则匹配规则
  253. const CONDITIONAL_COMMENT_REGEXP = /\[\s*if\s+[^\]][\s\w]*\]/i;
  254. // 非IE条件注释开始:<![if !IE]> or <![if false]>
  255. const NOT_IE_REVEALED_OPENING_CONDITIONAL_COMMENT_REGEXP = /^\[if\s+(!IE|false)\]$/i;
  256. // IE条件注释结束:<![endif]>
  257. const REVEALED_CLOSING_CONDITIONAL_COMMENT_REGEXP = /^\[endif\s*\]$/i;
  258. // 非IE的条件注释整体: <!--[if !IE]> HTML <![endif]--> or <!--[if false]> HTML <![endif]-->
  259. const NOT_IE_HIDDEN_CONDITIONAL_COMMENT_REGEXP = /^\[if\s+(!IE|false)\]>.*<!\[endif\]$/i;
  260. /* 正则 */
  261. const REG = {
  262. //script标签
  263. SCRIPT: /<script[^>]*>[\s\S]*?<\/[^>]*script>/gi,
  264. //注释
  265. COMMENT: /<!--[\s\S]*?--\>/g,
  266. //cssExpression
  267. CSS_EXPRESSION: /expression[\s\r\n ]?\(/gi,
  268. //textarea
  269. TEXTAREA:/<textarea[^>]*>[\s\S]*?<\/[^>]*textarea>/gi,
  270. //不合法的标签
  271. INVALID_TAG:/<\W+>/gi
  272. };
  273. /**
  274. * 能够自动闭合的标签,就算不闭合也不影响兄弟节点的布局
  275. */
  276. const SELF_CLOSING_TAGS = [
  277. 'meta','link','area','base',
  278. 'col','input','img','br',
  279. 'hr','param','embed'
  280. ];
  281. /**
  282. * 限定HTML嵌套的最大深度为30
  283. * @type Number
  284. */
  285. const HTML_DOM_MAX_DEPTH = 30;
  286. /**
  287. * 统计项
  288. */
  289. const LOG = {
  290. //选项页面:【打开】
  291. options_page_opened : "m_20111124_options_page_opened",
  292. //选项页面:【保存】
  293. options_page_btnsave : "m_20111124_options_page_btnsave",
  294. //选项页面:【关闭】
  295. options_page_btnclose : "m_20111124_options_page_btnclose",
  296. //popup页面:【显示】
  297. popup_page_show : "m_20111124_popup_page_show",
  298. //popup页面:【编码规范检测】
  299. popup_page_fcp : "m_20111124_popup_page_fcp",
  300. //popup页面:【栅格规范检测】
  301. popup_page_grid : "m_20111124_popup_page_grid",
  302. //popup页面:【FE文档检索】
  303. popup_page_fdp : "m_20111124_popup_page_fdp",
  304. //popup页面:【字符串编解码】
  305. popup_page_endecode : "m_20111124_popup_page_endecode",
  306. //popup页面:【网页加载耗时】
  307. popup_page_loadtime : "m_20111124_popup_page_loadtime",
  308. //编解码工具:【打开】
  309. endecode_page_opened : "m_20111124_endecode_page_opened",
  310. //编解码工具:【Unicode编码】
  311. endecode_page_uniEncode : "m_20111124_endecode_page_uniEncode",
  312. //编解码工具:【Unicode解码】
  313. endecode_page_uniDecode : "m_20111124_endecode_page_uniDecode",
  314. //编解码工具:【UTF-8编码】
  315. endecode_page_utf8Encode : "m_20111124_endecode_page_utf8Encode",
  316. //编解码工具:【UTF-8解码】
  317. endecode_page_utf8Decode : "m_20111124_endecode_page_utf8Decode",
  318. //编解码工具:【Base64编码】
  319. endecode_page_base64Encode : "m_20111124_endecode_page_base64Encode",
  320. //编解码工具:【base64解码】
  321. endecode_page_base64Decode : "m_20111124_endecode_page_base64Decode",
  322. //编解码工具:【转换】
  323. endecode_page_btnchange : "m_20111124_endecode_page_btnchange",
  324. //编解码工具:【清空】
  325. endecode_page_btnclear : "m_20111124_endecode_page_btnclear",
  326. //文档检索:【打开】
  327. fdp_page_opened : "m_20111124_fdp_page_opened",
  328. //文档检索:【空间FE文档】
  329. fdp_page_spacedoc : "m_20111124_fdp_page_spacedoc",
  330. //文档检索:【大FE文档】
  331. fdp_page_fedoc : "m_20111124_fdp_page_fedoc",
  332. //文档检索:【检索】
  333. fdp_page_btnsearch : "m_20111124_fdp_page_btnsearch",
  334. //编码规范检测:【显示层】
  335. fcp_detect_show : "m_20111124_fcp_detect_show",
  336. //编码规范检测:【关闭检测结果】
  337. fcp_detect_close : "m_20111124_fcp_detect_close",
  338. //编码规范检测:【最小化检测结果】
  339. fcp_detect_min : "m_20111124_fcp_detect_min",
  340. //编码规范检测:【最大化检测结果】
  341. fcp_detect_max : "m_20111124_fcp_detect_max",
  342. //编码规范检测:【更多HTML规范】
  343. fcp_detect_morehtml : "m_20111124_fcp_detect_morehtml",
  344. //编码规范检测:【更多css规范】
  345. fcp_detect_morecss : "m_20111124_fcp_detect_morecss",
  346. //编码规范检测:【更多js规范】
  347. fcp_detect_morejs : "m_20111124_fcp_detect_morejs",
  348. //栅格检测:【显示层】
  349. grid_detect_show : "m_20111124_grid_detect_show",
  350. //栅格检测:【ESC】
  351. grid_detect_esc : "m_20111124_grid_detect_esc",
  352. //栅格检测:【关闭栅格】
  353. grid_detect_btnclose : "m_20111124_grid_detect_btnclose",
  354. //每天使用人数【粗略统计】
  355. fehelper_user_count : "m_20111124_fehelper_user_count"
  356. };