From 3028fb3b3bae6c9825eefb6aef5c940823e1d104 Mon Sep 17 00:00:00 2001
From: anekos
Date: Thu, 18 Feb 2010 07:49:44 +0000
Subject: URLが並んで複数アル場合に、初めの一つしか処置されない問題の応急処置
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@36794 d0d07461-0603-4401-acd4-de1884942a52
---
appendAnchor.js | 58 ++++++++++++++++++++++++++++++++-------------------------
1 file changed, 33 insertions(+), 25 deletions(-)
(limited to 'appendAnchor.js')
diff --git a/appendAnchor.js b/appendAnchor.js
index 17ede34..76a92f0 100644
--- a/appendAnchor.js
+++ b/appendAnchor.js
@@ -3,7 +3,7 @@ let PLUGIN_INFO =
appendAnchor
append anchors to texts look like url.
リンク中の URL っぽいテキストにアンカーをつける。
- 0.4.2
+ 0.4.3
SAKAI, Kazuaki
2.0pre
2.3
@@ -54,39 +54,47 @@ let PLUGIN_INFO =
// register command
liberator.modules.commands.addUserCommand(['anc'], 'append anchors to texts look like url',
function(arg) {
- const doc = window.content.document;
- const range = doc.createRange();
+ function append() {
+ let result = 0;
+ const doc = window.content.document;
+ const range = doc.createRange();
- let nodes = util.evaluateXPath(xpathQueryPlainText);
- for (let node in nodes) {
- while (node) {
- range.selectNode(node)
+ let nodes = util.evaluateXPath(xpathQueryPlainText);
+ for (let node in nodes) {
+ while (node) {
+ range.selectNode(node)
- // search string like URL
- let start = range.toString().search(regexpLikeURL);
- // go to next node when there is nothing look like URL in current node
- if (!(start > -1)) break;
+ // search string like URL
+ let start = range.toString().search(regexpLikeURL);
+ // go to next node when there is nothing look like URL in current node
+ if (!(start > -1)) break;
- // build URL
- let href = 'h' + RegExp.$1 + '://' + RegExp.$2;
+ result++;
- // reset range
- range.setStart(node, start);
- range.setEnd(node, start + RegExp.lastMatch.length);
+ // build URL
+ let href = 'h' + RegExp.$1 + '://' + RegExp.$2;
- // build anchor element
- let anchor = doc.createElement('a');
- anchor.setAttribute('href', href);
- range.surroundContents(anchor);
+ // reset range
+ range.setStart(node, start);
+ range.setEnd(node, start + RegExp.lastMatch.length);
- // insert
- range.insertNode(anchor);
+ // build anchor element
+ let anchor = doc.createElement('a');
+ anchor.setAttribute('href', href);
+ range.surroundContents(anchor);
- // iterate
- node = node.nextSibling.nextSibling.nextSibling;
+ // insert
+ range.insertNode(anchor);
+
+ // iterate
+ node = node.nextSibling.nextSibling.nextSibling;
+ }
}
+ range.detach();
+ return result;
}
- range.detach();
+ for (let i = 0; i < 20 && append(); i++)
+ ;
},
{},
true
--
cgit v1.2.3