Coder Social home page Coder Social logo

loadchange / gwm Goto Github PK

View Code? Open in Web Editor NEW
210.0 210.0 65.0 875 KB

🍭gwm.js Generate Watermark 用于生成网页水印,警示信息安全与责任追踪。

Home Page: https://loadchange.github.io/gwm/

License: MIT License

HTML 19.31% TypeScript 80.69%

gwm's People

Contributors

fupengl avatar loadchange avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gwm's Issues

🐛 默认的 Canvas 模式如果 txt 存在 '&' 或 '<' 等 html 实体字符,会导致生成水印空白。

目前看 Canvas 模式会使用无参数的 toDataURL 方法生成一个 dataURL 给 div 元素设置背景图片。

目前生成的 dataURL 的 mine-type 是 data:image/svg+xml;base64 ,后面的内容是 Svg 文本的 Base64 编码。

如果 txt 存在特殊字符,那么将生成的 dataURL 直接放在浏览器地址栏输入,便会出现下图提示问题。

xml-parse-error

根据 https://stackoverflow.com/questions/39623432/xml-error-on-line-at-column-entityref-expecting 的说法,是浏览器使用 XML 的语法解析 Svg 报错了。

解决方法可以将 txt 中的特殊字符进行转换,希望 gwm 这边能够处理下这个场景。

水印 z-index 支持自定义

当前水印的z-index,会被强制覆盖为999999,无法通过css属性设置。

export default (gwm = {}) => {
    const {gwmDom} = gwm
    const {css} = gwm.opts
    const target = gwmDom ? gwmDom : document.getElementById(_id)
    if (target) target.remove()
    const gwmDiv = document.createElement('div')
    if (isSupport('pointerEvents')) {
        css.pointerEvents = 'none'
        css.zIndex = 999999 // 此处覆盖了外部可能传递进来的zIndex
    }
    bindCSS(gwmDiv, css)
    gwmDiv.id = _id
    return gwmDiv
}

可以支持文字换行吗?

例如txt参数传入一个数组

{
  txt: ['4444444444', '2019-01-14', 'userID:9999']
}

输出的水印可以变成三行

container参数无效

传入了一个id为div1 的div容器,为啥填充的还是整个页面都有水印?

样式问题

将已经有设置position定位的容器设置为container,会导致样式错乱。elem.style.setProperty(key, css[key], 'important'),能不能先判断该元素有没有设置定位再进行设置?

style.setProperty 不能设置 pointerEvents 和 zIndex

bindCss.ts 中的 isSupport 用 document.documentElement.style 来判断属性是否可用,但里面的key是驼峰的形式,然后元素设置样式的时候,elem.style.setProperty(key, css[key], 'important') setProperty 的key不支持驼峰形式,必须是横杠的,导致pointerEvents和zIndex没有设置上。

怎么解决打印网页空白问题呢

当前的这些水印方案,都是插入一个背景图片为水印的div元素,遮罩在整个页面上面,虽说解决了水印需求,但是对于网页打印就完全无解了啊,大佬有没有什么思路

可以给指定的页面添加水印吗

我的项目是单页面应用
在其中的一个页面组件中添加了水印
其他的页面 也都有了
可以只给指定的页面组件加吗
其他的不加

水印可以被隐藏

生成的水印都带有一个id,虽然不能在元素本身上修改样式,但因为这个id,就可以另外写样式

啦啦

在轩辕上就的就是这个吧

多次创建水印

没办法多次creation 最终生成一个水印
即使destroy 为 true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.