From 45abe5f31645c3c4f6247f1f9315264f49f4b39e Mon Sep 17 00:00:00 2001 From: drry Date: Fri, 18 Apr 2008 14:09:00 +0000 Subject: lang/javascript/vimperator-plugins/trunk/direct_bookmark.js: * DOM に変更しました。 * ほか。 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@9729 d0d07461-0603-4401-acd4-de1884942a52 --- direct_bookmark.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/direct_bookmark.js b/direct_bookmark.js index 462a106..3b9ea79 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -135,21 +135,20 @@ } // copied from Pagerization (c) id:ofk - function parseHTML(str, ignore_tags){ + function parseHTML(str, ignoreTags) { var exp = "^[\\s\\S]*?]*)?>|[\\S\\s]*$"; - if (ignore_tags) { - if (typeof ignore_tag != "object") ignore_tags = [ignore_tags]; - ignore_tags = ignore_tags.filter(function(tag) { - if (tag[tag.length - 1] != "/") return true; - tag = tag.replace(/\/$/, ""); - exp += "|<" + tag + "(?:\\s[^>]*|/)?>(?:[\\s\\S]*?)?"; - return false; - }); - if (ignore_tags.length > 0) { - ignore_tags = ignore_tags.length > 1 - ? "(?:" + ignore_tags.join("|") + ")" - : String(ignore_tags); - exp += "|<" + ignore_tags + "(?:\\s[^>]*|/)?>|"; + if (ignoreTags) { + if (typeof ignoreTags == "string") ignoreTags = [ignoreTags]; + var stripTags = []; + ignoreTags = ignoreTags.filter(function(tag) { + if (tag[tag.length - 1] == "/") return true; + stripTags.push(tag); + }).map(function(tag) tag.replace(/\/$/, "")); + if (stripTags.length > 0) { + stripTags = stripTags.length > 1 + ? "(?:" + stripTags.join("|") + ")" + : String(stripTags); + exp += "|<" + stripTags + "(?:\\s[^>]*|/)?>|"; } } str = str.replace(new RegExp(exp, "ig"), ""); @@ -157,6 +156,10 @@ var range = document.createRange(); range.setStartAfter(window.content.document.body); res.documentElement.appendChild(res.importNode(range.createContextualFragment(str), true)); + if (ignoreTags) ignoreTags.forEach(function(tag) { + var elements = res.getElementsByTagName(tag); + for (var i = elements.length, el; el = elements.item(--i); el.parentNode.removeChild(el)); + }); return res; } @@ -374,16 +377,13 @@ function getTags(arg){ var user,password; - var tags = liberator.plugins.direct_bookmark.tags; - liberator.plugins.direct_bookmark.tags = []; + var tags = []; useServicesByTag.split(/\s*/).forEach(function(service){ var currentService = services[service] || null; [user,password] = currentService.account ? getUserAccount.apply(currentService,currentService.account) : [null, null]; tags = tags.concat(currentService.tags(user,password)); }); - // unique tags - for(var i = tags.length; i --> 0; tags.indexOf(tags[i]) == i || tags.splice(i, 1)); - liberator.plugins.direct_bookmark.tags = tags.sort(); + liberator.plugins.direct_bookmark.tags = tags.filter(function(e,i,a) a.indexOf(e) == i).sort(); } liberator.commands.addUserCommand(['btags'],"Update Social Bookmark Tags",getTags,{}); liberator.commands.addUserCommand(['bentry'],"Goto Bookmark Entry Page", -- cgit v1.2.3