Talk:Code snippets

From GreaseSpot Wiki
Jump to navigationJump to search


This page is rather messy. Does anyone have ideas for how to better structure this information? --Henrik 05:48, 5 June 2007 (EDT)

It is getting a bit big, perhaps separating it out into different pages, each with a short explanation, the code and some examples. The main page would just have the links and a one line description. Also some more logical categories could help. --Alien scum 18:43, 6 June 2007 (EDT)

array.forEach in XPath example


Restored that example, it works fine (using Fx 2) without Prototype. See e.g.

Just try it:

 // ==UserScript==
 // @name          Example
 // @namespace     wiki
 // @include       *
 // ==/UserScript==
 function $x(p, context) {
   if (!context) context = document;
   var i, arr = [], xpr = document.evaluate(p, context, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
   for (i = 0; item = xpr.snapshotItem(i); i++) arr.push(item);
   return arr;
 var i, paragraphs = $x("//p");	 
 paragraphs.forEach(function(paragraph) { // Loop over every paragraph	 
 	paragraph.innerHTML = "Halloa!";	 

-- 18:18, 25 March 2007 (EDT)