Bookmarklet for Jobbole
本书签工具主要功能是方便用户向伯乐在线 | 头条分享文章,虽然官方也提供了浏览器扩展,个人觉得安装扩展显得有些“笨重”,而且最主要的是消耗系统资源。于是,参考 pocket 与 一点黑科技,写了本书签工具,希望对大家有帮助。😊
GitHub 出于某些原因,不允许在 README.md
里面使用 script
标签,内敛样式(inline-styles),所以我只能创建 GitHub Pages 来做安装演示。囧
-
编写源代码
javascript:(function() { var excerpt = window.getSelection ? window.getSelection().toString() : ""; if(excerpt === "") { var meta = document.querySelector("meta[name=\'description\']"); if(meta) { excerpt = meta.getAttribute("content"); } } window.location="http://top.jobbole.com/submit/?utm_source=bookmark&utm_medium=toolBar&source="+encodeURIComponent(document.location)+"&title="+encodeURIComponent(document.title)+"&excerpt="+encodeURIComponent(excerpt); })()
-
为了防止旧版浏览器对 URL 中一些字符的兼容性,需要对源代码进行 encodeURIComponent,可使用开源中国在线编码转换
需要注意的是,代码起始处的
javascript:
中的:
不需要编码。