fe-const.js 7.9 KB

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