google-code-rawfile

get google code revision rawfile-link

  1. // ==UserScript==
  2. // @name google-code-rawfile
  3. // @namespace http://userscripts.org/scripts/show/98112
  4. // @description get google code revision rawfile-link
  5. // @author idx (http://userscripts.org/users/idx)
  6. // @include http://code.google.com/p/*
  7. // @version 0.1
  8. // @timestamp 1298980778837
  9. // ==/UserScript==
  10.  
  11. (function(){
  12.  
  13. /*
  14. javascript:window.alert(new Date().getTime());
  15. */
  16. function init(){
  17.  
  18. var tr = $D('.af');
  19. var td,par,cucok,el,lnk,chref='';
  20. if(tr){
  21. for(var i=0; i<tr.length; i++){
  22. var td=getTag('td', tr[i]);
  23. if(td) {
  24. el=$D(".//a[contains(@href, 'diff?')]",tr[i],true);
  25. if(el) chref = el.href;
  26. par=td[td.length-1];
  27. if( cucok=chref.match(/google\.com\/p\/([^\/]+)[^\?]+.spec=svn([^&]+)[^\/]+(\/.+)/i) ){
  28. lnk='http://'+cucok[1]+'.googlecode.com/svn-history/r'+cucok[2]+cucok[3];
  29. el=createEl('a',{href:lnk,style:'margin-left:25px'},'raw ('+cucok[2]+')');
  30. Dom.add(el,par);
  31. }
  32. }
  33. }
  34. }
  35. }
  36.  
  37. //=====
  38. // static routine
  39. function isDefined(x) { return !(x == null && x !== null); }
  40. function isUndefined(x) { return x == null && x !== null; }
  41. function isString(x) { return (typeof(x)!='object' && typeof(x)!='function'); }
  42. function createEl(type, attrArray, html){
  43. var node = document.createElement(type);
  44. for (var attr in attrArray)
  45. if (attrArray.hasOwnProperty(attr))
  46. node.setAttribute(attr, attrArray[attr]);
  47. if(html) node.innerHTML = html;
  48. return node;
  49. }
  50. function getTag(name, parent){
  51. var ret = (typeof(parent)!='object' ? document.getElementsByTagName(name) : parent.getElementsByTagName(name) );
  52. return (isDefined(ret[0]) ? ret : false);
  53. }
  54.  
  55. // Get Elements
  56. var $D=function (q, root, single) {
  57. if (root && typeof root == 'string') {
  58. root = $D(root, null, true);
  59. if (!root) { return null; }
  60. }
  61. if( !q ) return false;
  62. if ( typeof q == 'object') return q;
  63. root = root || document;
  64. if (q[0]=='/' || (q[0]=='.' && q[1]=='/')) {
  65. if (single) { return document.evaluate(q, root, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; }
  66. return document.evaluate(q, root, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  67. }
  68. else if (q[0]=='.') { return root.getElementsByClassName(q.substr(1)); }
  69. else { return root.getElementById( (q[0]=='#' ? q.substr(1):q.substr(0)) ); }
  70. return root.getElementsByTagName(q);
  71. };
  72. var Dom = {
  73. g: function(el) {
  74. if(!el) return false;
  75. return ( isString(el) ? document.getElementById(el) : el );
  76. },
  77. add: function(el, dest) {
  78. var el = this.g(el);
  79. var dest = this.g(dest);
  80. if(el && dest) dest.appendChild(el);
  81. }
  82. };
  83.  
  84.  
  85. // -----------
  86. init();
  87. // -----------
  88.  
  89.  
  90. })()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址