Includes : XPath

xpath Function

Ezt a szkriptet nem ajánlott közvetlenül telepíteni. Ez egy könyvtár más szkriptek számára, amik tartalmazzák a // @require https://update.greatest.deepsurf.us/scripts/7145/29376/Includes%20%3A%20XPath.js hivatkozást.

  1. // ==UserScript==
  2. // @name Includes : XPath
  3. // @namespace http://gm.wesley.eti.br/includes
  4. // @description xpath Function
  5. // @author w35l3y
  6. // @email w35l3y@brasnet.org
  7. // @copyright 2009+, w35l3y (http://gm.wesley.eti.br)
  8. // @license GNU GPL
  9. // @homepage http://gm.wesley.eti.br
  10. // @version 1.0.0.5
  11. // @language en
  12. // @include nowhere
  13. // ==/UserScript==
  14.  
  15. /**************************************************************************
  16.  
  17. Author 's NOTE
  18.  
  19. Original http://lowreal.net/blog/2007/11/17/1
  20.  
  21. ***************************************************************************
  22.  
  23. This program is free software: you can redistribute it and/or modify
  24. it under the terms of the GNU General Public License as published by
  25. the Free Software Foundation, either version 3 of the License, or
  26. (at your option) any later version.
  27.  
  28. This program is distributed in the hope that it will be useful,
  29. but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. GNU General Public License for more details.
  32.  
  33. You should have received a copy of the GNU General Public License
  34. along with this program. If not, see <http://www.gnu.org/licenses/>.
  35.  
  36. **************************************************************************/
  37.  
  38. XPath = Xpath = xpath = function()
  39. {
  40. var a = Array.prototype.slice.call(arguments), // args
  41. e = a[0], // expression
  42. c = a[1], // context
  43. t = a[2]; // type
  44. if (typeof c == "function")
  45. {
  46. t = c;
  47. c = null;
  48. }
  49. if (!c)
  50. c = document.documentElement||document;
  51. var d = c.ownerDocument || c;
  52. e = d.createExpression(e, function(p)
  53. {
  54. var o = d.createNSResolver(c).lookupNamespaceURI(p);
  55.  
  56. if (o)
  57. return o;
  58. else switch (c.contentType)
  59. {
  60. case "text/xhtml":
  61. case "application/xhtml+xml":
  62. return "http://www.w3.org/1999/xhtml";
  63. default:
  64. return "";
  65. }
  66. });
  67.  
  68. switch (t)
  69. {
  70. case String:
  71. return e.evaluate(c, XPathResult.STRING_TYPE, null).stringValue;
  72. case Number:
  73. return e.evaluate(c, XPathResult.NUMBER_TYPE, null).numberValue;
  74. case Boolean:
  75. return e.evaluate(c, XPathResult.BOOLEAN_TYPE, null).booleanValue;
  76. case Array:
  77. var r = e.evaluate(c, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null),
  78. o = [];
  79.  
  80. for ( var ai = 0 , at = r.snapshotLength ; ai < at ; ++ai )
  81. o.push(r.snapshotItem(ai));
  82.  
  83. return o;
  84. case undefined:
  85. var r = e.evaluate(c, XPathResult.ANY_TYPE, null);
  86. switch (r.resultType)
  87. {
  88. case XPathResult.STRING_TYPE:
  89. return r.stringValue;
  90. case XPathResult.NUMBER_TYPE:
  91. return r.numberValue;
  92. case XPathResult.BOOLEAN_TYPE:
  93. return r.booleanValue;
  94. case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
  95. var o = [], i;
  96. while (i = r.iterateNext())
  97. o.push(i);
  98.  
  99. return o;
  100. }
  101. return null;
  102. default:
  103. throw(TypeError("xpath: specified type is not valid type."));
  104. }
  105. };