• Stars
    star
    199
  • Rank 196,105 (Top 4 %)
  • Language
    JavaScript
  • Created over 8 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CSS Text Transformation

CSST (CSS Text Transformation)

NPM version Build Status Coverage Status

背景

什么是 CSST?

一种用 CSS 跨域传输文本的方案。相比 JSONP 更为安全,不需要执行跨站脚本。

原理

通过读取 CSS3 content 属性获取传送内容。

调用流程

image

技术手段

  • 怎么监听 <link> 加载完毕?

收集线上的资料,发现常见的方案是计时器或者用 onpropertychange、DOMAttrModified。

考虑是 CSS3 场景,取巧用动画开始 (animationstart) 这个事件来捕获。

  • 怎么传送特殊字符("、'、\、\n、\r、\t)?

Chrome、Safari 对 content 样式属性字符解析并不一致

为避免未知解析规则影响,统一使用 base64 编码

服务器应答的内容

function csst(id, text) {
  return `
  @keyframes ${id} {
    from {
    }
    to {
      color: red;
    }
  }
  @-webkit-keyframes ${id} {
    from {}
    to {
      color: red;
    }
  }
  #${id} {
    content: ${new Buffer(text, 'utf-8').toString('base64')};
    animation: ${id} 2s;
    -webkit-animation: ${id} 2s;
  }`;
}

与 JSONP 安全性比较

image

开发

本机调试

$ npm run debug

构建

$ npm run dist

问题

  • 没有 JSONP 适配广,CSST 依赖支持 CSS3 的浏览器。

线上体验

http://jhtmls.com/idea/csst.html

参考资料

License

MIT © zswang

More Repositories

1

jdists

A feature rich code block preprocessing tool.
JavaScript
317
star
2

h5psd

Converting PSD files into mobile page
JavaScript
185
star
3

jdetects

Detect if DevTools is open
JavaScript
139
star
4

jfogs

JavaScript Obfuscator
JavaScript
89
star
5

jpacks

Binary data packing and unpacking.
JavaScript
56
star
6

examplejs

A tool for converting example code into test cases
JavaScript
44
star
7

icity

Get the tools for the city where your phone number is located
TypeScript
43
star
8

np2km

Analysis of NPM dependencies, and generate a file kityminder file
JavaScript
41
star
9

zswang.github.com

HTML
40
star
10

bigfont

A tool for to enlarge the font.
JavaScript
29
star
11

gallery.animate.css

Gallery of Animate CSS
CSS
22
star
12

jints

Big Integer
JavaScript
16
star
13

jhtmls

Unmarked front-end template
JavaScript
15
star
14

fis-optimizer-tinify

JavaScript
11
star
15

snake

简易贪吃蛇
HTML
11
star
16

rtconfig

A real time updated configuration.
JavaScript
9
star
17

jrands

The random function of the constructor can specify random seeds
JavaScript
9
star
18

h5i18n

A mobile page of internationalization development framework
JavaScript
8
star
19

selector-helper

A CSS selector preview tool.
JavaScript
7
star
20

h5tracker

Mobile web page data collection framework
JavaScript
7
star
21

ace-engine

HTML visualization development
JavaScript
6
star
22

jcameras

Mouse behavior recording and playing
JavaScript
6
star
23

jphps

Unmarked PHP template
JavaScript
5
star
24

ziiya

聊天枝丫
JavaScript
4
star
25

fis3-parser-webpack

A parser plugin for fis3 to compile webpack file.
JavaScript
4
star
26

penjs

Mobile-side page small development framework.
JavaScript
4
star
27

light-map

Cordova 地图
Java
3
star
28

element-path

Path of element get and query.
JavaScript
3
star
29

snow-globe

snow globe
TypeScript
3
star
30

svgbackground

Some simple SVG background generation tools.
JavaScript
2
star
31

jfpss

JavaScript
2
star
32

jmaths

用于收集常用数学函数
JavaScript
2
star
33

bo2km

Analysis of Bower dependencies, and generate a file kityminder file
JavaScript
2
star
34

h5ajax

Ajax of Mobile
JavaScript
2
star
35

jsizes

锚点控制组件
JavaScript
2
star
36

jnodes

A tool view of template
JavaScript
2
star
37

proxy-fs

A simple proxy filesystem.
JavaScript
2
star
38

chessengine

棋类引擎
2
star
39

h5i18n-editor

The dictionary editor of h5i18n
JavaScript
2
star
40

jtasks

构建工具。怎么又是构建工具?挖这么大坑干啥?
2
star
41

mikecrm-api

mikecrm api
TypeScript
2
star
42

jpaths

一个简单绘图库,兼容 svg 和 vml,路径只支持其交集。
JavaScript
2
star
43

xqueue

Emitter at Redis queue
JavaScript
2
star
44

h5emitter

event emitter function
JavaScript
2
star
45

jfetchs

cache of fetch data
JavaScript
2
star
46

jvects

矢量计算
JavaScript
2
star
47

renrousousuo.com

人肉搜索网站
2
star
48

linenum

This tool will replace text "^linenum" with the line number.
JavaScript
1
star
49

light-flashlight

Cordova 手电筒插件
1
star
50

jmd5s

md5 函数封装
JavaScript
1
star
51

jfetchs-memory

jfetchs memory store
TypeScript
1
star
52

cellular

JavaScript
1
star
53

gulp-jdists

Code block processing with jdists - gulp plugin
JavaScript
1
star
54

jchecks

Checklist black box testing.
JavaScript
1
star
55

fis-parser-linenum

A parser plugin for fis3 to replace line number.
JavaScript
1
star
56

npdep

Automatic import NPM's main file to HTML
JavaScript
1
star
57

mockjs_jdists_demo

mockjs and jdists demo
HTML
1
star
58

gulp-examplejs

A tool for converting sample code into test cases
JavaScript
1
star
59

jsets

JavaScript
1
star
60

h5toast

Simple toast notifications of Mobile Web
JavaScript
1
star
61

business-mail

JavaScript
1
star
62

h5tap

Tap event trigger of mobile.
JavaScript
1
star
63

iplus

Timestamp based GUID
JavaScript
1
star
64

iholiday

Holiday schedule for holidays of China.
TypeScript
1
star
65

react-drawer

TypeScript
1
star
66

sensorsdata-api

sensorsdata API
JavaScript
1
star
67

file-analyzer

Automatically exported from code.google.com/p/file-analyzer
Pascal
1
star
68

jstrs

String functions
JavaScript
1
star
69

iorder

For the title sort of the article
JavaScript
1
star
70

jdists-loader

jdists loader module for webpack
JavaScript
1
star