aboutsummaryrefslogtreecommitdiffstats
path: root/auto-bookmark.js
diff options
context:
space:
mode:
authoranekos2012-02-05 14:59:43 +0900
committeranekos2012-02-05 15:00:53 +0900
commitfe4b2d2157a00e6d32961f771f03a9e729cf2d38 (patch)
tree29c7af0f6103246f976ba14a7eb6ebf175091eac /auto-bookmark.js
parenta1d5d3d2c1c0ed8188833386cc0d620d5be7831c (diff)
downloadvimperator-plugins-fe4b2d2157a00e6d32961f771f03a9e729cf2d38.tar.bz2
設定と機能の追加
let g:auto_bookmark_overwrite_target = 1 let g:auto_bookmark_mark = 1
Diffstat (limited to 'auto-bookmark.js')
-rw-r--r--auto-bookmark.js57
1 files changed, 54 insertions, 3 deletions
diff --git a/auto-bookmark.js b/auto-bookmark.js
index 3133c54..829178c 100644
--- a/auto-bookmark.js
+++ b/auto-bookmark.js
@@ -1,5 +1,5 @@
/* NEW BSD LICENSE {{{
-Copyright (c) 2011, anekos.
+Copyright (c) 2011-2012, anekos.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
@@ -35,7 +35,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
// INFO {{{
let INFO =
<>
- <plugin name="AutoBookmark" version="1.1.0"
+ <plugin name="AutoBookmark" version="1.2.0"
href="http://vimpr.github.com/"
summary="Auto update bookmark"
lang="en-US"
@@ -50,7 +50,7 @@ let INFO =
<description><p></p></description>
</item>
</plugin>
- <plugin name="AutoBookmark" version="1.1.0"
+ <plugin name="AutoBookmark" version="1.2.0"
href="http://vimpr.github.com/"
summary="自動更新するブックマーク"
lang="ja"
@@ -77,6 +77,22 @@ let INFO =
if (!__context__.Previous)
__context__.Previous = {};
+ function config (name, defaultValue) { // {{{
+ let value = liberator.globalVariables['auto_bookmark_' + name];
+ return (typeof value === 'undefined') ? defaultValue : value;
+ } // }}}
+
+ function highlightElement (target) { // {{{
+ const Style = 'background-color: orange; color: black; border: dotted 2px blue;';
+
+ let doc = target.ownerDocument;
+ let span = doc.createElement('span');
+ span.setAttribute('style', Style);
+ let range = doc.createRange();
+ range.selectNode(target);
+ range.surroundContents(span);
+ } // }}}
+
function def (obj, names, defaultValue) { // {{{
if (!obj)
return defaultValue;
@@ -98,7 +114,41 @@ let INFO =
win.scrollTo(data.scroll.x, data.scroll.y);
} // }}}
+ function fixTab (tab, data) { // {{{
+ if (config('overwrite_target', true)) {
+ let links = tab.linkedBrowser.contentDocument.querySelectorAll('a[href][target]');
+ for (let [, link] in Iterator(Array.slice(links))) {
+ link.removeAttribute('target');
+ }
+ }
+
+ if (config('mark', true) && data.pages) {
+ let links = tab.linkedBrowser.contentDocument.querySelectorAll('a[href]');
+ for (let [, link] in Iterator(Array.slice(links))) {
+ if (!data.pages.some(function (page) page.URL == link.href))
+ continue;
+ highlightElement(link);
+ }
+ }
+
+ if (config('focus_next', true) && data.pages) {
+ let links = tab.linkedBrowser.contentDocument.querySelectorAll('a[href]');
+ let next = false;
+ let last = data.pages[data.pages.length - 1].URL;
+ for (let [, link] in Iterator(Array.slice(links))) {
+ if (next) {
+ link.focus();
+ break;
+ }
+ next = last === link.href;
+ }
+ }
+
+ } // }}}
+
function initializeTab (tab, data) { // {{{
+ fixTab(tab, data);
+
if (tab.__anekos_auto_bookmark)
return false;
@@ -205,6 +255,7 @@ let INFO =
bookmarks.set(name, data);
updated();
+ fixTab(tab, data);
liberator.echomsg('AutoBookmark: CT Updated - ' + data.name + ' / ' + data.current.URL);
} // }}}