|
1 | 1 | // ==UserScript== |
2 | | -// @name Translate Objective-C Docs to MacRuby |
| 2 | +// @name MacRuby Docs JS - Adds MacRuby/RubyMotion syntax to Apple's Objective-C/Cocoa docs. |
3 | 3 | // @namespace http://twitter.com/joakimk |
4 | | -// @description Inserts MacRuby / RubyMotion syntax below Obj-c declarations in Apple documentation. |
| 4 | +// @description Adds MacRuby/RubyMotion syntax to Apple's Objective-C/Cocoa docs. |
5 | 5 | // @include http://developer.apple.com/library/mac/* |
6 | 6 | // @include https://developer.apple.com/library/mac/* |
7 | 7 | // @version 1.0 |
|
18 | 18 | }; |
19 | 19 |
|
20 | 20 | var load_latest = function() { |
21 | | - //require("https://raw.github.com/joakimk/macruby-docs-js/master/dist/latest.js"); |
22 | | -//// |
23 | | -////////// |
24 | | - |
25 | | -function addJQuery(callback) { |
26 | | - var script = document.createElement("script"); |
27 | | - script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); |
28 | | - script.addEventListener('load', function() { |
29 | | - var script = document.createElement("script"); |
30 | | - script.textContent = "(" + callback.toString() + ")();"; |
31 | | - document.body.appendChild(script); |
32 | | - }, false); |
33 | | - document.body.appendChild(script); |
34 | | -} |
35 | | - |
36 | | -function main() { |
37 | | - $.noConflict() |
38 | | - //alert("There are " + $('a').length + " links on this page."); |
39 | | - |
40 | | - function check() |
41 | | - { |
42 | | -var Declaration; |
43 | | -Declaration = (function() { |
44 | | - function Declaration(declaration) { |
45 | | - this.declaration = declaration; |
46 | | - } |
47 | | - Declaration.prototype.returnType = function() { |
48 | | - var pattern; |
49 | | - pattern = /.\((.+?)\)/; |
50 | | - return this.declaration.match(pattern)[1]; |
51 | | - }; |
52 | | - Declaration.prototype.methodName = function() { |
53 | | - var pattern; |
54 | | - pattern = /.+?\)(.+?):/; |
55 | | - return this.declaration.match(pattern)[1]; |
56 | | - }; |
57 | | - Declaration.prototype.isInstanceMethod = function() { |
58 | | - var pattern; |
59 | | - pattern = /-.+/; |
60 | | - return !!this.declaration.match(pattern); |
61 | | - }; |
62 | | - Declaration.prototype.parameters = function() { |
63 | | - var parameter, parameters, pattern, _i, _len, _results; |
64 | | - pattern = /.+?:(.+)/; |
65 | | - parameters = this.declaration.match(pattern)[1].replace(new RegExp(" \\*", "g"), "#*").split(' '); |
66 | | - parameters = (function() { |
67 | | - var _i, _len, _results; |
68 | | - _results = []; |
69 | | - for (_i = 0, _len = parameters.length; _i < _len; _i++) { |
70 | | - parameter = parameters[_i]; |
71 | | - _results.push(parameter.replace('#*', ' *')); |
72 | | - } |
73 | | - return _results; |
74 | | - })(); |
75 | | - _results = []; |
76 | | - for (_i = 0, _len = parameters.length; _i < _len; _i++) { |
77 | | - parameter = parameters[_i]; |
78 | | - _results.push(this.mapParameter(parameter)); |
79 | | - } |
80 | | - return _results; |
81 | | - }; |
82 | | - Declaration.prototype.mapParameter = function(parameter) { |
83 | | - var arg, key, pattern, type, value, _ref, _ref2; |
84 | | - if (parameter[0] === "(") { |
85 | | - pattern = /\((.+?)\)(.+)/; |
86 | | - return parameter.match(pattern).slice(1, 3).reverse(); |
87 | | - } else { |
88 | | - pattern = /\((.+?)\)(.+)/; |
89 | | - _ref = parameter.split(':'), key = _ref[0], arg = _ref[1]; |
90 | | - _ref2 = arg.match(pattern).slice(1, 3).reverse(), value = _ref2[0], type = _ref2[1]; |
91 | | - return ["" + key + ": " + value, type]; |
92 | | - } |
93 | | - }; |
94 | | - return Declaration; |
95 | | -})(); |
96 | | - |
97 | | - try { |
98 | | - className = jQuery("#pageTitle", window.parent.frames[0].document).html().split(" ")[0]; |
99 | | - jQuery.each(jQuery(".declaration", window.parent.frames[0].document), function(i, element) { |
100 | | - content = element.innerHTML; |
101 | | - if(content.indexOf("MacRuby") == -1) { |
102 | | - dec = new Declaration(element.textContent) |
103 | | - try { |
104 | | - element.innerHTML = element.innerHTML + "<br/><br/><h5>MacRuby:</h5>" + className + dec.methodName(); |
105 | | - } |
106 | | - catch(err2) { |
107 | | - } |
108 | | - } |
109 | | - }); |
110 | | - } |
111 | | - catch(err) { |
112 | | - console.log(err) |
113 | | - } |
114 | | - } |
115 | | - |
116 | | - setInterval(check, 3000); |
117 | | -} |
118 | | - |
119 | | -// load jQuery and execute the main function |
120 | | -addJQuery(main); |
121 | | -////////// |
122 | | - |
| 21 | + require("https://raw.github.com/joakimk/macruby-docs-js/master/lib/macruby-docs.stable.js"); |
123 | 22 | }; |
124 | 23 |
|
125 | 24 | load_latest(); |
|
0 commit comments