Skip to content

Instantly share code, notes, and snippets.

View Noitidart's full-sized avatar

Noitidart Noitidart

View GitHub Profile
@Noitidart
Noitidart / _ff-addon-snippet-MasterPasswordPrompt.js
Last active August 29, 2015 13:56
_ff-addon-snippet-MasterPasswordPrompt - This snippet checks to see if master password exists. If it does it prompts user to enter it and if they get it right returns true else fail. If no master password exists then returns true.
var me = Services.wm.getMostRecentWindow(null);
var tokenDB = Cc['@mozilla.org/security/pk11tokendb;1'].getService(Ci.nsIPK11TokenDB);
var master_password = tokenDB.getInternalKeyToken();
var master_password_authenticated;
try {
master_password_authenticated = Components.isSuccessCode(token.login(false)); //login argument is false meaning that if the user had previously entered their master password it will not prompt them now AND if they had not entered it before and it is still valid for the session it will NOT prompt. IF you set it to true then regardless if the user entered it in before or not it will force them to enter it again
} catch (ex) {
master_password_authenticated = false;
}
@Noitidart
Noitidart / _ff-addon-snippet-HighlightTextInDocument.js
Last active August 29, 2015 13:57
_ff-addon-snippet-HighlightTextInDocument - This takes from http://mxr.mozilla.org/mozilla-release/source/toolkit/modules/Finder.jsm#225 to try to highlight text in document.
function _getEditableNode(aNode) {
while (aNode) {
if (aNode instanceof Ci.nsIDOMNSEditableElement)
return aNode.editor ? aNode : null;
aNode = aNode.parentNode;
}
return null;
}
@Noitidart
Noitidart / _ff-addon-snippet-contentWindowQIToDOMWin.js
Last active August 29, 2015 13:57
_ff-addon-snippet-contentWindowQIToDOMWin: How to get nsIDOMWindow from contentWindow
var DOMWin = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
@Noitidart
Noitidart / _ff-addon-template-BootstrapWatchHostEventListenerInjectFiles.xpi
Last active August 29, 2015 13:57 — forked from Noitidart/_ff-addon-template-BootstrapWatchHostEventListener.xpi
_ff-addon-template-BootstrapWatchHostEventListenerInjectFiles - Uses event listener (DOMContentLoaded) to watch page loads in all tabs and windows with gBrowser once it finds matching host it will inject files that are packaged with the addon.
@Noitidart
Noitidart / regex_patt_release.md
Last active November 14, 2017 23:49
regex pattern for release

Find: ^.*?console\.(warn|info|log|error|exception).*?$ Replace with: ``

@Noitidart
Noitidart / InsertXULPanel.js
Created March 9, 2014 10:51
_ff-addon-snippet-InsertXULPanel - How to create and insert a panel that fills the whole screen.
/*run this first*/
var win = Services.wm.getMostRecentWindow('navigator:browser');
var panel = win.document.createElement('panel');
var screen = Services.appShell.hiddenDOMWindow.screen;
var props = {
noautohide: true,
noautofocus: false,
level: 'top',
style: 'padding:15px; margin:0; width:' + screen.width + 'px; height:' + screen.height + 'px; background-color:steelblue;'
}
@Noitidart
Noitidart / _ff-addon-snippet-AddToolbarButtonToPalette.js
Last active December 25, 2019 03:04
_ff-addon-snippet-AddToolbarButtonToPalette - This shows how to add button to the toolbar palette and on customize it shows how to store the position/order of the icon. Reason to add to palette instead of adding directly to addonbar or navbar is so that user can customize. It is the XUL Overlay equivalent of adding `toolbarbutton` to `<toolbarpa…
var doc = document;
var win = doc.defaultView;
var toolbox = doc.querySelector('#navigator-toolbox');
var buttonId = 'bpMyBtn';
var button = doc.getElementById(buttonId);
if (!button) {
button = doc.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'toolbarbutton');
button.setAttribute('id', buttonId);
@Noitidart
Noitidart / _js-snippet-MDNBuildingDomTrees.js
Last active March 27, 2017 07:00
_js-snippet-MDNBuildingDomTrees - how to use the jsonToDom function the way I like. This code is a JavaScript snippet but compatabile with privelaged Firefox addon scope. Is not compataible with Google Chrome, I haven't tested other browsers. I do need to work on making it compatabile with other browsers.
function example() {
var hotkeyLabelJson =
['ul', {class: 'apple cf',id:'apple-qwerty'},
['li', {class:'apple'},
['a',{class:'nthotkey-apple-key apple-key'},
[span, {},
1
]
]
],
@Noitidart
Noitidart / _ff-addon-snippet-FindAddonMgr.js
Created March 13, 2014 04:03
_ff-addon-snippet-FindAddonMgr - Finds the addon manager and returns an object holding its windows.
function findAddonMgr() {
//future: i plan to allow argument to this function so it searches just the CURRENT firefox window for addon manager, but for right now its global
//searches for addon manager tab in ALL FIREFOX WINDOWS and when found it returns the an object holding browser window (domWindow) and contentWindow (the window is the equivlent of gBrowser.contentWindow from scratchpad)
var windows = wm.getEnumerator('navigator:browser'); //gets all windows with gBrowser
while (windows.hasMoreElements()) {
var domWindow = windows.getNext();
if (domWindow.gBrowser) {
if (domWindow.gBrowser.tabContainer) {
var browsers = domWindow.gBrowser.tabContainer.tabbrowser.browsers; //each tab is a browser
for (var i=0; i<browsers.length; i++) {
@Noitidart
Noitidart / _ff-addon-snippet-StandardChromeImport.js
Created March 13, 2014 06:12
_ff-addon-snippet-StandardChromeImport - Chrome import that is usually the first line of every addon.
const {classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu, results: Cr, manager: Cm} = Components;