-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathUserChrome.js
138 lines (124 loc) · 6.87 KB
/
UserChrome.js
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
/// Create in Firefox-Install-Directory/UserChrome.js - a minimal bootstrap to run javascript snippets on Firefox startup - by AveYo
/// Requires: Firefox-Install-Directory/defaults/pref/enable-UserChrome.js
try {
let { classes: Cc, interfaces: Ci, manager: Cm } = Components;
const { XPCOMUtils } = Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
XPCOMUtils.defineLazyModuleGetters(this, { Services: "resource://gre/modules/Services.jsm" });
function UserChromeJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); }
UserChromeJS.prototype = { observe:function(s) {s.addEventListener('DOMContentLoaded', this, {once:true});}, handleEvent:function(evt) {
let document = evt.originalTarget; let window = document.defaultView; let location = window.location; let console = window.console;
let skip = /^chrome:(?!\/\/(global\/content\/(commonDialog|alerts\/alert)|browser\/content\/webext-panels)\.x?html)|about:(?!blank)/i;
if (!window._gBrowser || !skip.test(location.href)) return; window.gBrowser = window._gBrowser;
/*********************************************** PLACE JS SNIPPETS BELOW THIS LINE! ***********************************************/
// ==UserScript==
// @name OneClickSearch redux v3
// @author AveYo
// @description see resource:///modules/UrlbarSearchOneOffs.jsm
// @include main
// @onlyonce
// ==/UserScript==
if (typeof UC === 'undefined') UC = {};
UC.OneClickSearch = {
init: function() {
XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarSearchOneOffs: "resource:///modules/UrlbarSearchOneOffs.jsm",
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
});
this.UrlbarSearchOneOffs.prototype.handleSearchCommand = function (event, searchMode) {
let button = this.selectedButton;
if (button == this.view.oneOffSearchButtons.settingsButtonCompact) {
this.input.controller.engagementEvent.discard(); this.selectedButton.doCommand(); return;
}
let engine = Services.search.getEngineByName(searchMode.engineName); let { where, params } = this._whereToOpen(event);
if (engine && !event.shiftKey) {
this.input.handleNavigation({
event, oneOffParams: { openWhere: where, openParams: params, engine: this.selectedButton.engine, },
});
this.selectedButton = null; return;
}
let startQueryParams = {allowAutofill: !searchMode.engineName && searchMode.source != UrlbarUtils.RESULT_SOURCE.SEARCH, event, };
this.input.searchMode = searchMode; this.input.startQuery(startQueryParams); this.selectedButton = button;
};
console.info('\u2713 OneClickSearch');
}
};
UC.OneClickSearch.init();
// ==UserScript==
// @name Addressbar redux v3
// @author AveYo
// @description Open input as URL on Enter - press Tab to Search instead
// @include main
// @onlyonce
// ==/UserScript==
if (typeof UC === 'undefined') UC = {};
UC.Addressbar = {
init: function() {
XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarView: "resource:///modules/UrlbarView.jsm",
UrlbarInput: "resource:///modules/UrlbarInput.jsm",
});
this.UrlbarView.prototype.onQueryResults_uc = this.UrlbarView.prototype.onQueryResults;
this.UrlbarView.prototype.onQueryResults = function (queryContext) {
this.onQueryResults_uc(queryContext);
if (this.selectedElementIndex == 0 && !this.input.searchMode && !this.oneOffSearchButtons.selectedButton) {
let result = this.getResultAtIndex(0);
if (result?.payload.suggestion || result?.payload.query) {this.clearSelection();}
}
};
this.UrlbarInput.prototype.handleCommand = function (event = null) {
let element = this.view.selectedElement;
let result = this.view.getResultFromElement(element);
let btn = this.view.oneOffSearchButtons.selectedButton;
if (result && result?.payload.keyword) {
this.pickResult(result, event);
}
else if (btn && (event instanceof this.window.MouseEvent === false || event.target == btn)) {
this.view.oneOffSearchButtons.handleSearchCommand(
event, {engineName: btn.engine?.name, source: btn.source, entry: "oneoff"}
);
}
else if (this.searchMode || this.view.selectedElementIndex == 0 || (this.value && /\s/.test(this.value))) {
this.handleNavigation({event});
}
else if (this.value && /\s/.test(this.value) === false) {
let flags = Ci.nsIURIFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS;
if (this.isPrivate) {flags |= Ci.nsIURIFixup.FIXUP_FLAG_PRIVATE_CONTEXT;}
let {preferredURI: uri, postData} = Services.uriFixup.getFixupURIInfo(this.value, flags);
this._loadURL(uri.spec, event, this._whereToOpen(event), {});
}
};
console.info('\u2713 Addressbar');
}
};
UC.Addressbar.init();
// ==UserScript==
// @name SimpleHotkeysOverride v2
// @author AveYo
// @description see Firefox-Install-Directory/browser/omni.ja/chrome/browser/content/browser/browser.xhtml - 'mainKeyset'
// @include main
// @onlyonce
// ==/UserScript==
if (typeof UC === 'undefined') UC = {};
UC.SimpleHotkeysOverride = {
init: function() {
let hotkeys = function (id, modifiers, key, cmd, oncmd) {
const k = window.document.createXULElement("key"); k.id = id;
if (!key.startsWith("VK_")) {k.setAttribute("key", key);} else {k.setAttribute("keycode", key); k.setAttribute("event", "keydown");}
k.setAttribute("modifiers", modifiers); if (cmd) k.setAttribute("command", cmd); if (oncmd) k.setAttribute("oncommand", oncmd);
window.document.getElementById("mainKeyset").appendChild(k);
};
// Example 1: Ctrl Shift B for Library (set either command or oncommand like in browser.xhtml - here, command set, oncommand empty)
hotkeys("hot_library", "accel,shift", "VK_B", "Browser:ShowAllBookmarks", "");
// Example 2: B to toggle Bookmarks toolbar (set either command or oncommand like in browser.xhtml - here, command empty, oncommand set)
hotkeys("hot_bookmtb", "", "B", "", "BookmarkingUI.toggleBookmarksToolbar('shortcut');");
// Example 3: Ctrl Alt Q instead of Ctrl Shift Q to prevent accidental quit
let key_quit = document.getElementById("key_quitApplication"); if (key_quit) key_quit.setAttribute("modifiers", "accel,alt");
// Example 4: remove quit application built-in shortcut
let key_quit_rem = document.getElementById("key_quitApplication"); if (key_quit_rem) key_quit.remove();
console.info('\u2713 SimpleHotkeysOverride');
}
};
//UC.SimpleHotkeysOverride.init();
/*********************************************** PLACE JS SNIPPETS ABOVE THIS LINE! ***********************************************/
} }; if (!Services.appinfo.inSafeMode) new UserChromeJS(); } catch(fox) {};
/// ^,^