Skip to content

Instantly share code, notes, and snippets.

@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 = {
@Noitidart
Noitidart / _example-TwitterRequestToken-PLAINTEXT.js
Created February 20, 2014 12:08
_example-TwitterRequestToken-PLAINTEXT
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 = {
@Noitidart
Noitidart / _ff-addon-snippet-XulPanelAnimShowAnimHide.js
Last active August 29, 2015 13:56
_ff-addon-snippet-XulPanelAnimShowAnimHide - Copy paste script for Firefox Scratchpad with Environment set to Browser. It adds a panel as type arrow. All type arrow panels are animated on show but not on out, this snippet makes it animate on hide as well. Option to remove panel on end of animation or just hide it (see comments one Line 18 and 19…
var win = Services.wm.getMostRecentWindow('navigator:browser');
var panel = win.document.createElement('panel');
var props = {
type: 'arrow',
style: 'width:300px;height:100px;'
}
for (var p in props) {
panel.setAttribute(p, props[p]);
}
@Noitidart
Noitidart / _template-BootstrapSQLite.js
Created February 26, 2014 08:11
_template-BootstrapSQLite - Bare bones of bootstrapped SQLite addon
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
const self = {
id: 'Floppers',
suffix: '@jetpack',
path: 'chrome://floppers/content/',
aData: 0,
};
const myServices = {};
Cu.import('resource://gre/modules/Services.jsm');
@Noitidart
Noitidart / _template_construction-RoarPanelMessages.htm
Last active August 29, 2015 13:56
_template_construction-RoarPanelMessages - HTML panels with style for message displaying. Forked from builder.addons.mozilla.org.
<div style="left: 10px; top: 10px;" class="roar-body">
<div id="shipyard-hrtypyw7" style="opacity: 1;" class="roar error"><div style="" class="roar-bg"></div><div class="roar-icon"></div><h3>Install Add-on Builder Helper</h3><p>To test this add-on, please install the <a id="install_addon_helper" href="https://addons.mozilla.org/firefox/downloads/latest/182410?src=external-builder">Add-on Builder Helper add-on</a></p></div>
<div id="shipyard-hrtypyw7" style="opacity: 1;" class="roar warning"><div style="" class="roar-bg"></div><div class="roar-icon"></div><h3>Install Add-on Builder Helper</h3><p>To test this add-on, please install the <a id="install_addon_helper" href="https://addons.mozilla.org/firefox/downloads/latest/182410?src=external-builder">Add-on Builder Helper add-on</a></p></div>
<div id="shipyard-hrtypyw7" style="opacity: 1;" class="roar message"><div style="" class="roar-bg"></div><div class="roar-icon"></div><h3>Install Add-on Builder Helper</h3><p>To test this add-on, please install the <a id
@Noitidart
Noitidart / _snippet-ff-addon-AppendFlag.js
Created February 27, 2014 07:16
_snippet-ff-addon-AppendFlag - This is a snippet to show you how to append a flag to existing flags. Plan to figure out how to remove a flag from existing flags.
var loadFlags = chan.loadFlags;
if (chan.URI.schemeIs("https"))
loadFlags &= ~chan.INHIBIT_PERSISTENT_CACHING; //the &= ~ will add it