Skip to content

Instantly share code, notes, and snippets.

@Infocatcher
Infocatcher / request.js
Last active December 15, 2015 21:39
Получение свойств файла по ссылке, пример для статьи на habrahabr.ru Getting file's properties by it's URL, example for article on habrahabr.ru http://habrahabr.ru/post/175745/
var uriString = "https://addons.mozilla.org/firefox/downloads/latest/413716/addon-413716-latest.xpi";
var referer = "https://addons.mozilla.org/";
var private = false; // Отсылать запрос в приватном режиме
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ios.newURI(uriString, null, null);
var scheme = uri.scheme && uri.scheme.toLowerCase();
var channel = scheme == "about" && "nsIAboutModule" in Components.interfaces
@Infocatcher
Infocatcher / newTabButtonRightClick.js
Last active December 16, 2015 05:09
Right-click on New Tab button to open URI from clipboard in new tab. You can use Custom Buttons extension (paste code into "initialization" section) or something like http://userchromejs.mozdev.org/ or https://addons.mozilla.org/addon/uc/ to run this code
addEventListener("contextmenu", handleClick, true);
addEventListener("click", handleClick, true);
addEventListener("unload", function destroy(e) {
removeEventListener(e.type, destroy, false);
removeEventListener("contextmenu", handleClick, true);
removeEventListener("click", handleClick, true);
}, false);
function isNewTabButton(e) {
var trg = e.originalTarget || e.target;
var cl = trg.classList;
@Infocatcher
Infocatcher / increaseDownloadCount.js
Last active December 16, 2015 05:49
Firefox: increase item count in built-in download panel(browser.download.useToolkitUI = false)
// https://gist.github.com/Infocatcher/5387328
// More: https://github.com/Infocatcher/Download_Panel_Tweaker
// (c) Infocatcher 2013, 2015
var itemCountLimit = 5;
// resource://app/modules/DownloadsCommon.jsm, see getSummary() function
if(DownloadsCommon._privateSummary)
DownloadsCommon._privateSummary._numToExclude = itemCountLimit;
if(DownloadsCommon._summary)
DownloadsCommon._summary._numToExclude = itemCountLimit;
@Infocatcher
Infocatcher / string_indexOf_test.js
Last active December 16, 2015 05:49
Test: String.indexOf() vs other methods
var stack = 'before@resource://gre/modules/XPIProvider.jsm -> jar:file:///Z:/FirefoxPortable/Data/profile/extensions/[email protected]!/bootstrap.js:1899\n\
wrapper@resource://gre/modules/XPIProvider.jsm -> jar:file:///Z:/FirefoxPortable/Data/profile/extensions/[email protected]!/bootstrap.js:2211\n\
SocialUI.enabled@chrome://browser/content/browser.js:4292\n\
SSB_updateShareState@chrome://browser/content/browser.js:4644\n\
XULBrowserWindow.onLocationChange@chrome://browser/content/browser.js:11409\n\
@chrome://browser/content/tabbrowser.xml:384\n\
_callProgressListeners@chrome://browser/content/tabbrowser.xml:381\n\
updateCurrentBrowser@chrome://browser/content/tabbrowser.xml:896\n\
onselect@chrome://browser/content/browser.xul:1\n\
set_selectedIndex@chrome://global/content/bindings/tabbox.xml:661\n\
@Infocatcher
Infocatcher / importTest.js
Created May 9, 2013 14:35
Speed test: Components.utils.import() vs check + Components.utils.import()
var c = 30e3;
var tmr = "performance" in window && "now" in performance
? performance
: Date;
var Cu = Components.utils;
var i = c + 1, t = tmr.now();
while(--i)
Cu.import("resource://gre/modules/Services.jsm");
@Infocatcher
Infocatcher / showDownloadRate.js
Last active December 18, 2015 13:09
Firefox: show download rate in built-in download panel, code for Custom Buttons extension https://addons.mozilla.org/addon/custom-buttons/ ("initialization" section) http://custombuttons.sf.net/forum/viewtopic.php?t=1006
// https://gist.github.com/Infocatcher/5787749
// More: https://github.com/Infocatcher/Download_Panel_Tweaker
// (c) Infocatcher 2013
function showDownloadRate(patch) {
//var {DownloadUtils} = Components.utils.import("resource://gre/modules/DownloadUtils.jsm", {});
const bakKey = "_customButtons_getDownloadStatusNoRate";
if(!patch ^ bakKey in DownloadUtils)
return;
if(patch) {
// https://gist.github.com/Infocatcher/5891622
var menu = [
{ label: "Alert!", cb_id: "alert" },
{ label: "Google", cb_id: "google", image: "https://www.google.com/favicon.ico" },
"menuseparator",
[
"Menu label",
{ label: "Sub item 1", cb_id: "sub" },
{ label: "Sub item 2", cb_id: "sub2" }
],
@Infocatcher
Infocatcher / ClickToPlay_per-element.js
Created July 30, 2013 22:33
Click to Play per-element demo for Scratchpad (devtools.chrome.enabled = true, Environment – Browser) or something similar. Based on code from https://addons.mozilla.org/firefox/addon/click-to-play-per-element/
let WindowListener = {
handleEvent: function(aEvent) {
var trg = aEvent.originalTarget;
if( // I don't know, how do better checks here :(
trg.className != "hoverBox"
|| String.toLowerCase(trg.localName) != "div"
|| !trg.parentNode
|| trg.parentNode.className != "mainBox"
//|| String.toLowerCase(aEvent.target.localName) != "embed"
|| !(aEvent.target instanceof Ci.nsIObjectLoadingContent)
@Infocatcher
Infocatcher / detectPressedKeys.js
Created August 6, 2013 06:47
Detect pressed keys (Ctrl, Alt, Shift or Meta), code for https://addons.mozilla.org/addon/custom-buttons/ or something like http://userchromejs.mozdev.org/
// Allow styles like
// :root[cb_pressed] { /* Pressed any modifier */ }
// :root[cb_pressed~="shift"] { /* Pressed Shift */ }
var pressed = {
ctrl: false,
alt: false,
shift: false,
meta: false,
__proto__: null
};
@Infocatcher
Infocatcher / deleteCurrentFile.js
Last active December 20, 2015 21:49
AkelPad: delete current file, for Scripts plugin
// https://gist.github.com/Infocatcher/6200149
// Version: 0.1.2 - 2014-07-17
// Author: Infocatcher
//// Delete current file
// Usage:
// Call("Scripts::Main", 1, "deleteCurrentFile.js")
var confirm = AkelPad.GetArgValue("confirm", true);