Skip to content

Instantly share code, notes, and snippets.

const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
const self = {
id: 'Bootstrap-Skeleton-Plus',
suffix: '@jetpack',
path: 'chrome://bootstrap-skeleton-plus/content/',
aData: 0,
};
const myServices = {};
Cu.import('resource://gre/modules/Services.jsm');
@Noitidart
Noitidart / _template-BootstrapJSM.xpi
Last active July 22, 2018 03:30
ff-addon-template: Template for how to create a JSM module.
@Noitidart
Noitidart / _scratchpad-AlertWithinScratchpad
Created February 17, 2014 11:34
In Firefox, when in scratchpad and working in Environment > Browser, if do alert, it alerts in the window behind it, to make the alert happen within the scratchpad window use this technique.
var spwin = Services.wm.getMostRecentWindow(null); //this gets the scratchpad window
var str = 'rawr';
var str = str[0].toUpperCase() + str.substr(1);
spwin.alert(str) // will upper case str this is just to demo the alert comes in the scratchpad window
@Noitidart
Noitidart / oauth_nonce_gen.js
Created February 19, 2014 08:13
OAuth nonce generator function from codebird, its bascially a random string generator.
//https://github.com/jublonet/codebird-js/blob/master/codebird.js#L745
function _nonce(length) {
if (typeof length === "undefined") {
length = 8;
}
if (length < 1) {
console.warn("Invalid nonce length.");
}
var nonce = "";
for (var i = 0; i < length; i++) {
@Noitidart
Noitidart / _ff-addon-snippet-HTTPWraper.js
Last active August 29, 2015 13:56
_firefox-addon-snippet-HTTPWrapper - Forked from an addon long ago and slightly tweaked here and there. Designed for use in privelaged scope, meaning it does not need access to nsIDOMWindow for any properies or functions.
var XMLHttpRequest = Cc['@mozilla.org/xmlextras/xmlhttprequest;1'];
var timeoutTimer;
/**
* The following keys can be sent:
* onSuccess (required) a function called when the response is 2xx
* onFailure a function called when the response is not 2xx (IF onFailure and onTimeout are defined, when times out then onTimeout is executed only and not onFailure. IF onFailure is defined and onTimeout is NOT defined then when times out it will execute onFailure) (not called if aborted)
* username The username for basic auth
* password The password for basic auth
* overrideMimeType The mime type to use for non-XML response mime types
* timeout A timeout value in milliseconds for the response
@Noitidart
Noitidart / bootstrap.js
Last active August 29, 2015 13:56 — forked from Noitidart/_template-bootstrapSkeleton.xpi
_demo-Bootstrap-nsITimer - Creates a timer that executes callback every 5s, waits for callback to finish, then starts again. Doing TYPE_REPEATING_SLACK with TYPE_ONE_SHOT. This is nice because if used TYPE_REPEATING_PRECISE will trigger this call back every myTimerInterval. TYPE_REPEATING_PRECISE_SKIP will trigger this call back every myTimerInt…
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
var myTimer = Cc['@mozilla.org/timer;1'].createInstance(Ci.nsITimer);
var myTimerCookie;
var myTimerInterval = 5000;
// we need an nsITimerCallback compatible interface for the callbacks.
var myTimerEvent = {
notify: function(timer) {
Cu.reportError('Timer Fired!');
//do stuff here, this stuff will finish and then timer will start countdown of myTimerInterval.
@Noitidart
Noitidart / _firefox-addon-snippet-HTTWPWrapperEXAMPLES.js
Last active August 29, 2015 13:56
_firefox-addon-snippet-HTTWPWrapperEXAMPLES - examples of usage of https://gist.github.com/Noitidart/9088113
var labelHTTP = 'loadPreLike - loadingPreLike of el0 in like arr';
HTTP('GET',referer,{
returnHeaders: true,
/*timeout: 30000,
onTimeout: function() {
Cu.reportError('TIMEOUT: ' + labelHTTP);
},*/
onSuccess: function(status, responseXML, responseText, headers, statusText) {
Cu.reportError('SUCCESS: ' + labelHTTP + '\n\nstatusText:' + statusText + '\nresponseText:' + responseText + '\nheaders:' + uneval(headers));
var respDataStr = [];respDataStr.push('status:"' + status + '"');respDataStr.push('statusText:"' + statusText + '"');respDataStr.push('responseText:"' + responseText + '"');respDataStr.push('headers:"' + uneval(headers) + '"');respDataStr = respDataStr.join('<br><br>');
@Noitidart
Noitidart / _twiitter-oauth\request_token-POST.js
Last active August 29, 2015 13:56
_twiitter-oauth\request_token-POST - example
//https://api.twitter.com/oauth/request_token
//requestURL: "https://api.twitter.com/oauth/request_token"
var param = {
oauth_callback: 'http://www.floppers.comyr',
oauth_signature_method: 'PLAINTEXT',
oauth_timestamp: '', ////running setTimestampNonceSignature() will update this
oauth_version: '1.0',
oauth_consumer_key: ' jrcJKxvJ92NeeV48RL1lotN9PigbxCCbqUkKj237yio', //api key u get from ur app page on twiitter
oauth_signature: '', //running setTimestampNonceSignature() will update this //to make the function i followed steps here to create my gen function: https://dev.twitter.com/docs/auth/creating-signature
oauth_nonce: '' //running setTimestampNonceSignature() will update this
@Noitidart
Noitidart / _example-TwitterRequestToken.js
Created February 20, 2014 11:57
_example-TwitterRequestToken
Cu.import('chrome://cdumpjsm/content/cDump.jsm');
initSHA1(this); //onload must run this once
var HTTPMethod = 'POST';
var requestURL = 'https://api.twitter.com/oauth/request_token';
var APIKey = 'AjONvgAdbD8YWCtRn5U9yA'; //also known as oauth_consumer_key //from your app page on twitter dev site
var ConsumerSecret = 'jrcJKxvJ92NeeV48RL1lotN9PigbxCCbqUkKj237yio'; //from your app page on twitter dev site
var OAuthTokenSecret = '';
var param = {