Skip to content

Instantly share code, notes, and snippets.

View ZER0's full-sized avatar

Matteo Ferretti ZER0

  • Amsterdam, Netherlands
View GitHub Profile
@ZER0
ZER0 / gist:5267608
Last active April 26, 2023 17:26
Find all the CSS rules applied to a specific element; and check if a CSS property for a specific element is defined in the stylesheet – not inline style. Notice that is not like `getComputedStyle`, that returns the calculated properties for a specific element.
var proto = Element.prototype;
var slice = Function.call.bind(Array.prototype.slice);
var matches = Function.call.bind(proto.matchesSelector ||
proto.mozMatchesSelector || proto.webkitMatchesSelector ||
proto.msMatchesSelector || proto.oMatchesSelector);
// Returns true if a DOM Element matches a cssRule
var elementMatchCSSRule = function(element, cssRule) {
return matches(element, cssRule.selectorText);
};
@ZER0
ZER0 / latex.md
Created August 1, 2022 18:09
LaTex

$$\mathrm{e} = \sum_{n=0}^{\infty} \dfrac{1}{n!}$$

@ZER0
ZER0 / gist:10024431
Created April 7, 2014 17:19
Add-on SDK: to Certificate Viewer window
let { events: windowEvents } = require('sdk/window/events');
let { on } = require('sdk/event/core');
let { filter } = require('sdk/event/utils');
let ready = filter(windowEvents, ({type}) => type === 'DOMContentLoaded');
let certificateWindows = filter(ready, ({target}) =>
target.document.documentElement.mozMatchesSelector('dialog#certDetails'));
on(certificateWindows, 'data', ({target: window}) => {
<!doctype html>
<html>
<div>
<button>click A</button>
<button>click B</button>
</div>
<output></output>
<script>
let buttons = document.querySelector("div");
let output = document.querySelector("output");
diff --git a/lib/sdk/deprecated/unit-test-finder.js b/lib/sdk/deprecated/unit-test-finder.js
index 0d13265..c2268d5 100644
--- a/lib/sdk/deprecated/unit-test-finder.js
+++ b/lib/sdk/deprecated/unit-test-finder.js
@@ -55,8 +55,20 @@ TestFinder.prototype = {
function(suite) {
// Load each test file as a main module in its own loader instance
// `suite` is defined by cuddlefish/manifest.py:ManifestBuilder.build
- var loader = Loader(module);
- var module = cuddlefish.main(loader, suite);
@ZER0
ZER0 / gist:5548355
Last active December 17, 2015 04:09
let { Button } = require("sdk/ui");
let button = Button({
id: "my-button",
// assuming automatically `data` folder for "./"
image: "./beer.png",
// required as tooltip and overflow
label: "My Button",
type: "checked"
});
@ZER0
ZER0 / gist:5255953
Created March 27, 2013 16:52
Change a label of a context-menu item based on selection
let cm = require("sdk/context-menu");
let item = cm.Item({
label: "My Menu Item",
context: cm.SelectionContext()
});
require("sdk/selection").on("select", function(){
item.label = this.text
})
@ZER0
ZER0 / gist:5209412
Last active December 15, 2015 05:29
JEP window.postMessage for Add-ons
// main.js
PageMod({
onAttach: function(worker) {
worker.addEventListener("message", function(event){
if (event.origin === "good.com") // page script
event.source.postMessage(event.data + " addon!", "good.com");
else if(event.origin === worker.origin) // content script
event.source.postMessage("content script, hello!", worker.origin);
});
@ZER0
ZER0 / rulers.js
Created October 6, 2015 16:10
Example of highligther based on CanvasHighlighter
function RulersHighlighter2(highlighterEnv) {
CanvasHighlighter.call(this, highlighterEnv);
}
RulersHighlighter2.prototype = extend(CanvasHighlighter.prototype, {
typeName: "RulersHighlighter",
textStep: 100,
graduationStep: 5,
stepScale: 1,
JPM [info] Starting jpm test on addon-sdk
Creating XPI
JPM [info] XPI created at /var/folders/tx/91xwh51562l5_4xcqjst9bvw0000gn/T/@addon-sdk-0.1.18.xpi (1173ms)
Created XPI at /var/folders/tx/91xwh51562l5_4xcqjst9bvw0000gn/T/@addon-sdk-0.1.18.xpi
JPM [info] Creating a new profile
Shumway is registered
Running tests on Firefox 42.0a1/Gecko 42.0a1 (Build 20150805030208) ({ec8030f7-c20a-464f-9b0e-13a3a9e97384}) under darwin/x86_64.
console.error: addon-sdk:
JPM [error] Message: TypeError: FakeCu is not a constructor
Stack: