Skip to content

Instantly share code, notes, and snippets.

var uris = {
"http://example.com/": true,
"https://example.com/": true,
"https://example.com/foo/bar.php?key=val&key2=val2#hash": true,
"file:///": true,
"ftp://example.com": true,
//"about:": true, // Removed in new versions
"about:newtab": true,
"about:config": true,
"about:cache?device=memory": true,
@Infocatcher
Infocatcher / turn-off-signatures.js
Created January 20, 2017 20:39
Turn off extensions signatures in Firefox (see comments in the code)
// Turn off extensions signatures in Firefox
// Use at your own risk!
// Usage:
// Start browser with rights to write into his install directory (run as administrator)
// devtools.chrome.enabled = true (in about:config)
// Open Scratchpad: Shift+F4 (Tools - Web-Developer - Scratchpad)
// Set: Environment - Browser
// Then paste following code and press Run, browser will be restarted, than enjoy
@Infocatcher
Infocatcher / getDownloadHistory.js
Last active October 25, 2016 17:10
Tricky way to detect if there something to remove using nsIDownloadHistory.removeAllDownloads()
function getDownloadHistory() {
var query = PlacesUtils.history.getNewQuery();
query.setTransitions([Components.interfaces.nsINavHistoryService.TRANSITION_DOWNLOAD], 1);
var options = PlacesUtils.history.getNewQueryOptions();
options.resultType = options.RESULTS_AS_URI;
options.queryType = Components.interfaces.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY;
options.includeHidden = true;
var result = PlacesUtils.history.executeQuery(query, options);
var contents = result.root;
function getVKChar(vk) {
// Firefox doesn't have string representation for some codes...
// https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent#Virtual_key_codes
if(/^VK_(?:NUMPAD)?([\d+A-Z])$/.test(vk))
return RegExp.$1;
switch(vk) {
case "VK_SPACE": return " "; //32
case "VK_COLON": return ":"; //58
case "VK_SEMICOLON": return ";"; //59
case "VK_LESS_THAN": return "<"; //60
@Infocatcher
Infocatcher / document-start.user.js
Last active March 5, 2016 19:48
Testcase for Greasemonkey: will be executed twice in Greasemonkey 3.7 (https://github.com/greasemonkey/greasemonkey/issues/2371)
// ==UserScript==
// @name about:blank?UserScripts/test
// @namespace dev/null
// @include about:blank?UserScripts/test
// @run-at document-start
// @version 1
// @grant none
// ==/UserScript==
console.log("test: " + document.readyState);
@Infocatcher
Infocatcher / base64.js
Last active August 29, 2015 14:28
Base64 converter for Gecko-based browsers, accepts any valid URL string
// https://gist.github.com/Infocatcher/2d001a8c72eb278c3686
// Based on code from Custom Buttons extension
// https://addons.mozilla.org/files/browse/261190/file/components/CustomButtonsService.js#L210
function ImageConverter(imageURL, feedback) {
this.imageURL = imageURL;
this.feedback = feedback;
this.bytes = [];
this.channel = Services.io.newChannel(imageURL, null, null);
this.channel.notificationCallbacks = this;
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:xbl="http://www.mozilla.org/xbl">
<binding id="urlbar" extends="chrome://browser/content/urlbarBindings.xml#urlbar">
<content sizetopopup="pref">
<xul:hbox class="autocomplete-textbox-container urlbar-textbox-container" flex="1">
@Infocatcher
Infocatcher / windowsWatcher.js
Created January 29, 2015 18:08
Windows watcher example for Custom Buttons (just a simplified demo)
// Windows watcher, based on code from
// https://github.com/Infocatcher/Custom_Buttons/tree/master/CB_Editor_Toggle_on_Top
const watcherId = "customButtonsWindowsWatcher_" + this.id;
var {Application, Components} = window; // Prevent garbage collection in Firefox 3.6 and older
var watcher = Application.storage.get(watcherId, null);
if(!watcher) {
watcher = {
REASON_STARTUP: 1,
REASON_SHUTDOWN: 2,
@Infocatcher
Infocatcher / getKeyboardLayout.js
Last active August 29, 2015 14:14
Get keyboard layout on Gecko-based browsers, Windows-only
// Based on code from TabLang extension: https://addons.mozilla.org/addon/tablang/
// and Master Password+ extension https://addons.mozilla.org/addon/master-password/
var kb = {
GetKeyboardLayout: null,
GetLocaleInfoW: null,
init: function()
{
this.init = function() {};
Components.utils.import("resource://gre/modules/ctypes.jsm", this);
@Infocatcher
Infocatcher / openTabWithScrollAndZoom.js
Created November 12, 2014 07:38
Open tab in Firefox with scroll and zoom (but zoom works strange with browser.zoom.siteSpecific = true)
var textZoom = 1.5;
var fullZoom = 1;
var scrollX = 0;
var scrollY = 200;
var tab = gBrowser.addTab("https://addons.mozilla.org/");
var browser = tab.linkedBrowser;
if(scrollX || scrollY) {
var scrollTimer = setInterval(function() {