Skip to content

Instantly share code, notes, and snippets.

@mdsy
mdsy / execOnNodes.js
Created March 3, 2013 14:20
Execute function against matched nodes (a la forEach)
//Doing something for every instance of a specific HTML element
//demo call: execOnTags("a",function(a){a.href=a.href.replace("http://","ftp://")});
function xpathOnTags(tag, func, doc){
var i, allNodes=[], thisNode;
doc = doc || content.document;
allNodes = doc.getElementsByTagName(tag);
for (i = 0; i < allNodes.length; i++){
thisNode = allNodes[i];
func(thisNode);
@mdsy
mdsy / DocLogic.js
Created March 3, 2013 14:12
Text Editor file handling (open, save, new,...) for Firefox Extensions
const DocLogic = function(configObject){
const KEY_PERSIST = configObject.KEY_PERSIST; //not used currently
const KEY_CSS = configObject.KEY_CSS; //about:config user pref, a string holding textbox style
const KEY_NOSAVE = configObject.KEY_NOSAVE; //about:config user pref, a boolean holding save prompt state
const ID_TEXTBOX = configObject.ID_TEXTBOX; //ID of the editor textbox
const ID_FNLABEL = configObject.ID_FNLABEL; //ID of the filname label
const XUL_OPTIONS = configObject.XUL_OPTIONS; //chrom URI of options window
const AUTOSAVE_FILE = configObject.AUTOSAVE_FILE; //path to file used for persistance of text
@mdsy
mdsy / StrList.js
Created March 3, 2013 14:10
Simple String List
function makeStrList(seed){
/* private variables */
var sliceFn = Array.prototype.slice;
var seed = seed || '';
/* prototype */
//if(typeof String.prototype.trim==='undefined')
//if(! 'trim' in String.prototype.trim)
@mdsy
mdsy / gist:5076247
Created March 3, 2013 14:09
Simple Javascript Set
//2013-02-26 05:02 am
//constructor
function Set(){
var values = [].slice.call(arguments);
this.set = {};
if(values.length>0){
Set.prototype.add.apply(this, values);
}
}
@mdsy
mdsy / gist:5076236
Created March 3, 2013 14:06
File IO library for Firefox Extension Development
//2013-01-03 06:28 am
'-use strict';
let FileIO = new function(){
/******************** Private ********************/
let Cc=Components.classes;
let Ci=Components.interfaces;
let prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
// Flags passed when opening a file
@mdsy
mdsy / gist:5076221
Created March 3, 2013 14:03
DOM Library for GreaseMonkey (tested only with Firefox) for educational purposes only!
/* 2013-03-03 03:41 am
GreaseMonkey:
in about:config set greasemonkey.fileIsGreaseable = true
// @require file:///D:/_VB%20Progs/_JavaScript/DOM%20Chained%20Mini%20Library/domch.js
var $ = make$(document);
Chrome Scope:
var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
loader.loadSubScript("file:///D:/_VB%20Progs/_JavaScript/DOM%20Chained%20Mini%20Library/domch.js");
@mdsy
mdsy / gist:5076199
Created March 3, 2013 13:57
Very simple iterator
var iterator = {
array : [],
position: 0,
hasNext: function() {
return this.position < this.array.length;
},
next: function() {
return this.array[this.position++];
},