fe-const.js 11 KB

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