aboutsummaryrefslogtreecommitdiffstats
path: root/migratestatusbar.js
blob: 782aa36db0f0c3b366b844324b8a7097ecd340ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * ==VimperatorPlugin==
 * @name            migratestatusbar.js
 * @description     migrate specified elements to status bar.
 * @description-ja  指定した要素をステータスバーに移動する。
 * @author          janus_wel <janus_wel@fb3.so-net.ne.jp>
 * @version         0.10
 * @minversion      2.0pre
 * @maxversion      2.0pre
 * ==/VimperatorPlugin==
 *
 * LICENSE
 *  New BSD License
 *
 * USAGE
 *  this script do not effect in default.
 *  you should set liberator.globalVariables.migrate_elements.
 *  it is the ARRAY has objects like below:
 *
 *      {
 *          id:    id of the target element,
 *          dest:  id of the destination element - this is marker. in fine tuning, used 'after',
 *          after: boolean that show insert position is after 'dest' element.
 *      }
 *
 *  refer: http://d.hatena.ne.jp/janus_wel/20081127/1227807826
 *
 * EXAMPLE
 *  in .vimperatorrc
 *
 *  javascript <<EOM
 *      liberator.globalVariables.migrate_elements = [
 *          {
 *              // star button of awesome bar
 *              id:    'star-button',
 *              dest:  'security-button',
 *              after: true,
 *          },
 *          {
 *              // icon that show the existence of RSS and Atom on current page
 *              id:    'feed-button',
 *              dest:  'security-button',
 *              after: true,
 *          },
 *          {
 *              // favicon of awesome bar
 *              id:    'page-proxy-stack',
 *              dest:  'liberator-statusline',
 *              after: false,
 *          },
 *      ];
 *  EOM
 *
 * ACKNOWLEDGMENT
 *  refer: http://vimperator.org/trac/ticket/17
 *  thanks teramako.
 *
 * */

(function() {

const style = [
    'padding:    1px;',
    'margin:     0;',
    'border:     none;',
    'max-height: 18px;',
    'max-width:  18px;',
].join('');

function migrateElements(elements) {
    const doc = window.document;
    let master = doc.createElement('statusbarpanel');
    master.setAttribute('style', style);

    for (let [, e] in Iterator(elements)) {
        let base = doc.getElementById(e.id);
        let dest = doc.getElementById(e.dest);
        if (!dest || !base) {
            liberator.log('id "' + e.id + '" or "' + e.dest + '" is not exist.', 0);
            continue;
        }

        base.setAttribute('style', style);
        let panel = master.cloneNode(false);
        panel.setAttribute('id', 'panel-' + e.id);
        panel.appendChild(base);
        e.after
            ? insertNodeAfterSpecified(panel, dest)
            : insertNodeBeforeSpecified(panel, dest);
    }
}

// node control
function insertNodeBeforeSpecified(inserted, specified) {
    return specified.parentNode.insertBefore(inserted, specified);
}
function insertNodeAfterSpecified(inserted, specified) {
    var next = specified.nextSibling;
    if(next) {
        return specified.parentNode.insertBefore(inserted, next);
    }
    else {
        return specified.parentNode.appendChild(inserted);
    }
}

// main
let elements = liberator.globalVariables.migrate_elements;
if (elements) migrateElements(elements);

})();

// vim: set sw=4 ts=4 et;
; let modeR = gv('reveal_ie_image_mode_reverse', 'R'); function gv (name, def) let (v = liberator.globalVariables[name]) (v === undefined ? def : v); function getAbsPosition (elem) { let rect = elem.getBoundingClientRect(); return { x: Math.max((rect.left + content.scrollX), content.scrollX), y: Math.max((rect.top + content.scrollY), content.scrollY), }; } function reveal (elem, sec, zura) { if (sec <= 0) sec = 5; let body = elem.ownerDocument.body; let indicator = elem.ownerDocument.createElement('div'); let pos = getAbsPosition(elem); //let rect = elem.getBoundingClientRect(); indicator.id = 'detect-hidden-indicator'; let style = 'background-image: url(' + ieimg + ');' + //'opacity: 0.8;' + //TODO 'background-repeat: repeat;' + 'z-index: 999;' + 'position: absolute; ' + 'top: ' + (pos.y + (zura ? 1 : 0)) + 'px;' + 'height:' + elem.clientHeight + 'px;'+ 'left: ' + pos.x + 'px;' + 'width: ' + elem.clientWidth + 'px'; indicator.setAttribute('style', style); body.appendChild(indicator); setTimeout(function () body.removeChild(indicator), sec * 1000); } // for debug if (0) { let xpath = '/html/body/div[2]/div[3]/table/tbody/tr/td[2]/div/table/tbody/tr/td[2]/div/img'; let node = util.evaluateXPath(xpath).snapshotItem(0); reveal(node, 1); } [ [modeN, false], [modeR, true] ].forEach(function ([mode, zura]) { if (!mode) return; hints.addMode( mode, 'Reveal IE Ctrl-A images.' + (zura ? ' (reverse)' : ''), function (elem, loc, count) { reveal(elem, count, zura); }, function () '//img' ); }); commands.addUserCommand( ['revealimage'], 'Reveal IE Ctrl-A images.', function (args) { hints.show(args.bang ? modeR : modeN); }, { bang: true }, true ); })(); // vim:sw=2 ts=2 et si fdm=marker: