Skip to content

Instantly share code, notes, and snippets.

@urig
Last active November 20, 2015 22:06
Show Gist options
  • Save urig/828ddc85e3fd0b79327e to your computer and use it in GitHub Desktop.
Save urig/828ddc85e3fd0b79327e to your computer and use it in GitHub Desktop.
Firefox add-on index.js with nasty hack to load a page-mod script from the add-on's root folder rather than from under its /data folder (for http://stackoverflow.com/questions/22656494/contentscriptfile-dont-work-in-pagemod)
var self = require('sdk/self');
var pageMod = require("sdk/page-mod");
// Nasty hack based on source code from sdk/self.js
const options = require('@loader/options');
const { get } = require("sdk/preferences/service");
const { readURISync } = require('sdk/net/url');
const id = options.id;
const readPref = key => get("extensions." + id + ".sdk." + key);
const name = readPref("name") || options.name;
const baseURI = readPref("baseURI") || options.prefixURI + name + "/"
const uri = (path="") =>
path.includes(":") ? path : baseURI + path.replace(/^\.\//, "");
var hack = Object.freeze({
url: uri,
load: function read(path) {
return readURISync(uri(path));
}
});
// End of nasty hack
pageMod.PageMod({
include: "*.org",
// instead of self.data() we use hack()
contentScriptFile: myData.url("myFile.html")
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment