aboutsummaryrefslogtreecommitdiffstats
path: root/statusline-toolbar.js
blob: bebb57d6da7b24323ac8bfe90df163ee20634af2 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
var INFO =
<plugin name="Statusline Toolbar" version="0.1"
        href="http://github.com/vimpr/vimperator-plugins/raw/master/statusline-toolbar.js"
        summary="Append Toolbar to Statusline"
        xmlns="http://vimperator.org/namespaces/liberator">
    <author email="teramako@gmail.com">teramako</author>
    <license>MPL 1.1/GPL 2.0/LGPL 2.1</license>
    <project name="Vimperator" minVersion="3.0"/>
    <description>
      <ul>
        <li>Add toolbar to status-line</li>
        <li>Move the status-bar to the toolbar.</li>
        <li>Make the toolbarbuttons in the toolbar palette configurable
          <ul>
            <li>Can customize by command (ex. <ex>:set statustoolbars=feed-button</ex>)</li>
            <li>Also, can drop the toolbarbutton from Customize Toolbar window</li>
          </ul>
        </li>
      </ul>
    </description>
    <item>
      <tags>'slt' 'statustoolbars'</tags>
      <spec>'statustoolbars' 'slt'</spec>
      <type>stringlist</type>
      <default></default>
      <description>
        <p>
          Add/Remove toolbarbutton of the toolbar palette.
        </p>
      </description>
    </item>
</plugin>

var updater = {
  "star-button": [
    null,
    function rm(elm) {
      $("urlbar-icons").insertBefore(elm, $("go-button"));
    }
  ],
};
var css = <css><![CDATA[
  #liberator-customize-toolbar {
    border: none !important;
    min-width: 5px !important;
    max-height: 17px;
  }
  #liberator-customize-toolbar > :-moz-any(image, toolbarbutton) { max-height: 16px; }
  #liberator-customize-toolbar .statusbar-resizerpanel { display: none; }
  #liberator-customize-toolbar toolbarbutton { padding: 0 !important; }
  #status-bar { background-color: transparent !important; }
]]></css>.toString() +
({
  WINNT: <css></css>,
  Linux: <css></css>,
  Darwin: <css><![CDATA[
    #liberator-customize-toolbar toolbarbutton {
      background: transparent !important;
      border: none !important;
      margin: 0 !important;
      padding: 0 !important;
    }
  ]]></css>
})[Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS].toString();

function $(id) document.getElementById(id);
function createElement (name, attrs) {
  var elm = document.createElement("toolbar");
  for (let [name, value] in Iterator(attrs)) {
    elm.setAttribute(name, value);
  }
  return elm;
}
function customizeDone () {
  window.BrowserToolboxCustomizeDone(true);
}

var gToolbox = gNavToolbox;
var id = "liberator-customize-toolbar";
if (!$(id)) {
  init();
}

function init () {
  styles.addSheet(true, "customize-toolbar", "chrome://*", css, false);

  var t = createToolbar();
  t.appendChild($("status-bar"));
  $("liberator-bottombar").appendChild(t);
  updateSets(t, t.currentSet.split(","), []);

  config.toolbars.statuslinetoolbar = [[id], "Statusline Toolbar"];

  options.add(["statuslinetoolbars", "slt"], "Statusline Toolbar Sets",
   "stringlist", "", {
     toolbar: t,
     getter: function () {
       return this.toolbar.currentSet.split(",").filter(function(id) id != "status-bar").join(",") || "none";
     },
     setter: function (val) {
       if (val == "none")
         val = "";

       let newSets = [],
           removeSets = this.toolbar.currentSet.split(",").filter(function(id) id != "status-bar"),
           index;
       for (let [, id] in Iterator(this.parseValues(val))) {
         let i = removeSets.indexOf(id);
         if (i != -1) {
           newSets.push(id);
           removeSets.splice(i, 1);
           continue;
         }
         let elm = $(id);
         if (elm) {
           if (elm.parentNode !== t) {
             t.appendChild(elm);
             if (updater[id] && typeof updater[id][0] == "function") 
               updater[id][0](elm);
           }
           newSets.push(id);
         } else if (gToolbox.palette.querySelector("#" + id)) {
           newSets.push(id);
         }
       }
       t.currentSet = newSets.join(",");
       t.setAttribute("currentset", newSets.join(","));
       updateSets(this.toolbar, newSets, removeSets);
       document.persist(this.toolbar.id, "currentset");
       customizeDone();
       return val;
     },
     completer: function (context) {
       context.completions = [["none","-"]].concat(Array.map(gToolbox.palette.children, function(elm) {
         return [ elm.id, elm.getAttribute("label") || "-" ];
       }));
     },
     validator: function (ids) {
       return ids.every(function(id) {
         return ($(id) || gToolbox.palette.querySelector("#" + id));
       });
     },
   });

  customizeDone();
}

