Skip to content

Instantly share code, notes, and snippets.

@Ventero
Ventero / userval.user.js
Created January 21, 2014 17:29
Greasemonkey user variable definition example
function makeUserModifiable(varName, defaultVal, parseFunc) {
if(typeof parseFunc !== "function")
parseFunc = function(a) { return a; };
var currentVal = GM_getValue(varName, defaultVal);
GM_registerMenuCommand("Set variable " + varName, function() {
var val = prompt("Value for " + varName, currentVal);
GM_setValue(varName, val);
// if you need live modification, uncomment this (requires varName to be a
// global variable)
// ==UserScript==
// @name GM_getResourceText ScriptChannel behavior
// @namespace test
// @version 1.0
// @include *
// @grant GM_getResourceText
// @grant GM_getResourceURL
// @resource script.user.js http://dump.ventero.de/greasemonkey/resource
// ==/UserScript==
<!DOCTYPE html>
<html>
<head><title>GM #1494 test</title></head>
<body>
<button onclick="sendEvent();">Click</button>
<script>
var div = document.createElement("div");
function sendEvent() {
div.click();
}
// ==UserScript==
// @name Icon Update Test
// @description Test the displayed icon in the addon manager when updating this script.
// @namespace ventero.de
// @include http*
// @icon http://iconpacks.mozdev.org/images/firefox-world32x32.png
// @downloadURL https://gist.github.com/Ventero/5897253/raw/d1558153f6977f84a8288c260a3560b59577a7fc/update.user.js
// @updateURL https://gist.github.com/Ventero/5897253/raw/3d9118b6beca694e265648c9c46b815ac42dd367/update.meta.js
// @version 0.5
// ==/UserScript==
@Ventero
Ventero / scriptresource.user.js
Last active October 9, 2015 23:38
GM crash test
// example script resource
console.log("resource");
@Ventero
Ventero / deadobject.user.js
Created August 5, 2012 20:28
GM_xhr dead object test
// ==UserScript==
// @name GM_xhr dead object test
// @namespace test
// @include *
// @version 1
// @grant GM_xmlhttpRequest
// ==/UserScript==
GM_xmlhttpRequest({
method: "GET",
@Ventero
Ventero / issue_1584_2.diff
Created July 16, 2012 21:31
GM issue 1584 diff #2
diff --git a/components/greasemonkey.js b/components/greasemonkey.js
index 4863722..559d178 100644
--- a/components/greasemonkey.js
+++ b/components/greasemonkey.js
@@ -322,6 +322,7 @@ function startup(aService) {
var observerService = Components.classes['@mozilla.org/observer-service;1']
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(aService, 'document-element-inserted', false);
+ observerService.addObserver(aService, 'content-document-global-created', false);
}
@Ventero
Ventero / location_replace_test.user.js
Created July 7, 2012 14:54
location.replace test for GM
// ==UserScript==
// @name location.replace test
// @namespace test
// @include *
// @version 1
// @grant GM_addStyle
// ==/UserScript==
if(window.location.href.indexOf("anchor") == -1) {
alert("Replacing location");
// ==UserScript==
// @name Break GMail Test
// @namespace test
// @include https://mail.google.com/*
// @include http://mail.google.com/*
// @version 1
// @grant none
// ==/UserScript==
j = 0;
@Ventero
Ventero / issue_1578.diff
Created July 3, 2012 18:55
Greasemonkey issue 1578
diff --git a/content/browser.js b/content/browser.js
index e6e9556..13d1c27 100644
--- a/content/browser.js
+++ b/content/browser.js
@@ -335,6 +335,16 @@ function GM_showPopup(aEvent) {
GM_MenuCommander.onPopupShowing(menuCommandPopup);
}
+/**
+ * Clean up the menu after it hides to prevent memory leaks