阅读:1557回复:3
请问大家用Ubiquity了吗?
我刚刚上手,有一个问题,命令 highlight ,实现高亮。我想在全文章的情况下实现关键词高亮,可是一直不行。例如:关键词“Firefox",在论坛首页实现全部高亮。一直以来只能实现一个关键词高亮,或者逐个操作。请教大家如何实现全部关键词高亮。
|
|
1楼#
发布于:2009-12-20 18:00
SearchWP 扩展
|
|
|
2楼#
发布于:2009-12-20 18:00
高亮选中文本的bookmarklets:
javascript:(function(){%20%20function%20highlight%20(node,%20word){%20var%20offset%20=%20node.nodeValue.lastIndexOf(word);%20while(offset%20>=%200){%20var%20range%20=%20document.createRange();%20range.setStart(%20node,%20offset%20);%20range.setEnd(%20node,%20offset%20+%20word.length%20);%20range.surroundContents(%20SPAN.cloneNode(false)%20);%20offset%20=%20node.nodeValue.lastIndexOf(word);%20}%20}%20%20var%20word%20=%20getSelection()+''%20||%20prompt('Search%20word');%20if%20(!word)%20return;%20%20var%20XPATH%20=%20'descendant::text()[contains(self::text(),%22'%20+%20word%20+'%22)%20and%20not(ancestor::option)%20and%20not(ancestor::textarea)%20and%20not(ancestor::script)%20and%20not(ancestor::style)]';%20var%20SPAN%20=%20document.createElement('span');%20SPAN.style.cssText%20=%20'background-color:#ff6;%20color:#000';%20%20var%20x%20=%20document.evaluate(XPATH,%20document.body,%20null,%207,%20null);%20for%20(var%20i%20=%200,%20len%20=%20x.snapshotLength;%20i%20<%20len;%20i++){%20var%20node%20=%20x.snapshotItem(i);%20highlight(node,%20word);%20}%20%20})(); |
|
3楼#
发布于:2009-12-20 18:00
一直在用Ubiquity, 新版本的API和0.1的不同, 所以之前写的命令都要转换才能用, Ubiquity wiki上有个升级API教程.
|
|
|