diff options
author | drry | 2008-04-18 11:10:46 +0000 |
---|---|---|
committer | drry | 2008-04-18 11:10:46 +0000 |
commit | 885f89c78c53b2a4e5c37be86c08acfee0ca7585 (patch) | |
tree | b5e6376210c739899b72989932c147f9b6463076 /direct_bookmark.js | |
parent | 3f7d71f9a90def579664fde786853b5a8a247d9e (diff) | |
download | vimperator-plugins-885f89c78c53b2a4e5c37be86c08acfee0ca7585.tar.bz2 |
lang/javascript/vimperator-plugins/trunk/direct_bookmark.js:
* `parseHTML()`
* removed a `strip_tags`. now you can add a tailing slash suffix instead.
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@9713 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'direct_bookmark.js')
-rw-r--r-- | direct_bookmark.js | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/direct_bookmark.js b/direct_bookmark.js index ed82f7b..eebcf5d 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -135,22 +135,25 @@ }
// copied from Pagerization (c) id:ofk
- function parseHTML(str, strip_tags, ignore_tags){
- var exp = '^[\\s\\S]*?<html(?:\\s[^>]*)?>|</html\\s*>[\\S\\s]*$';
- if (strip_tags) {
- strip_tags = strip_tags instanceof Array && strip_tags.length > 1
- ? '(?:' + strip_tags.join('|') + ')'
- : String(strip_tags);
- exp += '|<' + strip_tags + '(?:\\s[^>]*)?>|</' + strip_tags + '\\s*>';
- }
+ function parseHTML(str, ignore_tags){
+ var exp = "^[\\s\\S]*?<html(?:\\s[^>]*)?>|</html\\s*>[\\S\\s]*$";
if (ignore_tags) {
if (!(ignore_tags instanceof Array)) ignore_tags = [ignore_tags];
- exp += '|' + ignore_tags.map(function(tag) {
- return '<' + tag + '(?:\\s[^>]*)?>.*?</' + tag + '\\s*>';
- }).join('|');
+ ignore_tags = ignore_tags.filter(function(tag) {
+ if (tag[tag.length - 1] != "/") return true;
+ tag = tag.replace(/\/$/, "");
+ exp += "|" + "<" + tag + "(?:\\s[^>]*)?>.*?</" + tag + "\\s*>";
+ return false;
+ });
+ if (ignore_tags.length > 0) {
+ ignore_tags = ignore_tags.length > 1
+ ? "(?:" + ignore_tags.join("|") + ")"
+ : String(ignore_tags);
+ exp += "|<" + ignore_tags + "(?:\\s[^>]*)?>|</" + ignore_tags + "\\s*>";
+ }
}
- str = str.replace(new RegExp(exp, 'ig'), '');
- var res = document.implementation.createDocument(null, 'html', null);
+ str = str.replace(new RegExp(exp, "ig"), "");
+ var res = document.implementation.createDocument(null, "html", null);
var range = document.createRange();
range.setStartAfter(window.content.document.body);
res.documentElement.appendChild(res.importNode(range.createContextualFragment(str), true));
@@ -266,7 +269,7 @@ xhr.open("GET","http://b.hatena.ne.jp/my",false);
xhr.send(null);
- var mypage_html = parseHTML(xhr.responseText, ['img', 'script']);
+ var mypage_html = parseHTML(xhr.responseText, ['img', 'script/']);
var tags = getElementsByXPath("//ul[@id=\"taglist\"]/li/a",mypage_html);
tags.forEach(function(tag){
@@ -341,7 +344,7 @@ xhr.open("GET","http://clip.livedoor.com/clip/add?link=http://example.example/",false);
xhr.send(null);
- var mypage_html = parseHTML(xhr.responseText, ['img', 'script']);
+ var mypage_html = parseHTML(xhr.responseText, ['img', 'script/']);
var tags = getElementsByXPath("id(\"tag_list\")/span",mypage_html);
tags.forEach(function(tag){
|