Advertisement
Guest User

Untitled

a guest
May 18th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.76 KB | None | 0 0
  1. // In Nexus
  2.  
  3. /*
  4. Subversion v0.01
  5.  
  6. */
  7.  
  8. // https://mathiasbynens.be/notes/localstorage-pattern
  9. // Feature detect + local reference
  10. var storage;
  11. var fail;
  12. var uid;
  13. try {
  14. uid = new Date;
  15. (storage = window.localStorage).setItem(uid, uid);
  16. fail = storage.getItem(uid) != uid;
  17. storage.removeItem(uid);
  18. fail && (storage = false);
  19. } catch (exception) {}
  20.  
  21. // Intentional Pollution
  22. exy = function(what) { if (typeof what != 'undefined') { return true }; return false }
  23. log = console.log
  24.  
  25. subv = (function() {
  26. // 'file:///C:/Users/William Yu/Dropbox/subv/subv.main.js'
  27. // 'chrome-extension://cphhciabmdjhdnphcfpaldiacnhdgjnf/subv.main.js'
  28. var c = {}
  29. var id, pkg;
  30.  
  31. var init = function() {
  32. // enslave Nexus
  33. if (exy(Nexus)) { subv.c = Nexus; c = subv.c }
  34. // which computer?
  35. if (storage) {
  36. var n = storage.getItem('subversion-id')
  37. if (n != null) { subv.id = n; id = subv.id } }
  38. // load main
  39. inject('chrome-extension://' + id + '/subv.main.js')
  40. // point to self
  41. if (exy(c.client) & exy(c.client.packages)) {
  42. var g = c.client.packages
  43. for (var i=0; i<g.length; i++) {
  44. if (g[i].name && g[i].name == 'subversion') {
  45. subv.pkg = g[i]; pkg = subv.pkg; break }
  46. }
  47. }
  48. }
  49.  
  50. var inject = function(datum, type, cb) {
  51. if (type == 'script' || type == null) {
  52. var head = document.getElementsByTagName('head')[0]
  53. var elem = document.createElement('script')
  54. elem.src = datum
  55. elem.onload = function() { log('Completed loading.') }
  56. head.appendChild(elem) // try/catch does not capture these errors
  57. }
  58. if (type == 'css') {
  59. $('body').append('<div class="subv-rule">&shy;<style>' + datum + '</style></div>')
  60. }
  61. }
  62. $('.subv-rule').remove()
  63.  
  64. return {
  65. c : c,
  66. id : id,
  67. pkg : pkg,
  68.  
  69. init : init,
  70. inject: inject,
  71. }
  72. })()
  73.  
  74. subv.init()
  75.  
  76. // Hard Disk
  77. log = console.log
  78. String.prototype.toProperCase = function () {
  79. return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
  80. }
  81.  
  82. subv = (function(subv) {
  83. var c = subv.c.client
  84. var id = subv.id
  85. var inject = subv.inject
  86. var path = 'chrome-extension://' + id + '/'
  87.  
  88. var main = function() {
  89. inject(path + 'core/subv.globals.js')
  90. inject(path + 'core/subv.utility.js')
  91. inject(path + 'core/subv.aliases.js')
  92. inject(path + 'core/subv.triggers.js')
  93. inject(path + 'core/subv.redress.js')
  94. injectcss(path + 'core/subv.redress.css')
  95. inject(path + 'core/subv.modules.js')
  96. }
  97.  
  98. var injectcss = function(href) {
  99. var css = $('<link>', {
  100. 'rel' : 'stylesheet',
  101. 'type' : 'text/css',
  102. 'href' : href,
  103. })[0]
  104. document
  105. .getElementsByTagName('head')[0]
  106. .appendChild(css)
  107. }
  108.  
  109. var send = function(msg) {
  110. c.send_direct(msg, true)
  111. }
  112.  
  113. // assignment out
  114. subv.main = main
  115. subv.send = send
  116. subv.path = path
  117. subv.injectcss = injectcss
  118. return subv
  119. })( subv || {} )
  120.  
  121. subv.main()
  122.  
  123. /*
  124. https://developer.chrome.com/extensions/manifest/web_accessible_resources
  125. https://mathiasbynens.be/notes/localstorage-pattern
  126. */
  127.  
  128.  
  129. subv = (function(subv) {
  130. var clone = subvu.clone
  131. var c = subv.c.client
  132. var triggers = []
  133. var trm = subv.trm || false
  134. var ign = subv.tri || false
  135.  
  136. // reroute alias handling ONCE
  137. if (typeof triggersChained == 'undefined' || triggersChained == null) {
  138. handle_triggers_old = clone( c.handle_triggers )
  139. triggersChained = true }
  140.  
  141. // overwrite handle_aliases
  142. c.handle_triggers = function(input) {
  143. trm = subv.trm; subv.trm = trm
  144. ign = subv.tri; subv.tri = ign
  145. var output = handle_triggers_old( input )
  146.  
  147. for (var i=0; i<input.length; i++) {
  148. var t = input[i]
  149. var line = ''
  150. if (exy(t.parsed_line) && exy(t.parsed_line.text)) { line = t.parsed_line.text() }
  151.  
  152. var matched = trm
  153. for (var j=0; j<triggers.length; j++) {
  154. var RE = triggers[j].RE || {}
  155. if (RE.exec && RE.exec( line )) {
  156. if (!trm) {
  157. if (ign) { subv.tri = false; ign = subv.tri } else { subv.trm = true; trm = subv.trm } }
  158. matches = RE.exec( line )
  159. try { eval( triggers[j].output ) } catch(err) { log(err.message) }
  160. }
  161. }
  162. }
  163. return output
  164. }
  165.  
  166. // This is a pure C/P of Nexus code because we need to hijack 'actions'
  167. c.handle_triggers = function(block) {
  168. if (fullstop) return block;
  169. for (var idx = 0; idx < block.length; ++idx) {
  170. if (idx >= 1000) break; // just in case we somehow hit an infinite loop (notifications mainly)
  171. var text = null;
  172. if (block[idx].no_triggers) continue; // this is mostly for notifications
  173. if (block[idx].line) text = block[idx].parsed_line;
  174. else if (block[idx].prompt) text = block[idx].parsed_prompt;
  175. if (text == null) continue;
  176. var txt = text.text();
  177. // this is for custom functions/scripts
  178. client.current_line = block[idx];
  179. // Re-generate this list for every line - this means that enabling/disabling reflexes gets applied for the next line, not for the next block. Needed for multi-line to work correctly.
  180. var list = reflex_get_active_list('trigger');
  181. for (var id = 0; id < list.length; ++id) {
  182. var match = client.do_matching(txt, list[id].text, list[id].matching, list[id].whole_words, list[id].case_sensitive);
  183. if (match == null) continue;
  184. if (client.echo_triggers)
  185. print('Trigger: '+list[id].name, client.color_trigecho);
  186. var actions = client.prepare_actions('trigger', list[id], match, block, idx, text);
  187. client.execute_actions(actions, 0);
  188. }
  189. // START custom code
  190. for (var j=0; j<triggers.length; j++) {
  191. var RE = triggers[j].RE || {}
  192. if (RE.exec && RE.exec( txt )) {
  193. if (!trm) {
  194. if (ign) { subv.tri = false; ign = subv.tri } else { subv.trm = true; trm = subv.trm } }
  195. matches = RE.exec( txt )
  196. matches.blockIndex = idx
  197. // REALLY HACKY
  198. try { eval( triggers[j].output ) } catch(err) { log(err.message) } }
  199. }
  200. // END custom code
  201. client.match_waiting_actions(text, block, idx);
  202. }
  203. return block;
  204. }
  205.  
  206.  
  207. var make = function(pattern, output, name) {
  208. var name = name || '.orphan'
  209. triggers = subv.t
  210. subv.t = triggers
  211. var RE = new RegExp(pattern)
  212. triggers.push({ pattern: pattern, output: output, RE: RE, name: name })
  213. }
  214.  
  215. // assignment
  216. subv.t = triggers
  217. subv.tmake = make
  218. subv.tri = ign
  219. subv.trm = trm
  220. return subv
  221. })( subv || {} )
  222.  
  223. subv.tmake('^You will TIMEOUT in 1 minute unless you do something\\.$',`
  224. bsend('p snake')
  225. `,'core.timeout')
  226.  
  227. etc etc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement