mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 21:22:26 +01:00
Make :style better
This commit is contained in:
@@ -56,7 +56,7 @@ liberator.Bookmarks = function () //{{{
|
|||||||
this.__defineGetter__("keywords",
|
this.__defineGetter__("keywords",
|
||||||
function () [[k[2], k[1], k[0]] for each (k in self.bookmarks) if (k[2])]);
|
function () [[k[2], k[1], k[0]] for each (k in self.bookmarks) if (k[2])]);
|
||||||
|
|
||||||
this.__iterator__ = (val for each (val in self.bookmarks));
|
this.__iterator__ = function () (val for each (val in self.bookmarks));
|
||||||
|
|
||||||
function loadBookmark(node)
|
function loadBookmark(node)
|
||||||
{
|
{
|
||||||
@@ -242,16 +242,14 @@ liberator.Bookmarks = function () //{{{
|
|||||||
|
|
||||||
liberator.commands.add(["bma[rk]"],
|
liberator.commands.add(["bma[rk]"],
|
||||||
"Add a bookmark",
|
"Add a bookmark",
|
||||||
function (args)
|
function (args, special)
|
||||||
{
|
{
|
||||||
var url = args.arguments.length == 0 ? liberator.buffer.URL : args.arguments[0];
|
var url = args.arguments.length == 0 ? liberator.buffer.URL : args.arguments[0];
|
||||||
var title = args["-title"] || (args.arguments.length == 0 ? liberator.buffer.title : null);
|
var title = args["-title"] || (args.arguments.length == 0 ? liberator.buffer.title : null);
|
||||||
if (!title)
|
|
||||||
title = url;
|
|
||||||
var keyword = args["-keyword"] || null;
|
var keyword = args["-keyword"] || null;
|
||||||
var tags = args["-tags"] || [];
|
var tags = args["-tags"] || [];
|
||||||
|
|
||||||
if (liberator.bookmarks.add(false, title, url, keyword, tags))
|
if (liberator.bookmarks.add(false, title, url, keyword, tags, special))
|
||||||
{
|
{
|
||||||
var extra = "";
|
var extra = "";
|
||||||
if (title != url)
|
if (title != url)
|
||||||
@@ -310,14 +308,28 @@ liberator.Bookmarks = function () //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// if starOnly = true it is saved in the unfiledBookmarksFolder, otherwise in the bookmarksMenuFolder
|
// if starOnly = true it is saved in the unfiledBookmarksFolder, otherwise in the bookmarksMenuFolder
|
||||||
add: function (starOnly, title, url, keyword, tags)
|
add: function (starOnly, title, url, keyword, tags, force)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var uri = PlacesUIUtils.createFixedURI(url);
|
var uri = PlacesUIUtils.createFixedURI(url);
|
||||||
var id = bookmarksService.insertBookmark(
|
if (!force)
|
||||||
bookmarksService[starOnly ? "unfiledBookmarksFolder" : "bookmarksMenuFolder"],
|
{
|
||||||
uri, -1, title);
|
for (let bmark in cache)
|
||||||
|
{
|
||||||
|
if (bmark[0] == uri.spec)
|
||||||
|
{
|
||||||
|
var id = bmark[4];
|
||||||
|
if (title)
|
||||||
|
bookmarksService.setItemTitle(id, title);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (id == undefined)
|
||||||
|
id = bookmarksService.insertBookmark(
|
||||||
|
bookmarksService[starOnly ? "unfiledBookmarksFolder" : "bookmarksMenuFolder"],
|
||||||
|
uri, -1, title || url);
|
||||||
if (!id)
|
if (!id)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -34,11 +34,16 @@ liberator.Buffer = function () //{{{
|
|||||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
const arrayIter = liberator.util.arrayIter;
|
|
||||||
|
|
||||||
var zoomLevels = [ 1, 10, 25, 50, 75, 90, 100,
|
var zoomLevels = [ 1, 10, 25, 50, 75, 90, 100,
|
||||||
120, 150, 200, 300, 500, 1000, 2000 ];
|
120, 150, 200, 300, 500, 1000, 2000 ];
|
||||||
|
|
||||||
|
const arrayIter = liberator.util.arrayIter;
|
||||||
|
/* Can't reference liberator inside Styles --
|
||||||
|
* it's a global object, and liberator disappears
|
||||||
|
* with this window.
|
||||||
|
*/
|
||||||
|
const util = liberator.util;
|
||||||
|
|
||||||
function Styles(name, store, serial)
|
function Styles(name, store, serial)
|
||||||
{
|
{
|
||||||
const XHTML = "http://www.w3.org/1999/xhtml";
|
const XHTML = "http://www.w3.org/1999/xhtml";
|
||||||
@@ -60,18 +65,35 @@ liberator.Buffer = function () //{{{
|
|||||||
|
|
||||||
if (sheets.some(function (s) s[0] == filter && s[1] == css))
|
if (sheets.some(function (s) s[0] == filter && s[1] == css))
|
||||||
return null;
|
return null;
|
||||||
|
let filter = filter.split(",");
|
||||||
sheets.push([filter, css]);
|
sheets.push([filter, css]);
|
||||||
this.registerSheet(cssUri(wrapCSS(filter, css)));
|
this.registerSheet(cssUri(wrapCSS(filter, css)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.removeSheet = function (number)
|
this.removeSheet = function (filter, index)
|
||||||
{
|
{
|
||||||
if (number >= sheets.length)
|
if (filter == undefined)
|
||||||
return false;
|
filter = "";
|
||||||
let sheet = sheets.splice(number)[0];
|
/* Find all sheets which match the filter */
|
||||||
let uri =
|
let matches = [s for (s in Iterator(sheets)) if (filter == "" || s[1][0].indexOf(filter) >= 0)];
|
||||||
this.unregisterSheet(cssUri(wrapCSS(sheet[0], sheet[1])));
|
|
||||||
|
if (matches.length == 0 && sheets[Number(filter)])
|
||||||
|
matches.push([filter, sheets[filter]]);
|
||||||
|
else if (!isNaN(index))
|
||||||
|
matches = (index < matches.length) ? [matches[index]] : [];
|
||||||
|
else if (index)
|
||||||
|
matches = [m for each (m in matches) if (m[1][1] == index)];
|
||||||
|
|
||||||
|
for (let [,[i, sheet]] in Iterator(matches.reverse()))
|
||||||
|
{
|
||||||
|
this.unregisterSheet(cssUri(wrapCSS(sheet[0], sheet[1])));
|
||||||
|
sheet[0] = sheet[0].filter(function (f) f != filter);
|
||||||
|
if (sheet[0].length && isNaN(filter))
|
||||||
|
this.registerSheet(cssUri(wrapCSS(sheet[0], sheet[1])));
|
||||||
|
else
|
||||||
|
sheets.splice(i, 1);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,12 +113,15 @@ liberator.Buffer = function () //{{{
|
|||||||
|
|
||||||
function wrapCSS(filter, css)
|
function wrapCSS(filter, css)
|
||||||
{
|
{
|
||||||
if (filter == "*")
|
if (filter[0] == "*")
|
||||||
return css;
|
return "@namespace url(" + XHTML + ");\n" + css;
|
||||||
let selector = /[\/:]/.test(filter) ? "url" : "domain";
|
let selectors = filter.map(function (part) (/\/$/.test(part) ? "url-prefix" :
|
||||||
filter = filter.replace('"', "%22", "g");
|
/\/:/.test(part) ? "url"
|
||||||
|
: "domain")
|
||||||
|
+ '("' + part.replace(/"/g, "%22") + '")')
|
||||||
|
.join(", ");
|
||||||
return "@namespace url(" + XHTML + ");\n" +
|
return "@namespace url(" + XHTML + ");\n" +
|
||||||
"@-moz-document " + selector + '("' + filter + '") {\n' + css + "\n}\n";
|
"@-moz-document " + selectors + "{\n" + css + "\n}\n";
|
||||||
/* } vim */
|
/* } vim */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +150,7 @@ liberator.Buffer = function () //{{{
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var doc = document.implementation.createDocument(XHTML, "doc", null);
|
var doc = document.implementation.createDocument(XHTML, "doc", null);
|
||||||
doc.documentElement.appendChild(liberator.util.xmlToDom(
|
doc.documentElement.appendChild(util.xmlToDom(
|
||||||
<html><head><link type="text/css" rel="stylesheet" href={cssUri(css)}/></head></html>, doc));
|
<html><head><link type="text/css" rel="stylesheet" href={cssUri(css)}/></head></html>, doc));
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
@@ -151,8 +176,11 @@ liberator.Buffer = function () //{{{
|
|||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Styles.prototype = {
|
||||||
|
get sites() util.uniq(util.flatten([v[0] for ([k, v] in this)])),
|
||||||
|
};
|
||||||
|
|
||||||
let styles = liberator.storage.newObject(styles, Styles, false);
|
let styles = liberator.storage.newObject("styles", Styles, false);
|
||||||
|
|
||||||
function setZoom(value, fullZoom)
|
function setZoom(value, fullZoom)
|
||||||
{
|
{
|
||||||
@@ -672,8 +700,8 @@ liberator.Buffer = function () //{{{
|
|||||||
{
|
{
|
||||||
let str = liberator.template.tabular(["", "Filter", "CSS"],
|
let str = liberator.template.tabular(["", "Filter", "CSS"],
|
||||||
["padding: 0 1em 0 1ex; vertical-align: top", "padding: 0 1em 0 0; vertical-align: top"],
|
["padding: 0 1em 0 1ex; vertical-align: top", "padding: 0 1em 0 0; vertical-align: top"],
|
||||||
([i, style[0], style[1]] for ([i, style] in styles)
|
([i, style[0].join(","), style[1]] for ([i, style] in styles)
|
||||||
if (!filter || style[0] == filter)));
|
if (!filter || style[0].indexOf(filter) >= 0)));
|
||||||
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
|
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -685,20 +713,23 @@ liberator.Buffer = function () //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (filter) [0, [
|
completer: function (filter) [0, liberator.completion.filter(
|
||||||
[content.location.host, ""],
|
[[content.location.host, ""],
|
||||||
[content.location.href, ""]]
|
[content.location.href, ""]]
|
||||||
.concat([[s[0], ""] for ([i, s] in styles)])
|
.concat([[s, ""] for each (s in styles.sites)])
|
||||||
],
|
, filter)],
|
||||||
hereDoc: true,
|
hereDoc: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["dels[tyle]"],
|
liberator.commands.add(["dels[tyle]"],
|
||||||
"Remove a user stylesheet",
|
"Remove a user stylesheet",
|
||||||
function (args) { styles.removeSheet(parseInt(args.arguments[0])); },
|
function (args) { styles.removeSheet.apply(styles, args.arguments); },
|
||||||
{
|
{
|
||||||
completer: function (filter) [0, [[i, s[0] + ": " + s[1].replace("\n", "\\n")] for ([i, s] in styles)]],
|
completer: function (filter) [0, liberator.completion.filter(
|
||||||
argCount: 1
|
[[i, s[0].join(",") + ": " + s[1].replace("\n", "\\n")] for ([i, s] in styles)]
|
||||||
|
.concat([[s, ""] for each (s in styles.sites)])
|
||||||
|
, filter)],
|
||||||
|
argCount: "*",
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["vie[wsource]"],
|
liberator.commands.add(["vie[wsource]"],
|
||||||
@@ -1382,9 +1413,7 @@ liberator.Buffer = function () //{{{
|
|||||||
// add the frame indicator
|
// add the frame indicator
|
||||||
var doc = frames[next].document;
|
var doc = frames[next].document;
|
||||||
var indicator =
|
var indicator =
|
||||||
<div id="liberator-frame-indicator"
|
<div id="liberator-frame-indicator"/>;
|
||||||
style="background-color: red; opacity: 0.5; z-index: 999
|
|
||||||
position: fixed; top: 0; bottom: 0; left: 0; right: 0"/>;
|
|
||||||
doc.body.appendChild(liberator.util.xmlToDom(indicator));
|
doc.body.appendChild(liberator.util.xmlToDom(indicator));
|
||||||
|
|
||||||
// remove the frame indicator
|
// remove the frame indicator
|
||||||
@@ -1910,7 +1939,7 @@ liberator.template = {
|
|||||||
({
|
({
|
||||||
liberator.template.map(item.extra, function (e)
|
liberator.template.map(item.extra, function (e)
|
||||||
<>{e[0]}: <span style={"color: " + e[2]}>{e[1]}</span></>,
|
<>{e[0]}: <span style={"color: " + e[2]}>{e[1]}</span></>,
|
||||||
<> </>)
|
<![CDATA[ ]]>/* Non-breaking space */)
|
||||||
})
|
})
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
@@ -1930,7 +1959,7 @@ liberator.template = {
|
|||||||
{
|
{
|
||||||
this.map2(elems, function (idx, val)
|
this.map2(elems, function (idx, val)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{idx == index ? <span style="color: blue;">{">"}</span> : ""}</td> <!-- } //vim :( -->
|
<td style="color: blue;">{idx == index ? ">" : ""}</td>
|
||||||
<td>{Math.abs(idx - index)}</td>
|
<td>{Math.abs(idx - index)}</td>
|
||||||
<td style="width: 250px; max-width: 500px; overflow: hidden;">{val.title}</td>
|
<td style="width: 250px; max-width: 500px; overflow: hidden;">{val.title}</td>
|
||||||
<td><a href="#" class="hl-URL jump-list">{val.URI.spec}</a></td>
|
<td><a href="#" class="hl-URL jump-list">{val.URI.spec}</a></td>
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ liberator.Completion = function () //{{{
|
|||||||
var complist = list[i][0] instanceof Array ? list[i][0] : [list[i][0]];
|
var complist = list[i][0] instanceof Array ? list[i][0] : [list[i][0]];
|
||||||
for (let j = 0; j < complist.length; j++)
|
for (let j = 0; j < complist.length; j++)
|
||||||
{
|
{
|
||||||
var item = complist[j];
|
var item = String(complist[j]);
|
||||||
if (ignorecase)
|
if (ignorecase)
|
||||||
item = item.toLowerCase();
|
item = item.toLowerCase();
|
||||||
|
|
||||||
|
|||||||
@@ -172,6 +172,20 @@ liberator.util = { //{{{
|
|||||||
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
escapeRegex: function (str)
|
||||||
|
{
|
||||||
|
return str.replace(/([\\{}()[\].?*+])/g, "\\$1");
|
||||||
|
},
|
||||||
|
|
||||||
|
// Flatten an array:
|
||||||
|
// [["foo", "bar"], ["baz"]] -> ["foo", "bar", "baz"]
|
||||||
|
flatten: function (ary)
|
||||||
|
{
|
||||||
|
if (ary.length == 0)
|
||||||
|
return [];
|
||||||
|
return Array.concat.apply(Array, ary);
|
||||||
|
},
|
||||||
|
|
||||||
formatBytes: function (num, decimalPlaces, humanReadable)
|
formatBytes: function (num, decimalPlaces, humanReadable)
|
||||||
{
|
{
|
||||||
const unitVal = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
const unitVal = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
||||||
@@ -416,6 +430,18 @@ liberator.util = { //{{{
|
|||||||
return urls;
|
return urls;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
uniq: function (ary)
|
||||||
|
{
|
||||||
|
let ret = [];
|
||||||
|
for (let [,item] in Iterator(ary.sort()))
|
||||||
|
{
|
||||||
|
if (item != last || !ret.length)
|
||||||
|
ret.push(item);
|
||||||
|
var last = item;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
|
||||||
xmlToDom: function (node, doc)
|
xmlToDom: function (node, doc)
|
||||||
{
|
{
|
||||||
switch (node.nodeKind())
|
switch (node.nodeKind())
|
||||||
|
|||||||
Reference in New Issue
Block a user