fe-const.js 8.2 KB

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