aboutsummaryrefslogtreecommitdiffstats
path: root/keywordstore.js
blob: 2c47973caf79fa921274b88751a7a5072a3d35ae (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
/**
 * ==VimperatorPlugin==
 * @name			KeywordStore.js
 * @description			Store the keywords when ":open" or ":tabopen" launched
 * @author			Y. Maeda (clouds.across.the.moon@gmail.com)
 * @link			
 * @version			0.1
 * ==/VimperatorPlugin==
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Usage:
 *  :kssearch <str>
 * if <str> is nothing, incremental search starts by last keyword used by ":open" or ":tabopen".
 * <str> can be completed by using history of keywords.
 * 
 * Tested on:
 *	Firefox version: 3.0.3
 *	Vimperator version: 1.2
 *		URL: https://addons.mozilla.org/firefox/addon/4891
 */
(function (){
var queue = [];

function push(strs){
	for(let i = strs.length; i-- > 0;){
//		if((strs[i] != "") && !(queue.some(function(s){return s==strs[i]} ))){
		if(strs[i] != "" && queue[0] != strs[i]){
			queue.unshift(strs[i]);
		}
	}
}

function search(str){
	str = str || queue[0];
	liberator.commandline.open("/", str, modes.SEARCH_FORWARD);
}

function suggestions(str){
	return queue
		  .filter(function(i) i.indexOf(str) == 0)
		   .map(function(i) [i, "Stored Keyword"]);
}

function completer(str){
		return [0, suggestions(str)];
}


/* 元のwindow.getShortcutOrURIを退避しておく。*/
var __getShortcutOrURI;
if(!plugins["keywordStore"] || !plugins.keywordStore["__getShortcutOrURI"]){
	__getShortcutOrURI = window.getShortcutOrURI;
}else{
	__getShortcutOrURI = plugins.keywordStore.__getShortcutOrURI;
}

/* ":open"等が呼ばれたときに、キーワードをキューに入れるようにwindow.getShortcutOrURIを置き換える */
window.getShortcutOrURI = function(aURL, aPostDataRef){
	push(aURL.split(/[ \t\r\n]+/).slice(1));
	return __getShortcutOrURI(aURL, aPostDataRef);
};

/***  User Command ***/
commands.addUserCommand(['kssearch'], 'KeywordStore search',
	search,
	{completer: completer}, true);

/***  外からも使えるように ***/
liberator.plugins.keywordStore = {
	push:		push,
	search:		search,
	suggestions:	suggestions,
	completer:	completer,
	queue:		queue,

	/* 元のwindow.getShortcutOrURIの退避先 */
	__getShortcutOrURI:	__getShortcutOrURI
};

})();
/span>); }, /// Gives focus to the main Canvas, to make all keys working well. focusMainFrame:function () { GViMail.getMainCanvas().contentWindow.focus(); }, /// On TabSelect (if Gmail Tab), we will give focus to the main canvas. get isGmail () (/^https?:\/\/mail\.google\.com\//.test(buffer.URL)), /// when you type some key to make an action, habitually, the main canvas looses focus. /// we will add an EventListener on keypress to avoid this. preventLooseFocus:function() { if (liberator.mode == modes.NORMAL && !liberator.mode.isRecording && !(modes.extended & modes.MENU) && !modes.passNextKey && !modes.passAllKeys) { GViMail.focusMainFrame(); } } }; mappings.addUserMap(GViMail.modes, ["zM"], "Closes all fold", function () { GViMail.clickImage('Dm2exe', 'collapse_icon'); }); mappings.addUserMap(GViMail.modes, ["zR"], "Opens all fold", function () { GViMail.clickImage('kPoXId', 'expand_icon'); }); // Let's build the Gmail(v2)-custom hinttags. Follow the comments to understand. var gmail_v2_hinttags = "//span[@selector]" // Menu Settings, Older version, Compose Mail, Inbox, Starred .. Contacts, Labels, turn on/off chat // The [not(ancestor::tr//td[@class='mka4te'])] is to avoid interferring with //td[@class='mka4te']/ancestor::tr/td[5], see Select message in the list below + " | //span[@role='link'][not(ancestor::tr//td[@class='mka4te'])]" // Refresh, Back to "label", Reply to all, Forward, Filter messages like this, ... // You could just use //div[@act] here, but there appears 4 unwanted hints when first-viewing a message + " | //div[@act][not(ancestor::div[contains(concat(' ', @class, ' '), ' zWKgkf ')]) or (ancestor::div[contains(concat(' ', @class, ' '), ' zWKgkf ') and contains(@style, 'visibility')])]" // More actions, Toolbar buttons on RTE (don't use RTE, plain ascii mails are sexier) + " | //*[@unselectable='on']" // Fold and UnFold messages in thread that has an excerpt displayed in grey + " | //div[contains(concat(' ', @class, ' '), ' IUCKJe ')]" // UnFold messages in thread when no excerpt is displayed (blank line) // Such <div>s have a class XoqCub, have another <div> child having the class YrHFdf, and there is no table il all their descendants + " | //*[contains(concat(' ', @class, ' '), ' XoqCub ')]/div[@class='YrHFdf'][count(descendant-or-self::table)=0]" // Star on message list + " | //td[@class='mka4te']/img" // Star on thread list (same subject) + " | //td/span[starts-with(@class, 'lHQn1d')]/img" // Delete all spam messages now + " | //*[@class='rj1J6b'" // Invite x@y.z to Gmail. + " or @class='YCDlS'" // When you delete any message in a thread view, there are links saying "n deleted messages in this conversation. View message or delete forever." + " or @class='u1T3K' or @class='iVE0ue'" // Hide filter options (settings) + " or @class='u7uAnb']" // Select message in the list + " | //td[@class='mka4te']/ancestor::tr/td[5]" // Change picture [Settings] ==> next step still not working + " | //div[@class='c3pyI']/span" // Attach a file + Add event invitation + Rich formatting|Plain text + " | //*[contains(concat(' ', @class, ' '), ' MRoIub ')]" // Check spelling + " | //span[@class='mrKIf']" // Everything that is displayed as image (+ Edit labels) + " | //img[contains(@src, 'cleardot.gif')]" // Reply + Reply to all + Forward + show/hide details + Edit labels // We will not select divs that contains any hintable elements inside + " | //*[@idlink][count(descendant-or-self::span[@role='link'])=0 and count(descendant-or-self::a)=0]" // <label>|x + " | //table[@class='Ir5Jyf']//span" // Settings> Accounts> make_default|edit_info|delete|View_history|Check_mail_now + " | //*[contains(concat(' ', @class, ' '), ' GaVz0 ')]" // Update conversation, Ignore (when someone just posted a message on the thread you're reading & editing) + " | //*[contains(concat(' ', @class, ' '), ' Gf76kb ')]" + " | //*[contains(concat(' ', @class, ' '), ' GRpVjf ')]" //Recently changed to this ... // Show|Hide quoted text + " | //span[contains(concat(' ', @class, ' '), ' WQ9l9c ')]" // + " | //div[contains(concat(' ', @class), ' goog-menuitem')]"; // We provide limited support for Gmail(v1) var gmail_v1_hinttags = "//*[contains(@class, 'lk ') or @class='msc' or @class='ll' or @class='setl' or @class='lkw' or starts-with(@class, 'sc ')] | //tr[@class='rr' or @class='ur']/td[position()=5] | //div/span[contains(@class, 'bz_rbbb')] | //span[@class='l' and contains(@id, 'sl_')]" ; var gmail_hints = use_gmail_v1 ? gmail_v1_hinttags : ""; if (use_gmail_v2) gmail_hints = gmail_hints + (gmail_hints ? " | " : "") + gmail_v2_hinttags; gmail_hints = gmail_hints + (gmail_hints ? " | " : "") + options['hinttags']; // Now: override default hinttags. Override is not the true wording, I'd rather say extend. /*options.add(["hinttags", "ht"], "XPath string of hintable elements activated by 'f' and 'F'", // Gmail uses span[@selector] for labels in the line Select: All, None, Read, Unread, Starred, Unstarred "string", gmail_hints);*/ // This is not the most elegant solution to do this, but I don't manage to find the correct one myself... options.get("hinttags").value=gmail_hints; // When navigation keys (and others) no longer work, type zf to focus to the main frame mappings.addUserMap(GViMail.modes, ["zf"], "Focus main frame", function () { GViMail.focusMainFrame(); }); getBrowser().mTabBox.addEventListener('TabSelect', function(event){ if (GViMail.isGmail) window.setTimeout(function(){GViMail.focusMainFrame();}, 100); }, false); window.addEventListener('keypress', function () { if (GViMail.isGmail) GViMail.preventLooseFocus(); }, true); if (use_gvimail_css && (typeof liberator.globalVariables.styles == 'undefined' || liberator.globalVariables.styles == '')) { liberator.globalVariables.styles = 'style,gvimail'; } })(); // vim:noet: