Add Firefox XPI

This commit is contained in:
Kabir Sala 2014-02-15 22:46:50 +01:00
parent 017502e0dd
commit 471cf4f2f7
9 changed files with 13003 additions and 0 deletions

BIN
builds/xpi/4chanx.xpi Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,62 @@
function GM_openInTab(_url) {
self.port.emit("GM_openInTab", _url);
return; // Should return the Window object
};
function GM_setValue(_name, _value) {
localStorage[_name] = _value;
return;
};
function GM_getValue(_name, _default) {
if (localStorage[_name] === null && _default === null) return null;
return (localStorage[_name] || _default);
};
function GM_deleteValue(_name) {
localStorage.removeItem(_name);
return;
};
function GM_listValues() {
return Object.keys(localStorage);
};
function GM_setClipboard(_text) {
self.port.emit("GM_setClipboard", _text);
};
//Deprecated
function GM_log(_message) {
console.log(_message);
return;
};
function GM_xmlhttpRequest(_details) {
//Ugly hack? Race condition? Memory leak?
_onload = _details.onload;
_context = _details.context;
self.port.emit("GM_xmlhttpRequest", _details);
};
self.port.on("callback_GM_xmlhttpRequest", function(_response) {
_response.context = _context;
_onload(_response);
});
function GM_addStyle(_css) {
self.port.emit("GM_addStyle", _css);
}
var GM_info = new Object();
GM_info.version = '1.15';
GM_info.scriptWillUpdate = true;
//To do
function GM_registerMenuCommand(_caption, _commandFunc, _accessKey) {
return;
}
self.port.on("load-userscript", function(_script) {
eval(_script);
});

0
builds/xpi/doc/main.md Normal file
View File

BIN
builds/xpi/icon.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

BIN
builds/xpi/icon64.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

82
builds/xpi/lib/main.js Normal file
View File

@ -0,0 +1,82 @@
var data = require("sdk/self").data;
var Request = require("sdk/request").Request;
var tabs = require("sdk/tabs");
var system = require("sdk/system");
if (system.platform !== 'android') {
// Clipboard is not supported on Android
var clipboard = require("sdk/clipboard");
}
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: ["*.4chan.org", "*.4cdn.org"],
contentScriptFile: data.url("greaseshim.js"),
contentScriptWhen: "start",
onAttach: function(worker) {
worker.port.emit("load-userscript", data.load("4chan-X.user.js"));
//GM_openInTab
worker.port.on("GM_openInTab", function(url) {
tabs.open(url);
});
//GM_setClipboard
worker.port.on("GM_setClipboard", function(text) {
if (system.platform !== 'android') {
// Clipboard is not supported on Android
clipboard.set(text);
}
});
//GM_xmlhttpRequest
worker.port.on("GM_xmlhttpRequest", function(details) {
request = new Object();
request.url = details.url;
if (details.headers) {
request.headers = details.headers;
if (details.headers["Content-Type"]) {request.contentType = details.headers["Content-Type"]};
};
if (details.data) {request.content = encodeURIComponent(details.data)};
if (details.overrideMimeType) {request.overrideMimeType = details.overrideMimeType};
request.onComplete = function(response) {
response.finalUrl = details.url;
response.responseText = response.text;
for (var headerName in response.headers) {
_string = headerName + ": " + response.headers[headerName] + " \n";
response.responseHeaders += _string;
}
response.readyState = 4;
worker.port.emit("callback_GM_xmlhttpRequest", response);
}
xhr = Request(request);
switch(details.method){
case "GET":
xhr.get();
break;
case "POST":
xhr.post();
break;
case "HEAD":
xhr.head();
break;
case "PUT":
xhr.put();
break;
default: xhr.get();
}
});
//GM_addStyle
worker.port.on("GM_addStyle", function(css) {
tabs.activeTab.attach({
contentScript: "var style = document.createElement('style');" +
"style.type = 'text/css';" +
"style.innerHTML = '" + css + "';" +
"document.head.appendChild(style);"
});
});
}
});

9
builds/xpi/package.json Normal file
View File

@ -0,0 +1,9 @@
{
"name": "4chanx",
"title": "4chan X",
"id": "72DAF86E-9689-11E3-8BA3-F4B66188709B",
"description": "Adds various features to 4chan.",
"author": "Spittie",
"license": "MIT",
"version": "1.3.7"
}

View File

@ -0,0 +1,12 @@
var main = require("./main");
exports["test main"] = function(assert) {
assert.pass("Unit test running!");
};
exports["test main async"] = function(assert, done) {
assert.pass("async Unit test running!");
done();
};
require("sdk/test").run(exports);