function updateSets (toolbar, newSets, removeSets) {
  for (let [, id] in Iterator(newSets)) {
     if (updater[id] && typeof updater[id][0] == "function") {
       updater[id][0](id);
     }
  }
 for (let [, id] in Iterator(removeSets)) {
   let elm = $(id);
   if (!elm)
     continue;

   toolbar.removeChild(elm);
   if (updater[id] && typeof updater[id][1] == "function") {
     updater[id][1](elm);
   }
 }
}

function createToolbar () {
  var toolbar = createElement("toolbar", {
    id: id,
    toolbarname: "Liberator Statusline Toolbar",
    toolboxid: "navigator-toolbox",
    mode: "icons",
    iconsize: "small",
    defaulticonsize: "small",
    lockiconsize: "small",
    customizable: "true",
    context: "toolbar-context-menu",
  });
  toolbar.setAttributeNS(NS.uri, "highlight", "ModeMsg");

  var RDF = services.get("rdf");
  var localStore = RDF.GetDataSource("rdf:local-store");
  var currentSet = localStore.GetTarget(
    RDF.GetResource(document.baseURI + "#" + toolbar.id),
    RDF.GetResource("currentset"),
    true);
  if (currentSet) {
    currentSet = currentSet.QueryInterface(Ci.nsIRDFLiteral).Value;
    toolbar.setAttribute("currentset", currentSet);
  }
  return toolbar;
}


