1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00
elinks/contrib/smjs/smartprefixes_common.js
Kalle Olavi Niemitalo 8d02ae75c8 Link to gitweb at repo.or.cz, rather than pasky.or.cz.
The history converted from CVS is not in repo.or.cz though, so keep
referring to pasky.or.cz for that.  (We don't seem to use
"gitweb.elinks.cz", which is a DNS alias for pasky.or.cz.)

<paakku> Do you think we should maybe point people to gitweb at
    repo.or.cz rather than pasky.or.cz?
<pasky> absolutely
<pasky> actually I thought we already are pointing people at
    repo.or.cz
<pasky> at least there was some movement to do that already, I believe
    :)

[ From commit 9f75e1f094 in ELinks
  0.12.GIT.  --KON ]
2007-07-02 22:41:42 +03:00

105 lines
2.8 KiB
JavaScript

/* Common code for smartprefixes_classic.js and smartprefixes_bookmarks.js. */
/* Helper function for debian_contents and debian_file. */
function debian_package (url, t)
{
url = url.replace(/(\w+):(\w+)/g,
function (all, key, val) { t[key] = val; return ""; })
return 'http://packages.debian.org/cgi-bin/search_contents.pl?word='
+ escape(url.replace(/\s*(\S+)\s*/, '$1'))
+ '&searchmode=' + (t.searchmode || 'searchfilesanddirs')
+ '&case=' + (t["case"] || 'insensitive')
+ '&version=' + (t.version || 'stable')
+ '&arch=' + (t.arch || 'i386')
}
/* javascript:debian_contents("%s"); */
function debian_contents (url)
{
return debian_package (url, { searchmode: "filelist" })
}
/* javascript:debian_file("%s"); */
function debian_file (url)
{
return debian_package (url, { searchmode: "searchfilesanddirs" })
}
/* javascript:cvsweb("http://cvsweb.elinks.cz/cvsweb.cgi/", "elinks", "%s"); */
function cvsweb (base, project, url)
{
/* <file>:<revision>[-><revision>] */
url = url.replace(/^(.*):(.*?)(?:->(.*))?$/, "$1 $2 $3");
var parts = url.split(" ");
if (parts[3]) {
elinks.alert('this smartprefix takes only one to three arguments');
return "";
}
var file = parts[0], oldrev = parts[1], newrev = parts[2];
if (!file) {
elinks.alert('no file given');
return "";
}
if (newrev)
return base + project + "/" + file + ".diff"
+ "?r1=" + oldrev + "&r2=" + newrev + "&f=u";
if (oldrev)
return base + "~checkout~/" + project + "/" + file
+ (oldrev != "latest" && "?rev=" + oldrev || "");
return base + project + "/" + file
}
/* javascript:gitweb("http://repo.or.cz/gitweb.cgi", "elinks.git", "%s"); */
function gitweb(base, project, url)
{
var parts = url.match(/^(search|summary|shortlog|log|blob|commit|commitdiff|history|tree|tag)(\s(.*))?/);
var query = '?p=' + project;
if (parts) {
query += ';a=' + parts[1];
/* If the extra arg is not for searching assume it is an ID. */
if (parts[1] == 'search' && parts[3])
query += ';s=' + escape(parts[3]);
else if ((parts[1] == 'blob' || parts[1] == 'history' || parts[1] == 'tree') && parts[3])
query += ';f=' + escape(parts[3]);
else if (parts[3])
query += ';h=' + escape(parts[3]);
} else {
query += ';a=summary';
}
return base + query;
}
/* javascript:gmane("%s") */
function gmane (url)
{
var v = url.split(' ');
var group = v[0], words = v.slice(1).join(' ');
if (!words) return "";
return "http://search.gmane.org/search.php?query=" + words
+ "&group=" + group;
}
/* javascript:bugzilla('http://bugzilla.elinks.cz/', "%s"); */
function bugzilla (base_url, arguments)
{
if (!arguments || arguments == '') return base_url;
if (arguments.match(/^[\d]+$/))
return base_url + 'show_bug.cgi?id=' + arguments;
return base_url + 'buglist.cgi?short_desc_type=allwordssubstr'
+ '&short_desc=' + escape(arguments);
}