fe-const.js 11 KB

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