Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In Nexus
- /*
- Subversion v0.01
- */
- // https://mathiasbynens.be/notes/localstorage-pattern
- // Feature detect + local reference
- var storage;
- var fail;
- var uid;
- try {
- uid = new Date;
- (storage = window.localStorage).setItem(uid, uid);
- fail = storage.getItem(uid) != uid;
- storage.removeItem(uid);
- fail && (storage = false);
- } catch (exception) {}
- // Intentional Pollution
- exy = function(what) { if (typeof what != 'undefined') { return true }; return false }
- log = console.log
- subv = (function() {
- // 'file:///C:/Users/William Yu/Dropbox/subv/subv.main.js'
- // 'chrome-extension://cphhciabmdjhdnphcfpaldiacnhdgjnf/subv.main.js'
- var c = {}
- var id, pkg;
- var init = function() {
- // enslave Nexus
- if (exy(Nexus)) { subv.c = Nexus; c = subv.c }
- // which computer?
- if (storage) {
- var n = storage.getItem('subversion-id')
- if (n != null) { subv.id = n; id = subv.id } }
- // load main
- inject('chrome-extension://' + id + '/subv.main.js')
- // point to self
- if (exy(c.client) & exy(c.client.packages)) {
- var g = c.client.packages
- for (var i=0; i<g.length; i++) {
- if (g[i].name && g[i].name == 'subversion') {
- subv.pkg = g[i]; pkg = subv.pkg; break }
- }
- }
- }
- var inject = function(datum, type, cb) {
- if (type == 'script' || type == null) {
- var head = document.getElementsByTagName('head')[0]
- var elem = document.createElement('script')
- elem.src = datum
- elem.onload = function() { log('Completed loading.') }
- head.appendChild(elem) // try/catch does not capture these errors
- }
- if (type == 'css') {
- $('body').append('<div class="subv-rule">­<style>' + datum + '</style></div>')
- }
- }
- $('.subv-rule').remove()
- return {
- c : c,
- id : id,
- pkg : pkg,
- init : init,
- inject: inject,
- }
- })()
- subv.init()
- // Hard Disk
- log = console.log
- String.prototype.toProperCase = function () {
- return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
- }
- subv = (function(subv) {
- var c = subv.c.client
- var id = subv.id
- var inject = subv.inject
- var path = 'chrome-extension://' + id + '/'
- var main = function() {
- inject(path + 'core/subv.globals.js')
- inject(path + 'core/subv.utility.js')
- inject(path + 'core/subv.aliases.js')
- inject(path + 'core/subv.triggers.js')
- inject(path + 'core/subv.redress.js')
- injectcss(path + 'core/subv.redress.css')
- inject(path + 'core/subv.modules.js')
- }
- var injectcss = function(href) {
- var css = $('<link>', {
- 'rel' : 'stylesheet',
- 'type' : 'text/css',
- 'href' : href,
- })[0]
- document
- .getElementsByTagName('head')[0]
- .appendChild(css)
- }
- var send = function(msg) {
- c.send_direct(msg, true)
- }
- // assignment out
- subv.main = main
- subv.send = send
- subv.path = path
- subv.injectcss = injectcss
- return subv
- })( subv || {} )
- subv.main()
- /*
- https://developer.chrome.com/extensions/manifest/web_accessible_resources
- https://mathiasbynens.be/notes/localstorage-pattern
- */
- subv = (function(subv) {
- var clone = subvu.clone
- var c = subv.c.client
- var triggers = []
- var trm = subv.trm || false
- var ign = subv.tri || false
- // reroute alias handling ONCE
- if (typeof triggersChained == 'undefined' || triggersChained == null) {
- handle_triggers_old = clone( c.handle_triggers )
- triggersChained = true }
- // overwrite handle_aliases
- c.handle_triggers = function(input) {
- trm = subv.trm; subv.trm = trm
- ign = subv.tri; subv.tri = ign
- var output = handle_triggers_old( input )
- for (var i=0; i<input.length; i++) {
- var t = input[i]
- var line = ''
- if (exy(t.parsed_line) && exy(t.parsed_line.text)) { line = t.parsed_line.text() }
- var matched = trm
- for (var j=0; j<triggers.length; j++) {
- var RE = triggers[j].RE || {}
- if (RE.exec && RE.exec( line )) {
- if (!trm) {
- if (ign) { subv.tri = false; ign = subv.tri } else { subv.trm = true; trm = subv.trm } }
- matches = RE.exec( line )
- try { eval( triggers[j].output ) } catch(err) { log(err.message) }
- }
- }
- }
- return output
- }
- // This is a pure C/P of Nexus code because we need to hijack 'actions'
- c.handle_triggers = function(block) {
- if (fullstop) return block;
- for (var idx = 0; idx < block.length; ++idx) {
- if (idx >= 1000) break; // just in case we somehow hit an infinite loop (notifications mainly)
- var text = null;
- if (block[idx].no_triggers) continue; // this is mostly for notifications
- if (block[idx].line) text = block[idx].parsed_line;
- else if (block[idx].prompt) text = block[idx].parsed_prompt;
- if (text == null) continue;
- var txt = text.text();
- // this is for custom functions/scripts
- client.current_line = block[idx];
- // 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.
- var list = reflex_get_active_list('trigger');
- for (var id = 0; id < list.length; ++id) {
- var match = client.do_matching(txt, list[id].text, list[id].matching, list[id].whole_words, list[id].case_sensitive);
- if (match == null) continue;
- if (client.echo_triggers)
- print('Trigger: '+list[id].name, client.color_trigecho);
- var actions = client.prepare_actions('trigger', list[id], match, block, idx, text);
- client.execute_actions(actions, 0);
- }
- // START custom code
- for (var j=0; j<triggers.length; j++) {
- var RE = triggers[j].RE || {}
- if (RE.exec && RE.exec( txt )) {
- if (!trm) {
- if (ign) { subv.tri = false; ign = subv.tri } else { subv.trm = true; trm = subv.trm } }
- matches = RE.exec( txt )
- matches.blockIndex = idx
- // REALLY HACKY
- try { eval( triggers[j].output ) } catch(err) { log(err.message) } }
- }
- // END custom code
- client.match_waiting_actions(text, block, idx);
- }
- return block;
- }
- var make = function(pattern, output, name) {
- var name = name || '.orphan'
- triggers = subv.t
- subv.t = triggers
- var RE = new RegExp(pattern)
- triggers.push({ pattern: pattern, output: output, RE: RE, name: name })
- }
- // assignment
- subv.t = triggers
- subv.tmake = make
- subv.tri = ign
- subv.trm = trm
- return subv
- })( subv || {} )
- subv.tmake('^You will TIMEOUT in 1 minute unless you do something\\.$',`
- bsend('p snake')
- `,'core.timeout')
- etc etc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement