fe-const.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. //页面json代码自动格式化
  72. AUTO_FORMART_PAGE_JSON : "opt_item_autojson",
  73. //页面取色器
  74. COLOR_PICKER : "color-picker:newImage"
  75. };
  76. /**
  77. * 文件类型
  78. */
  79. const FILE = {
  80. //css的<style>标签
  81. STYLE : "style",
  82. //css的<link>标签
  83. LINK : "link",
  84. //js:通过script定义的内联js
  85. SCRIPT : "script-block"
  86. };
  87. //首先配一个DTD中的白名单
  88. const PUBLIC_ID_WHITE_LIST = {
  89. '': {
  90. systemIds: {
  91. '': true
  92. }
  93. },
  94. '-//W3C//DTD HTML 3.2 Final//EN': {
  95. systemIds: {
  96. '': true
  97. }
  98. },
  99. '-//W3C//DTD HTML 4.0//EN': {
  100. systemIds: {
  101. '': true,
  102. 'http://www.w3.org/TR/html4/strict.dtd': true
  103. }
  104. },
  105. '-//W3C//DTD HTML 4.01//EN': {
  106. systemIds: {
  107. '': true,
  108. 'http://www.w3.org/TR/html4/strict.dtd': true
  109. }
  110. },
  111. '-//W3C//DTD HTML 4.0 Transitional//EN': {
  112. systemIds: {
  113. '': true,
  114. 'http://www.w3.org/TR/html4/loose.dtd': true
  115. }
  116. },
  117. '-//W3C//DTD HTML 4.01 Transitional//EN': {
  118. systemIds: {
  119. '': true,
  120. 'http://www.w3.org/TR/html4/loose.dtd': true,
  121. 'http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd': true
  122. }
  123. },
  124. '-//W3C//DTD XHTML 1.1//EN': {
  125. systemIds: {
  126. 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd': true
  127. }
  128. },
  129. '-//W3C//DTD XHTML Basic 1.0//EN': {
  130. systemIds: {
  131. 'http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd': true
  132. }
  133. },
  134. '-//W3C//DTD XHTML 1.0 Strict//EN': {
  135. systemIds: {
  136. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd': true
  137. }
  138. },
  139. '-//W3C//DTD XHTML 1.0 Transitional//EN': {
  140. systemIds: {
  141. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd': true
  142. }
  143. },
  144. 'ISO/IEC 15445:1999//DTD HyperText Markup Language//EN': {
  145. systemIds: {
  146. '': true
  147. }
  148. },
  149. 'ISO/IEC 15445:2000//DTD HTML//EN': {
  150. systemIds: {
  151. '': true
  152. }
  153. },
  154. 'ISO/IEC 15445:1999//DTD HTML//EN': {
  155. systemIds: {
  156. '': true
  157. }
  158. }
  159. };
  160. /**
  161. * IE和Webkit对Doctype的解析差异
  162. */
  163. const COMPAT_MODE_DIFF_PUBLIC_ID_MAP = {
  164. '-//W3C//DTD HTML 4.0 Transitional//EN': {
  165. systemIds: {
  166. 'http://www.w3.org/TR/html4/loose.dtd': {
  167. IE: 'S',
  168. WebKit: 'Q'
  169. }
  170. }
  171. },
  172. 'ISO/IEC 15445:2000//DTD HTML//EN': {
  173. systemIds: {
  174. '': {
  175. IE: 'Q',
  176. WebKit: 'S'
  177. }
  178. }
  179. },
  180. 'ISO/IEC 15445:1999//DTD HTML//EN': {
  181. systemIds: {
  182. '': {
  183. IE: 'Q',
  184. WebKit: 'S'
  185. }
  186. }
  187. }
  188. };
  189. /**
  190. * 过时的HTML标签,HTML5已经不再支持
  191. */
  192. const HTML_DEPRECATED_TAGS = {
  193. acronym: "定义首字母缩写",
  194. applet: "定义Java Applet",
  195. basefont: "定义Font定义",
  196. big: "定义大号文本",
  197. center: "定义居中的文本",
  198. dir: "定义目录列表",
  199. font: "定义文字相关",
  200. frame: "定义框架",
  201. frameset: "定义框架集",
  202. isindex: "定义单行的输入域",
  203. noframes: "定义noframe 部分",
  204. s: "定义加删除线的文本",
  205. strike: "定义加删除线的文本",
  206. tt: "定义打字机文本",
  207. u: "定义下划线文本",
  208. xmp: "定义预格式文本",
  209. layer: "定义层"
  210. };
  211. /**
  212. * 过时的HTML属性,HTML5已经不再支持
  213. */
  214. const HTML_DEPRECATED_ATTRIBUTES = {
  215. align: {
  216. iframe: true,
  217. img: true,
  218. object: true,
  219. table: true
  220. },
  221. color: {
  222. font: true
  223. },
  224. height: {
  225. td: true,
  226. th: true
  227. },
  228. language: {
  229. script: true
  230. },
  231. noshade: {
  232. hr: true
  233. },
  234. nowrap: {
  235. td: true,
  236. th: true
  237. },
  238. size: {
  239. hr: true,
  240. font: true,
  241. basefont: true
  242. }
  243. };
  244. /**
  245. * 块级元素
  246. */
  247. const BLOCK_HTML_ELEMENT = [
  248. 'address','blockquote','center','dir',
  249. 'div','dl','fieldset','form','h1','h2',
  250. 'h3','h4','h5','h6','hr','isindex','menu',
  251. 'noframes','noscript','ol','p','pre','table','ul'
  252. ];
  253. /**
  254. * 内联元素
  255. */
  256. const INLINE_HTML_ELEMENT = [
  257. 'a','acronym','b','bdo','big','br','cite','code',
  258. 'dfn','em','font','i','img','input','kbd','label',
  259. 'q','s','samp','select','small','span','strike','strong',
  260. 'sub','sup','textarea','tt','u','var'
  261. ];
  262. /**
  263. * 可变元素:为根据上下文语境决定该元素为块元素或者内联元素。
  264. */
  265. const CHANGE_ABLE_HTML_ELEMENT = [
  266. 'applet','button','del','iframe',
  267. 'ins','map','object','script'
  268. ];
  269. //关于IE的条件注释,可以参考这里:http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
  270. //条件注释的正则匹配规则
  271. const CONDITIONAL_COMMENT_REGEXP = /\[\s*if\s+[^\]][\s\w]*\]/i;
  272. // 非IE条件注释开始:<![if !IE]> or <![if false]>
  273. const NOT_IE_REVEALED_OPENING_CONDITIONAL_COMMENT_REGEXP = /^\[if\s+(!IE|false)\]$/i;
  274. // IE条件注释结束:<![endif]>
  275. const REVEALED_CLOSING_CONDITIONAL_COMMENT_REGEXP = /^\[endif\s*\]$/i;
  276. // 非IE的条件注释整体: <!--[if !IE]> HTML <![endif]--> or <!--[if false]> HTML <![endif]-->
  277. const NOT_IE_HIDDEN_CONDITIONAL_COMMENT_REGEXP = /^\[if\s+(!IE|false)\]>.*<!\[endif\]$/i;
  278. /* 正则 */
  279. const REG = {
  280. //script标签
  281. SCRIPT: /<script[^>]*>[\s\S]*?<\/[^>]*script>/gi,
  282. //注释
  283. COMMENT: /<!--[\s\S]*?--\>/g,
  284. //cssExpression
  285. CSS_EXPRESSION: /expression[\s\r\n ]?\(/gi,
  286. //textarea
  287. TEXTAREA:/<textarea[^>]*>[\s\S]*?<\/[^>]*textarea>/gi,
  288. //不合法的标签
  289. INVALID_TAG:/<\W+>/gi
  290. };
  291. /**
  292. * 能够自动闭合的标签,就算不闭合也不影响兄弟节点的布局
  293. */
  294. const SELF_CLOSING_TAGS = [
  295. 'meta','link','area','base',
  296. 'col','input','img','br',
  297. 'hr','param','embed'
  298. ];