// vim: sw=2 ts=2 et:
ar windowWidth = window.innerWidth; } else if (document.all) { var windowWidth = document.body.clientWidth; } else if(document.getElementById){ var windowWidth = window.innerWidth; } var sl_style_base ='display: block;' +'position: absolute;' +'text-align: left;' +'overflow: visible;' +'white-space: pre;' +'font: 12px/12px monospace;'; var sl_style_main =sl_style_base +'top: '+(scrollTop+100)+'px;' +'left: '+windowWidth+'px;' +'padding: 20px;' +'z-index: 999;' +'color: '+sl_tx_color+';'; document.body.innerHTML += '<div id="__sl_main__" style="'+sl_style_main+'">'+sl_patterns[0]+'</div>'; var sl_w = document.getElementById("__sl_main__").clientWidth; var sl_h = document.getElementById("__sl_main__").clientHeight; var sl_style_background =sl_style_base +'top: '+(scrollTop+100)+'px;' +'left: 0px;' +'width: '+windowWidth+'px;' +'height: '+sl_h+'px;' +'z-index: 998;' +'background-color: '+sl_bg_color+';' +'filter: alpha(opacity=0);' +'-moz-opacity: 0.0;' +'opacity: 0.0;'; document.body.innerHTML += '<div id="__sl_background__" style="'+sl_style_background+'"><br /></div>'; //------------------------------------------------------------ // Actions //------------------------------------------------------------ var sl_bg_counter = 0; /** * sl_open (gradually open background) */ sl_open = function() { var oid = "__sl_background__"; var op = sl_bg_counter; var ua = navigator.userAgent document.getElementById(oid).style.filter = 'alpha(opacity=' + (op * 10) + ')'; document.getElementById(oid).style.MozOpacity = op / 10; document.getElementById(oid).style.opacity = op / 10; if ( sl_bg_counter < 8 ) { sl_bg_counter++; setTimeout('sl_open()',100); } else { sl_run(); } } /** * sl_run (move a train) */ sl_run = function() { document.getElementById("__sl_main__").innerHTML = sl_patterns[sl_counter]; document.getElementById("__sl_main__").style.left = windowWidth - sl_position + "px"; if ( sl_counter < 5 ) { sl_counter++; } else { sl_counter = 0; } sl_position += sl_pitch; if ( sl_w + (windowWidth - sl_position) < 0 ) { sl_counter = 0; sl_position = 0; document.body.removeChild(document.getElementById("__sl_main__")); sl_close(); } else { setTimeout('sl_run()',sl_speed); } } /** * sl_close (gradually close background) */ sl_close = function() { var oid = "__sl_background__"; var op = sl_bg_counter; var ua = navigator.userAgent document.getElementById(oid).style.filter = 'alpha(opacity=' + (op * 10) + ')'; document.getElementById(oid).style.MozOpacity = op / 10; document.getElementById(oid).style.opacity = op / 10; if ( sl_bg_counter > 0 ) { sl_bg_counter--; setTimeout('sl_close()',100); } else { next(); document.body.removeChild(document.getElementById(oid)); } } // start actions ! sl_open(); })(); }; //////////////////////////////////////////////////////////////////////////////// // END OF SL //////////////////////////////////////////////////////////////////////////////// let gv = liberator.globalVariables; let defaults = { methods: (gv.alert_default_methods || 'alert').split(/\W+/), time: parseFloat(gv.alert_default_time || '3'), message: gv.alert_default_message || 'Time out!', }; let maxMeow = parseInt(liberator.globalVariables.alert_mex_meow || '60', 10); let sound = Cc["@mozilla.org/sound;1"].createInstance(Ci.nsISound); sound.init(); let gunsou = 'data:image/gif;base64,'+ 'R0lGODlhYAB6AIQeAD8/P/j4+PDw8Ojo6ODg4NjY2NDQ0MjIyMDAwLi4uLCwsKioqKCgoJiYmJCQ'+ 'kIiIiICAgHh4eHBwcGhoaGBgYFhYWFBQUEhISEBAQDg4ODAwMCgoKCAgIBkZGf///////yH+EUNy'+ 'ZWF0ZWQgd2l0aCBHSU1QACH5BAEAAB8ALAAAAABgAHoAAAX+4CeOZCkGiBGYbOu+sCs4lhDfZIFV'+ 'yYr/wFcgQcFoGL5gKxDJWDIQm3IKDDwwF4UCM6CaAoqMQvDQRKTeNCvA2CECAYwj6Q0QMovVUDNB'+ 'q/9WGRNdHwEVGgV/AhYSSWAZEn5/VAJNkQQ9HwMZFJJBTBmEIwENG40wAQIBAwMCrqpwsHCzdC8C'+ 'E1CpExpzVhwKtT9gGAaFBQU+ARK8takDBwoPFRcXGBgW2NgXFhUSEA/fDg0KB8ewJgLLEXARGBkP'+ 'KwPXwTgCF3mFZBVjhRIbDXowRbBA7UI3CBAaNHCAUEKEB+AkTOBGoYLFCtkoJFRQoBWBQwBJWbuA'+ 'pkGGYkr+rHAhEcAAQQaq/FFYQIGaAwUGCMhyRKvnzlUFDiRwEIGC0QoZ/q0gYGEHARIHjqSUh6RE'+ 'oAwVCghocCECAq301NASQKBm1Q8Orj0lIW9CWBcBaDQzUO0CVlqTcKRSNQKBBgVfiqz9QeBCplEM'+ 'mlLDACyvGgEYE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undefined; function singularize (fs, msg) { if (!fs.length) return nop; let [f, arg] = fs[0]; return function () { f(singularize(fs.slice(1), msg), msg, arg); }; } let alertMethods = { alert: function (next, msg) { window.alert(msg); next(); }, pokimon: function (next, msg, arg) { let times = parseInt(arg || '10', 10); let colors = ['red', 'blue', 'yellow']; let elem = content.document.body; let indicator = elem.appendChild(elem.ownerDocument.createElement('div')); let rect = elem.getBoundingClientRect(); indicator.id = 'nyantoro-element-indicator'; let style = 'background-color: ' + colors[0] + ';' + 'opacity: 0.5; z-index: 999;' + 'position: fixed;' + 'top: ' + 0 + 'px;' + 'height: ' + content.innerHeight + 'px;' + 'left: ' + 0 + 'px;' + 'width: ' + content.innerWidth + 'px'; indicator.setAttribute('style', style); let (count = 0) { let handle = setInterval( function () { if (count++ < times) { indicator.style.backgroundColor = colors[count % colors.length]; } else { clearInterval(handle); elem.removeChild(indicator); next(); } }, 100 ); } }, gunsou: function (next, msg, arg) { let sleep = parseFloat(arg || 3) * 1000; let sz = innerWidth / msg.length / 1.5; liberator.echo( <div style="background: white; color: black;"> <table> <tr> <td><img src={gunsou}/></td> <td style={"font-size: " + sz + "px; white-space: nowrap;"}>{msg}</td> </tr> </table> </div> ); setTimeout(next, sleep); }, meow: function (next, msg, arg) { let times = Math.min(parseInt(arg || '3', 10), maxMeow); let handle = setInterval( function () { if (times--) { sound.play(makeURI('http://www.kurinton.net/~snca/files/meow.wav')); } else { clearInterval(handle); next(); } }, 1000 ); }, quit: function (next, msg) { liberator.quit(true); next(); }, SL: function (next, msg) { sl(next); } }; defaults.methods = defaults.methods.map( function (it) { let [_, name, arg] = it.match(/^-?(\w+)(?:=(.*))?$/); return [alertMethods[name] || nop, arg]; } ); commands.addUserCommand( ['alert'], 'Timer alert (:alert [<TIME> | <METHOD> | <MESSAGE>] ...)', function (args) { let methods = [], time = null, message = ''; args.forEach(function (v) { let m, f; if ((m = v.match(/^-(\w+)(?:=(.*))?$/)) && (f = alertMethods[m[1]])) methods.push([f, m[2]]); else if (!time && v.match(/^\d+(\.\d+)?$/)) time = parseFloat(v); else message += ' ' + v; }); if (!message) message = defaults.message; if (!time) time = defaults.time; if (!methods.length) methods = defaults.methods; setTimeout(singularize(methods, message), time * 60 * 1000); }, { argCount: '*', completer: function (context, args) { context.title = ['method', 'Description']; context.completions = [ ['-alert', 'JS alert'], ['-gunsou', 'Spawn horrible sergeant'], ['-meow', 'Meow'], ['-pokimon', 'Like a electric mouse'], ['-quit', 'Quit firefox'], ['-SL', 'Run SL'], ]; } }, true ); })(); // vim:sw=2 ts=2 et si fdm=marker: